public async Task Add(string applicationName, DeploymentManifestSourceSettings deploymentManifestSourceSettings) { var jobKey = new JobKey($"gitclone-{applicationName}", Constants.SchedulerGroup); if (await _scheduler.CheckExists(jobKey)) { var triggers = await _scheduler.GetTriggersOfJob(jobKey); foreach (var trigger in triggers) { await _scheduler.UnscheduleJob(trigger.Key); } await _scheduler.DeleteJob(new JobKey($"gitclone-{applicationName}", Constants.SchedulerGroup)); } var conf = _configuration.Value; // build repository information var checkoutPath = Path.Combine(Path.GetTempPath(), $"sb-{Guid.NewGuid()}-{applicationName}-{deploymentManifestSourceSettings.Repository.Ref}"); var repository = new DeploymentManifestRepository( new Uri(deploymentManifestSourceSettings.Repository.Uri), deploymentManifestSourceSettings.Repository.Ref, conf.GitCredentials.First( x => x.Name.Equals(deploymentManifestSourceSettings.Repository.Credentials) ).ConvertToGitCredentials(), _fileSystem.DirectoryInfo.FromDirectoryName(checkoutPath) ); var deploymentManifest = deploymentManifestSourceSettings.Type switch { DeploymentManifestType.Helm => (DeploymentManifest) new HelmDeploymentManifest( applicationName, repository, deploymentManifestSourceSettings.Path, deploymentManifestSourceSettings.Helm.ValueFiles, deploymentManifestSourceSettings.Helm.Secrets ), DeploymentManifestType.Raw => (DeploymentManifest) new RawDeploymentManifest( applicationName, repository, deploymentManifestSourceSettings.Path, new [] { deploymentManifestSourceSettings.Raw.File } ), _ => throw new InvalidOperationException() }; await _deploymentManifestSourceStore.StoreDeploymentManifest(applicationName, deploymentManifest); var context = new DeploymentManifestSourceTrackingContext( applicationName, deploymentManifest ); await _scheduler.TriggerJobOnce <GitRepositoryCheckoutJob, DeploymentManifestSourceTrackingContext>( $"gitclone-{applicationName}", Constants.SchedulerGroup, context ); }
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); }