Пример #1
0
        public async Task <ActionResult <Dictionary <string, string> > > GetCurrentImageTags(string id, string instanceId = "")
        {
            var application = _applicationService.GetApplication(id);

            var instanceIds = instanceId.ToLower() switch
            {
                "prime" => new List <string>()
                {
                    ""
                },
                "primary" => new List <string>()
                {
                    ""
                },
                "" => _applicationImageInstanceService.GetAllInstanceIdsForApplication(application),
                _ => new List <string>()
                {
                    instanceId
                }
            };
            var result = new Dictionary <string, Dictionary <string, string> >();

            foreach (var x in instanceIds)
            {
                var instanceTags = new Dictionary <string, string>();
                result.Add(string.IsNullOrEmpty(x) ? "primary" : x, instanceTags);

                foreach (var image in application.Images)
                {
                    var currentTag = await _applicationImageInstanceService.GetCurrentTag(application, image, x);

                    if (!currentTag.available)
                    {
                        instanceTags[image.TagProperty.Path] = "not-available-yet";
                    }
                    else
                    {
                        instanceTags[image.TagProperty.Path] = image.TagProperty.ValueFormat == TagPropertyValueFormat.TagOnly
                            ? $"{image.Repository}:{currentTag.tag}"
                            : $"{currentTag.tag}";
                    }
                }
            }

            if (result.Count == 1)
            {
                // single entry mode!
                return(Ok(result.First().Value));
            }

            if (result.Count > 1)
            {
                // multi-entry mode
                return(Ok(result));
            }

            return(NotFound());
        }
    }
Пример #2
0
        public async Task <Deployment> AddDeployment(
            Application application,
            ApplicationImage image,
            string newTag,
            DeploymentType type = DeploymentType.ImageUpdate,
            string instanceId   = "",
            IReadOnlyDictionary <string, string>?parameters = null)
        {
            var currentTagInStore = await _applicationImageInstanceService.GetCurrentTag(application, image, instanceId);

            var currentTag = currentTagInStore.available ? currentTagInStore.tag : "";

            var deployments = _deploymentsDbContextConfigurator.Set <Dao.Deployment>();

            var deploymentExists = await IsDeploymentPresent(
                application,
                image,
                newTag,
                type,
                instanceId
                );

            if (deploymentExists)
            {
                _log.LogInformation(
                    "Image tag update operation already in queue for '{Repository}' with {Tag} for application {Application} with new tag {NewTag}",
                    image.Repository,
                    currentTag,
                    application.Name,
                    newTag
                    );

                throw new Exception($"Deployment for {image} with {newTag} on application '{application.Name}' already exists.");
            }

            var entity = await CreateAndStoreDeploymentDao(
                deployments,
                application,
                image,
                type == DeploymentType.ImageUpdate?DaoDeploymentType.ImageUpdate : DaoDeploymentType.PreviewRelease,
                newTag,
                currentTag,
                string.Empty,
                instanceId,
                parameters
                );

            _log.LogInformation(
                "Adding image tag update operation for '{Repository}' with {Tag} for application {Application} with new tag {NewTag}",
                image.Repository,
                currentTag,
                application.Name,
                newTag
                );

            await _deploymentsDbContextConfigurator.SaveChangesAsync();

            var deployment = entity.Entity.ConvertToDeploymentModel();

            await _deploymentNotificationService.CreateNotification(deployment);

            return(deployment);
        }