From bf43f5bb8ce1aec450b2aa85864af450886f2491 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Wed, 10 Jun 2020 09:53:31 -0700 Subject: [PATCH] Allow upload-docker-image role to be used outside of promote This adds an option to the upload-docker-image role so that a job can be written to run build-docker-image and upload-docker-image in a release pipeline. This lets users build tagged docker images from release tags rather than using the promote pipeline (which may have built the image before a release git tag was applied). Change-Id: Id28d0a85e02e56640911c44ddbfff7b38547b0b4 --- roles/upload-docker-image/README.rst | 10 ++++++++++ roles/upload-docker-image/defaults/main.yaml | 1 + roles/upload-docker-image/tasks/push.yaml | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/roles/upload-docker-image/README.rst b/roles/upload-docker-image/README.rst index 2b04c2e42..836c77bfd 100644 --- a/roles/upload-docker-image/README.rst +++ b/roles/upload-docker-image/README.rst @@ -1,3 +1,13 @@ Upload one or more docker images. .. include:: ../../roles/build-docker-image/common.rst + +.. zuul:rolevar:: upload_docker_image_promote + :type: bool + :default: true + + If ``true`` (the default), then this role will upload the image(s) + to Docker Hub with special tags designed for use by the + :zuul:role:`promote-docker-image` role. Set to ``false`` to use + this role to directly upload images with the final tag (e.g., as + part of an un-gated release job). diff --git a/roles/upload-docker-image/defaults/main.yaml b/roles/upload-docker-image/defaults/main.yaml index d702500de..0c5fa0c84 100644 --- a/roles/upload-docker-image/defaults/main.yaml +++ b/roles/upload-docker-image/defaults/main.yaml @@ -1,2 +1,3 @@ zuul_work_dir: "{{ zuul.project.src_dir }}" docker_dockerfile: "Dockerfile" +upload_docker_image_promote: true diff --git a/roles/upload-docker-image/tasks/push.yaml b/roles/upload-docker-image/tasks/push.yaml index 574cebe34..dac3b45e1 100644 --- a/roles/upload-docker-image/tasks/push.yaml +++ b/roles/upload-docker-image/tasks/push.yaml @@ -1,5 +1,5 @@ - name: Upload tag to dockerhub - command: "docker push {{ zj_image.repository }}:change_{{ zuul.change }}_{{ zj_image_tag }}" + command: "docker push {{ zj_image.repository }}:{{ upload_docker_image_promote | ternary('change_' + zuul.change + '_', '') }}{{ zj_image_tag }}" loop: "{{ zj_image.tags | default(['latest']) }}" loop_control: loop_var: zj_image_tag