private async Task <List <ImportJob> > CreateImportJobs() { var importJobs = new List <ImportJob>(); var images = new List <string>(); if (_importConfiguration.Repositories != null) { var artifactProvider = new ArtifactProvider(_logger); var matchedTags = await artifactProvider.GetArtifactsAsync( _importConfiguration.SourceRegistry.RegistryUri, _importConfiguration.SourceRegistry.UserName, _importConfiguration.SourceRegistry.Password, _importConfiguration.Repositories).ConfigureAwait(false); images.AddRange(matchedTags); } if (_importConfiguration.Tags != null) { images.AddRange(_importConfiguration.Tags); } _logger.LogInformation($"Total registry artifacts to import: {images.Count}"); foreach (var image in images) { var job = new ImportJob { SourceType = ImportSourceType.RegistryImage, }; job.Images.Add(image); importJobs.Add(job); } var blobs = _importConfiguration.Blobs; _logger.LogInformation($"Total storage blobs to import: {blobs.Count}"); if (blobs != null && blobs.Count > 0) { foreach (var blob in blobs) { var job = new ImportJob { SourceType = ImportSourceType.AzureStorageBlob, ImportPipelineName = _importConfiguration.ImportPipelineName, PipelineRunName = Guid.NewGuid().ToString("N"), ImportBlobName = blob }; importJobs.Add(job); } } return(importJobs); }
private async Task <List <ExportJob> > CreateExportJobsAsync(List <string> importedImages) { var exportJobs = new List <ExportJob>(); var images = new List <string>(); var importedImageCount = importedImages?.Count ?? 0; if (importedImageCount > 0) { images.AddRange(importedImages); } if (_exportConfiguration.Repositories != null && _exportConfiguration.Repositories.Count > 0) { var artifactProvider = new ArtifactProvider(_logger); var loginServer = await _transferClient.GetRegistryLoginServerAsync().ConfigureAwait(false); var matchedTags = await artifactProvider.GetArtifactsAsync( loginServer, _identityConfiguration.ClientId, _identityConfiguration.ClientSecret, _exportConfiguration.Repositories).ConfigureAwait(false); images.AddRange(matchedTags); } if (_exportConfiguration.Tags != null) { images.AddRange(_exportConfiguration.Tags); } _logger.LogInformation($"Total artifacts to export: {images.Count}."); var i = 0; while (i < images.Count) { if (i % _exportConfiguration.MaxArtifactCountPerBlob == 0) { var endIndex = Math.Min(i + _exportConfiguration.MaxArtifactCountPerBlob - 1, images.Count - 1); var pipelineRunName = Guid.NewGuid().ToString("N"); var targetBlobName = $"{_exportConfiguration.BlobNamePrefix}From{i+1}To{endIndex+1}"; var job = new ExportJob { PipelineRunName = pipelineRunName, ExportPipelineName = _exportConfiguration.ExportPipelineName, ExportBlobName = targetBlobName }; while (i <= endIndex) { job.Images.Add(images[i]); i++; } exportJobs.Add(job); } } return(exportJobs); }