Example #1
0
        private async Task ExecuteExportAsync(ExportJob exportJob)
        {
            try
            {
                using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(_exportConfiguration.TransferTimeoutInSeconds)))
                {
                    await _transferClient.ExportImagesToStorageAsync(
                        exportJob.ExportPipelineName,
                        exportJob.PipelineRunName,
                        exportJob.Images,
                        exportJob.ExportBlobName,
                        cts.Token).ConfigureAwait(false);
                }

                exportJob.Status = TransferJobStatus.Succeeded;
                _logger.LogInformation($"PipelineRun {exportJob.PipelineRunName} succeeded.");
            }
            catch (Exception e)
            {
                exportJob.Status = TransferJobStatus.Failed;
                _logger.LogError($"PipelineRun {exportJob.PipelineRunName} failed, exception: {e}.");
            }
        }
Example #2
0
        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);
        }