From 1d795a95d456a0fad2c50960ef6dfc7ab906869f Mon Sep 17 00:00:00 2001 From: Brian Veltman <2551674+brianveltman@users.noreply.github.com> Date: Sun, 24 Dec 2023 00:29:57 +0100 Subject: [PATCH] Add ability to allow redeployments for containers with latest tag (#395) * Add ability to allow redeployments for containers with latest tag --------- Co-authored-by: Olivier Clavel --- README.md | 10 ++++++++++ files/groovy/create_repos_from_list.groovy | 9 +++++++++ molecule/nexus_common_test_vars.yml | 6 ++++++ 3 files changed, 25 insertions(+) diff --git a/README.md b/README.md index e94c2c1d..75585f87 100644 --- a/README.md +++ b/README.md @@ -713,6 +713,16 @@ nexus_repos_docker_group: - docker-hosted-repo ``` +```yaml +nexus_repos_docker_hosted: + - name: some-docker-repo + blob_store: docker-blob + v1_enabled: false + write_policy: allow_once # Values: "allow", "allow_once" or "deny" + # When set, it will ignore the defined write_policy and allows to redeploy container images with the tag 'latest' only. + allow_redeploy_latest: true +``` + Maven, Pypi, Docker, Raw, Rubygems, Bower, NPM, Git-LFS, yum, apt, helm, r, p2, conda and go repository types: see `defaults/main.yml` for these options. For historical reasons and to keep backward compatibility, maven is configured by default diff --git a/files/groovy/create_repos_from_list.groovy b/files/groovy/create_repos_from_list.groovy index 2c8c89d7..2c566005 100644 --- a/files/groovy/create_repos_from_list.groovy +++ b/files/groovy/create_repos_from_list.groovy @@ -212,6 +212,15 @@ parsed_args.each { currentRepo -> ] } + if (currentRepo.allow_redeploy_latest && currentRepo.type == 'hosted' && currentRepo.format == 'docker') { + configuration.attributes['storage'] = [ + latestPolicy: currentRepo.allow_redeploy_latest ? currentRepo.allow_redeploy_latest : null, + // When setting the allow_redeploy_latest, the writePolicy must be set to ALLOW_ONCE and API expects blobStoreName param + writePolicy: currentRepo.allow_redeploy_latest ? "ALLOW_ONCE" : currentRepo.write_policy.toUpperCase(), + blobStoreName: currentRepo.blob_store + ] + } + if (existingRepository == null) { repositoryManager.create(configuration) currentResult.put('status', 'created') diff --git a/molecule/nexus_common_test_vars.yml b/molecule/nexus_common_test_vars.yml index e097f8a4..e6a9e328 100644 --- a/molecule/nexus_common_test_vars.yml +++ b/molecule/nexus_common_test_vars.yml @@ -130,6 +130,12 @@ nexus_repos_docker_hosted: force_basic_auth: true v1_enabled: true write_policy: allow + - name: docker-private-redeploy + write_policy: deny # will be ignored when allow_redeploy_latest is true + allow_redeploy_latest: true + - name: docker-private-no-redeploy + write_policy: deny # will be effective when allow_redeploy_latest is false + allow_redeploy_latest: false nexus_repos_docker_proxy: [] nexus_repos_apt_hosted: