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 static void Main(string[] args) { try { Argument arg = null; // There have to be some arguments if (args == null || args.Length == 0) { PrintUsage(); return; } // Parse and gather arguments arg = new Argument(new Arguments(args)); // Display version info if (arg.DisplayVersion) { PrintVersion(); return; } // Parse global settings XML file Settings settings = XmlParser.ParseSettings("settings.xml", arg); // Parse project XML file Project project = XmlParser.ParseProject(arg.ConfigFile, settings, arg); // Get the deployment strategy based on the project type IDeployStrategy strategy = DeployStrategyFactory.GetStrategyFromType(project.ProjectType); foreach (var env in arg.DeploymentEnvironment) { // Check for confirmation if (arg.Confirmation) { Confirm(arg, settings, project, env); } // Do backup if (arg.Backup) { Backup(settings, project, env); } // Do the actual deployment var exitCode = strategy.Deploy(arg, settings, project, env); // Check if there was an error if (exitCode > 0) { Console.WriteLine("Deployment failed with exit code " + exitCode + ", quitting..."); Environment.Exit(exitCode); } // No error, display deployment information else { Console.WriteLine("Build & Deployment successful!"); PrintInfo(arg, env, settings, project); } } } catch (Exception ex) { PrintText(ex.Message); // Exit with an error Environment.Exit(1); } }
public static string GetStrategyName(string type) { IDeployStrategy strategy = GetStrategyFromType(type); return(strategy.Name); }