コード例 #1
0
        public override async Task Execute(DeploymentManifestSourceTrackingContext context)
        {
            using (_log.BeginScope(new Dictionary <string, object>
            {
                { "Application", context.ApplicationName },
                { "Ref", context.DeploymentManifest.Repository.Ref },
                { "Path", context.DeploymentManifest.Path }
            }))
            {
                var repository = context.DeploymentManifest.Repository;
                await _deploymentManifestRepositoryService.Checkout(repository);

                var application = _applicationService.GetApplication(context.ApplicationName);

                var manifestsChanged = context.DeploymentManifest switch
                {
                    HelmDeploymentManifest helmDeploymentManifest => await InternalExecute(helmDeploymentManifest,
                                                                                           application),
                    RawDeploymentManifest rawDeploymentManifest => await InternalExecute(rawDeploymentManifest,
                                                                                         application),
                    _ => throw new ArgumentOutOfRangeException()
                };

                if (
                    manifestsChanged &&
                    context.AutoDeploy &&
                    !_configuration.Value.Dryrun)
                {
                    await _deploymentManifestRepositoryService.Push(repository);
                }
            }
        }
    }
コード例 #2
0
 public Task <DeploymentManifestInfo> GetDeploymentManifestInfo(DeploymentManifest manifest)
 {
     return(manifest switch
     {
         HelmDeploymentManifest helmDeploymentManifest => GetDeploymentManifestInfo(helmDeploymentManifest),
         RawDeploymentManifest rawDeploymentManifest => GetDeploymentManifestInfo(rawDeploymentManifest),
         _ => throw new ArgumentOutOfRangeException(nameof(manifest))
     });
コード例 #3
0
        static async Task <int> Main(string[] args)
        {
            var hostBuilder = Host.CreateDefaultBuilder()
                              .ConfigureServices(
                collection =>
            {
                collection.RegisterApplicationManagementComponents();
                collection.RegisterDeploymentManifestSourceServices();
            }
                );

            var host = hostBuilder.Build();

            using var scope = host.Services.CreateScope();
            var serviceProvider = scope.ServiceProvider;

            // build repository and application metadta
            var appImage = new ApplicationImage(
                "511177966619.dkr.ecr.eu-west-1.amazonaws.com/odin/azurolongo.lucky8",
                new TagProperty("image.tag", TagPropertyValueFormat.TagOnly),
                new GlobImageUpdatePolicy("*-dev-*"),
                new DeploymentSettings(
                    true,
                    true,
                    new PreviewReleaseDeploymentSettings(
                        true,
                        new RegexImageUpdatePolicy("^[0-9.]*-demo-(.*)-[0-9]*"),
                        "(?<version>[\\d\\.]+)-demo-(?<branch>.*)-(?<buildNumber>\\d+)"
                        )
                    ),
                ApplicationImageSourceCode.Empty,
                ApplicationImageIngress.Empty
                );

            var application = new Application(
                "Test",
                new[]
            {
                appImage
            },
                new NotificationSettings()
                );

            var fs = new FileSystem();

            var repo = new DeploymentManifestRepository(
                new Uri("https://github.com/River-iGaming/odin-deploys"),
                "feature/test-shipbot",
                new UsernamePasswordGitCredentials("rt-deploy-bot", args[0]),
                fs.DirectoryInfo.FromDirectoryName(Path.Combine(Path.GetTempPath(), "abc"))
                );

            var manifest = new RawDeploymentManifest(
                "Test",
                repo,
                "frontend/caglisse/rig-dev-grey-eks/dev/",
                new[] { "lucky8.yaml" }
                );

            // app services
            var appServices = serviceProvider.GetRequiredService <IApplicationService>();

            appServices.AddApplication(application);

            // checkout
            var repoServices = serviceProvider.GetRequiredService <IDeploymentManifestRepositoryService>();
            await repoServices.Checkout(manifest.Repository, true);

            // get info
            var management = serviceProvider.GetRequiredService <IDeploymentManifestSourceManagementFacade>();
            var info       = await management.GetDeploymentManifestInfo(manifest);

            Console.WriteLine("Before ======");
            Console.WriteLine("Instances:");

            foreach (var deploymentManifestInstanceInfo in info.InstanceNames)
            {
                Console.WriteLine($"  {deploymentManifestInstanceInfo.Key}:");
                foreach (var s in deploymentManifestInstanceInfo.Value)
                {
                    Console.WriteLine($"  - { (string.IsNullOrWhiteSpace(s) ? "<primary>" : s ) }");
                }
            }

            // test creating a preview release
            await management.CreatePreviewRelease(manifest, appImage, "pr-555", "9.1.6-dev-111");

            info = await management.GetDeploymentManifestInfo(manifest);

            Console.WriteLine("After ======");

            Console.WriteLine("Instances:");

            foreach (var deploymentManifestInstanceInfo in info.InstanceNames)
            {
                Console.WriteLine($"  {deploymentManifestInstanceInfo.Key}:");
                foreach (var s in deploymentManifestInstanceInfo.Value)
                {
                    Console.WriteLine($"  - { (string.IsNullOrWhiteSpace(s) ? "<primary>" : s ) }");
                }
            }

            // remove
            await management.RemovePreviewRelease(manifest, appImage, "pr-555");

            info = await management.GetDeploymentManifestInfo(manifest);

            Console.WriteLine("After Removal ======");

            Console.WriteLine("Instances:");

            foreach (var deploymentManifestInstanceInfo in info.InstanceNames)
            {
                Console.WriteLine($"  {deploymentManifestInstanceInfo.Key}:");
                foreach (var s in deploymentManifestInstanceInfo.Value)
                {
                    Console.WriteLine($"  - { (string.IsNullOrWhiteSpace(s) ? "<primary>" : s ) }");
                }
            }

            return(0);
        }