private static async Task Main(string[] args) { // 0. Bootstraping Log.Logger = new LoggerConfiguration() .WriteTo.Console() .CreateLogger(); var appConfig = await new AppConfigurationProvider().Get(); var repositoryImportStrategies = new IRepositoryImportStrategy[] { new SvnRepositoryStrategy() }; var buildStrategies = new ISourceCodeBuilderStrategy[] { new DotNetCoreSourceBuilderStrategy() }; var deployStrategies = new IDeployStrategy[] { new InternetInformationServerDeploymentStrategy() }; // 1. Source Repo // 1.1 Type (SVN, GIT) // 1.2 Central Credentials // Moved to settings. // 3. Project Name // Moved to settings. var fetchResult = await RepositoryImporter.ImportAsync(Settings.ProjectName, Settings.SourceRepoUrl, SourceCodeRepositoryType.Svn, appConfig, new SvnAuthInfo(Settings.Username, Settings.Password), new ReadOnlyCollection <IRepositoryImportStrategy>(repositoryImportStrategies)); if (fetchResult.HasErrors) { goto end; } Log.Information(fetchResult.CheckOutDirectory); // 4. Targets to build. var buildTargets = new[] { new BuildTarget("Web", @"Trunk\Nrea.Web", BuildTargetType.DotNetCore), //new BuildTarget("Migration", @"Trunk\Nrea.Migration", BuildTargetType.DotNetCore) }; var buildResult = await SourceCodeBuilder.BuildTargetsAsync(fetchResult.CheckOutDirectory, buildTargets, new ReadOnlyCollection <ISourceCodeBuilderStrategy>(buildStrategies)); if (buildResult.Any(x => x.HasErrors)) { goto end; } // 5. Targets to deploy. var deployTargets = new[] { new DeployTarget(buildResult[0], DeployTargetType.IIS, new IISDeployTargetExtraInfo("Nrea", 54007)), //new DeployTarget(buildTargets[1], DeployTargetType.DotNetCoreRun, new IISDeployTargetExtraInfo("Nrea")) }; var deployResult = await DeployManager.DeployTargetsAsync(deployTargets, new ReadOnlyCollection <IDeployStrategy>(deployStrategies)); foreach (var item in deployResult) { Log.Information($"Deployment result: {item.Target.BuildTarget.Target.Name}, IsError: {item.HasErrors}"); } end: Log.Information("End."); Console.ReadLine(); }
public async Task DoWork(BuildAndDeployRequestModel request) { try { using (var scope = Payload.ServiceProvider.CreateScope()) { Logger.Information("Start fetching reposiotory..."); var config = scope.ServiceProvider.GetRequiredService <AppConfiguration>(); var authConfigs = scope.ServiceProvider.GetServices <IRepositoryAuthenticationInfo>(); var importStrategies = scope.ServiceProvider.GetServices <IRepositoryImportStrategy>(); var buildStrategies = scope.ServiceProvider.GetServices <ISourceCodeBuilderStrategy>(); var deployStrategies = scope.ServiceProvider.GetServices <IDeployStrategy>(); var importResult = await RepositoryManager.ImportAsync(request.Project, config, authConfigs.First(x => x.Type == request.Project.RepositoryType), new ReadOnlyCollection <IRepositoryImportStrategy>(importStrategies.ToList()), Logger, request.Cursor.Info.CommitId); if (importResult.HasErrors) { Logger.Error($"Importing repository did not complete successfully."); return; } Logger.Information($"Project directory: {importResult.CheckOutDirectory}"); Logger.Information("Start building reposiotory..."); if (request.Project.BuildTargets == null || request.Project.BuildTargets.Count == 0) { Logger.Error("Project doesn't contain BuildTargets."); return; } var buildResults = await SourceCodeBuilder.BuildTargetsAsync(importResult.CheckOutDirectory, request.Project.BuildTargets.ToArray(), new ReadOnlyCollection <ISourceCodeBuilderStrategy>(buildStrategies.ToList()), Logger); if (buildResults.Any(x => x.HasErrors)) { Logger.Error("Not all BuildTargets where build successfully. Skipping deployment."); Logger.Information("End."); return; } Logger.Information("Start deploying reposiotory..."); var deployResult = await DeployManager.DeployTargetsAsync(buildResults.ToArray(), new ReadOnlyCollection <IDeployStrategy>(deployStrategies.ToList()), Logger); if (deployResult.Any(x => x.HasErrors)) { Logger.Error("Not all deployments ran successfully."); } Logger.Information("End."); } } catch (Exception exp) { Logger.Error(exp); } }