From ff5759398406d2a8cb34ad4b145c58db87e867a0 Mon Sep 17 00:00:00 2001 From: Bharat Kunwar Date: Thu, 11 Jun 2020 09:29:01 +0000 Subject: [PATCH] [hca] Only build/push stable images if unpublished At present, the only mechanism we have for publishing a stable heat container agent image through manual tagging. This PS aims to automate this through the CI by only building them if they have not already been published. This should allow us to keep better track of which commit was used to build a given heat container agent image. Story: 2007264 Task: 40045 Change-Id: Ifb80575c18a34584afddc8b83084702713a802b7 --- playbooks/container-builder-vars.yaml | 10 +++++++--- playbooks/container-builder.yaml | 24 +++++++++++++++++++----- playbooks/container-publish.yaml | 4 ++-- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/playbooks/container-builder-vars.yaml b/playbooks/container-builder-vars.yaml index 22c8a4d5d2..ed49e8cf41 100644 --- a/playbooks/container-builder-vars.yaml +++ b/playbooks/container-builder-vars.yaml @@ -2,9 +2,13 @@ magnum_src_dir: "src/opendev.org/openstack/magnum" magnum_repository: openstackmagnum -magnum_images: - - name: heat-container-agent - tag: victoria-dev +# NOTE: By default, stable images are not built if they already exist. +# Assigning dev=true property for heat container agent images means that a new +# image is re-built and pushed under the same tag every time. +heat_container_agent_images: + - tag: victoria-stable-1 + - tag: wallaby-dev + dev: true kubernetes_versions: - version: v1.15.12 diff --git a/playbooks/container-builder.yaml b/playbooks/container-builder.yaml index d7747c19d0..f026f04022 100644 --- a/playbooks/container-builder.yaml +++ b/playbooks/container-builder.yaml @@ -2,15 +2,29 @@ tasks: - include_vars: container-builder-vars.yaml - - name: "Build magnum images" + # NOTE: By default, stable images are not built if they already exist. + # Assigning dev=true property for heat container agent images means that a new + # image is re-built and pushed under the same tag every time. + - name: "Build heat-container-agent images" block: - - name: "Build {{ magnum_repository }}/{{ item.name }}:{{ item.tag }} image" + - name: "Check if {{ magnum_repository }}/heat-container-agent:{{ item.tag }} exists" docker_image: - path: "{{ magnum_src_dir }}/dockerfiles/{{ item.name }}" - name: "{{ magnum_repository }}/{{ item.name }}" + name: "{{ magnum_repository }}/heat-container-agent" tag: "{{ item.tag }}" + pull: yes + register: docker_output + when: not (item.dev | default(false) | bool) + ignore_errors: true + with_items: "{{ heat_container_agent_images }}" + - name: "Build {{ magnum_repository }}/heat-container-agent:{{ item.item.tag }} image" + docker_image: + path: "{{ magnum_src_dir }}/dockerfiles/heat-container-agent" + name: "{{ magnum_repository }}/heat-container-agent" + tag: "{{ item.item.tag }}" push: no - with_items: "{{ magnum_images }}" + source: build + with_items: "{{ docker_output.results }}" + when: (item is failed) or (item.item.dev | default(false) | bool) retries: 10 - name: "Build kubernetes images" diff --git a/playbooks/container-publish.yaml b/playbooks/container-publish.yaml index 6d3b9755e7..cc17d4e511 100644 --- a/playbooks/container-publish.yaml +++ b/playbooks/container-publish.yaml @@ -9,8 +9,8 @@ - name: Push images to DockerHub block: - - command: docker push {{ magnum_repository }}/{{ item.name }}:{{ item.tag }} - with_items: "{{ magnum_images }}" + - command: docker push {{ magnum_repository }}/heat-container-agent:{{ item.tag }} + with_items: "{{ heat_container_agent_images }}" retries: 10 - command: docker push {{ magnum_repository }}/{{ item[1].name }}:{{ item[0].version }} with_nested: