Example #1
0
        private async Task ExecutePipelineRunAsync(ImportJob importJob, CancellationToken cancellationToken)
        {
            try
            {
                var importedImages = await _transferClient.ImportImagesFromStorageAsync(
                    importJob.ImportPipelineName,
                    importJob.PipelineRunName,
                    importJob.ImportBlobName,
                    cancellationToken).ConfigureAwait(false);

                importJob.Status = TransferJobStatus.Succeeded;

                if (importedImages != null && importedImages.Count > 0)
                {
                    foreach (var image in importedImages)
                    {
                        importJob.Images.Add(image);
                        _logger.LogInformation($"Sucessfully imported {image}, pipelineRun:{importJob.PipelineRunName}, blob:{importJob.ImportBlobName}.");
                    }
                }
            }
            catch (Exception e)
            {
                importJob.Status = TransferJobStatus.Failed;
                _logger.LogError($"Failed to import blob:{importJob.ImportBlobName}, pipelineRun:{importJob.PipelineRunName}, exception: {e}");
            }
        }
Example #2
0
        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);
        }
Example #3
0
 private async Task ExecuteAsync(ImportJob importJob)
 {
     using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(_importConfiguration.TransferTimeoutInSeconds)))
     {
         if (importJob.SourceType == ImportSourceType.RegistryImage)
         {
             await ExecuteImportImageAsync(importJob, cts.Token).ConfigureAwait(false);
         }
         else if (importJob.SourceType == ImportSourceType.AzureStorageBlob)
         {
             await ExecutePipelineRunAsync(importJob, cts.Token).ConfigureAwait(false);
         }
     }
 }
Example #4
0
        private async Task ExecuteImportImageAsync(ImportJob importJob, CancellationToken cancellationToken)
        {
            var image = importJob.Images.First();

            try
            {
                await _transferClient.ImportImageAsync(
                    _sourceRegistry,
                    image,
                    _importConfiguration.Force,
                    cancellationToken).ConfigureAwait(false);

                importJob.Status = TransferJobStatus.Succeeded;
                _logger.LogInformation($"Sucessfully imported {image}");
            }
            catch (Exception e)
            {
                importJob.Status = TransferJobStatus.Failed;
                _logger.LogError($"Failed to import: {image}, exception: {e}");
            }
        }