Skip to content

Commit f3fb8d8

Browse files
committed
Promote multiple tags simultaneously based on Kayobe config
This modifies the container image promotion process to be similar to package repo promotion. The tags for each image are stored in files in StackHPC Kayobe configuration (one per base distro), and these are queried to determine which tag to promote for each image. This avoids the need to specify tags when promoting images, and will allow for automatic tag promotion after merges to StackHPC Kayobe Configuration.
1 parent 34d4ad7 commit f3fb8d8

File tree

5 files changed

+139
-23
lines changed

5 files changed

+139
-23
lines changed

.github/workflows/container-promote.yml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ on:
1313
type: string
1414
required: false
1515
default: ""
16-
tag:
17-
description: Container image tag to promote
18-
required: true
16+
kayobe_config_branch:
17+
required: false
18+
description: Branch of StackHPC Kayobe configuration to use
19+
default: stackhpc/yoga
1920

2021
env:
2122
ANSIBLE_FORCE_COLOR: True
@@ -43,15 +44,22 @@ jobs:
4344
pip install -r requirements.txt &&
4445
ansible-galaxy collection install -r requirements.yml -p ansible/collections
4546
47+
- name: Clone StackHPC Kayobe configuration repository
48+
uses: actions/checkout@v3
49+
with:
50+
repository: stackhpc/stackhpc-kayobe-config
51+
ref: refs/heads/${{ github.event.inputs.kayobe_config_branch }}
52+
path: stackhpc-kayobe-config
53+
4654
- name: Promote images from stackhpc-dev to stackhpc namespace in Ark
4755
run: |
4856
source venv/bin/activate &&
4957
ansible-playbook -i ansible/inventory \
58+
ansible/dev-pulp-container-tag-query-kayobe.yml \
5059
ansible/dev-pulp-container-promote.yml \
51-
-e dev_pulp_repository_container_promotion_tag="$TAG" \
5260
-e kolla_container_image_filter="'$FILTER'" \
53-
-e kolla_base_distros_override="'$DISTROS'"
61+
-e kolla_base_distros_override="'$DISTROS'" \
62+
-e kayobe_config_repo_path=./stackhpc-kayobe-config/
5463
env:
55-
TAG: ${{ github.event.inputs.tag }}
5664
FILTER: ${{ github.event.inputs.filter }}
5765
DISTROS: ${{ github.event.inputs.distros }}

ansible/dev-pulp-container-promote.yml

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
---
22
# This playbook promotes images in the development namespace (stackhpc-dev) to
33
# the release namespace (stackhpc). This makes them available to clients.
4-
# Images with a tag defined by dev_pulp_repository_container_promotion_tag are
5-
# promoted.
4+
# Images with a tag defined by dev_pulp_repository_container_promotion_tags are
5+
# promoted. dev_pulp_repository_container_promotion_tags is a dict with the
6+
# following format:
7+
#
8+
# dev_pulp_repository_container_promotion_tags:
9+
# <base distro>:
10+
# <image name>: <image tag>
611

712
- name: Promote dev Pulp containers
813
hosts: localhost
914
gather_facts: false
1015
tasks:
11-
- name: Fail if container image to promote is not defined
16+
- name: Fail if container images to promote are not defined
1217
fail:
1318
msg: >
14-
The container image to promote must be specified via
15-
'dev_pulp_repository_container_promotion_tag'
16-
when: dev_pulp_repository_container_promotion_tag is not defined
19+
The container images to promote must be specified via
20+
'dev_pulp_repository_container_promotion_tags'
21+
when: dev_pulp_repository_container_promotion_tags is not defined
1722

18-
- debug:
19-
msg: "Promoting tag {{ dev_pulp_repository_container_promotion_tag }}"
23+
- name: Display which tags are being promoted
24+
debug:
25+
var: "dev_pulp_repository_container_promotion_tags"
2026

2127
# Copy tags from stackhpc-dev to stackhpc repositories.
2228
- import_role:
@@ -27,20 +33,18 @@
2733
pulp_password: "{{ dev_pulp_password }}"
2834
pulp_container_content: >-
2935
{%- set contents = [] -%}
30-
{%- for base_distro in kolla_base_distros -%}
31-
{%- for image in kolla_container_images_filtered -%}
32-
{%- if image not in kolla_unbuildable_images[base_distro]-%}
36+
{%- for base_distro, distro_images in dev_pulp_repository_container_promotion_tags.items() -%}
37+
{%- for image, tag in distro_images.items() -%}
3338
{%- set src_image_repo = "stackhpc-dev/" ~ base_distro ~ "-source-" ~ image -%}
3439
{%- set dest_image_repo = "stackhpc/" ~ base_distro ~ "-source-" ~ image -%}
3540
{%- set content = {
36-
"allow_missing": True,
41+
"allow_missing": False,
3742
"src_repo": src_image_repo,
3843
"src_is_push": true,
3944
"repository": dest_image_repo,
40-
"tags": [dev_pulp_repository_container_promotion_tag],
45+
"tags": [tag],
4146
} -%}
4247
{%- set _ = contents.append(content) -%}
43-
{%- endif -%}
4448
{%- endfor -%}
4549
{%- endfor -%}
4650
{{ contents }}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
# This playbook queries the Pulp container image tags defined in a Kayobe
3+
# configuration repository (in etc/kayobe/kolla/tags/*.yml). It then sets the
4+
# 'dev_pulp_repository_container_promotion_tags' tag map variable based
5+
# upon those tags, which defines the set of container image tags that
6+
# will be promoted when the dev-pulp-container-promote.yml playbook is run.
7+
8+
- import_playbook: kayobe-container-tag-query.yml
9+
10+
- name: Set dev Pulp container image tags to promote from Kayobe config tags
11+
hosts: localhost
12+
gather_facts: true
13+
tasks:
14+
- name: Set a fact about container image tags to promote
15+
set_fact:
16+
dev_pulp_repository_container_promotion_tags: >-
17+
{%- set tags = {} -%}
18+
{%- for base_distro in kolla_base_distros -%}
19+
{%- for image in kolla_container_images_filtered -%}
20+
{%- if image not in kolla_unbuildable_images[base_distro] -%}
21+
{%- if image in kayobe_pulp_container_tags.get(base_distro, {}) -%}
22+
{%- set distro_images = tags.setdefault(base_distro, {}) -%}
23+
{%- set _ = distro_images.setdefault(image, kayobe_pulp_container_tags[base_distro][image]) -%}
24+
{%- endif -%}
25+
{%- endif -%}
26+
{%- endfor -%}
27+
{%- endfor -%}
28+
{{ tags }}
29+
30+
- name: Display container promotion tags facts
31+
debug:
32+
var: dev_pulp_repository_container_promotion_tags
33+
34+
- name: Assert that tags variable is populated
35+
assert:
36+
that:
37+
- >-
38+
dev_pulp_repository_container_promotion_tags | length > 0
39+
msg: >-
40+
Distribution promotion tag variable
41+
'dev_pulp_repository_container_promotion_tags' is empty
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
# This playbook queries the Pulp container image tags defined in a Kayobe
3+
# configuration repository (in etc/kayobe/kolla/tags/*.yml). It then sets
4+
# the 'kayobe_pulp_container_tags' tag map variable based upon those
5+
# tags.
6+
#
7+
# The kayobe-config repository path should be specified via
8+
# kayobe_config_repo_path.
9+
10+
- name: Query container image tags for Kayobe
11+
hosts: localhost
12+
gather_facts: True
13+
vars:
14+
kayobe_config_repo_path: ""
15+
kayobe_pulp_container_tags_path: "{{ (kayobe_config_repo_path ~ '/etc/kayobe/kolla/tags') | realpath }}"
16+
tasks:
17+
- name: Fail if Kayobe config repo path is not specified
18+
fail:
19+
msg: >
20+
Kayobe config git repository path must be specified via 'kayobe_config_repo_path'.
21+
when: not kayobe_config_repo_path
22+
23+
- name: Fail if Kayobe config repo path is not a directory
24+
fail:
25+
msg: >
26+
Kayobe config git repository path {{ kayobe_config_repo_path }} is not a directory.
27+
when: kayobe_config_repo_path is not directory
28+
29+
- name: Fail if Kayobe Pulp container image tags directory not found
30+
fail:
31+
msg: >
32+
Can't find Kayobe Pulp container image tags directory {{ kayobe_pulp_container_tags_path }}.
33+
when: kayobe_pulp_container_tags_path is not directory
34+
35+
- name: Find container image tag files
36+
find:
37+
paths: "{{ kayobe_pulp_container_tags_path }}"
38+
patterns: "*.yml"
39+
register: find_result
40+
41+
- name: Assert that a container image tag file was found
42+
assert:
43+
that:
44+
find_result.matched > 0
45+
46+
- name: Set a fact about kayobe Pulp container image tags
47+
vars:
48+
base_distro: "{{ item.path | basename | splitext | first }}"
49+
distro_tags: "{{ lookup('file', item.path) | from_yaml }}"
50+
set_fact:
51+
kayobe_pulp_container_tags: "{{ kayobe_pulp_container_tags | default({}) | combine({base_distro: distro_tags}) }}"
52+
loop: "{{ find_result.files }}"
53+
loop_control:
54+
label: "{{ item.path }}"
55+
56+
- name: Display Kayobe Pulp container image tags
57+
debug:
58+
var: kayobe_pulp_container_tags

docs/usage/content-workflows.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,17 +245,22 @@ skydive_analyzer_tag: wallaby-20220811T091848
245245

246246
The [Promote container repositories](https://github.com/stackhpc/stackhpc-release-train/actions/workflows/container-promote.yml) workflow runs on demand.
247247
It should be run when container images need to be released, typically after a change to [update container image tags](#updating-container-image-tags-in-kayobe-configuration) has been approved.
248-
It runs the following playbook:
248+
It runs the following playbooks:
249249

250-
* `dev-pulp-container-promote.yml`: Promote a set of container images from `stackhpc-dev` to `stackhpc` namespace. The tag to be promoted is defined via `dev_pulp_repository_container_promotion_tag` which should be specified as an extra variable (`-e`).
250+
* `dev-pulp-container-tag-query-kayobe.yml`: Query the Pulp container image tags defined in a Kayobe configuration repository and set the tag map variable `dev_pulp_repository_container_promotion_tags` based upon those tags. A path to a Kayobe configuration repository must be specified via `kayobe_config_repo_path`.
251+
* `dev-pulp-container-promote.yml`: Promote a set of container images from `stackhpc-dev` to `stackhpc` namespace. The tags to be promoted are defined via `dev_pulp_repository_container_promotion_tags`.
251252

252253
Use GitHub Actions to run this workflow, or to run it manually:
253254

254255
```
255256
ansible-playbook -i ansible/inventory \
256-
ansible/dev-pulp-container-promote.yml
257+
ansible/dev-pulp-container-tag-query-kayobe.yml \
258+
ansible/dev-pulp-container-promote.yml \
259+
-e kayobe_config_repo_path=../stackhpc-kayobe-config/
257260
```
258261

262+
In this example, the Pulp container image tags defined in the `etc/kayobe/kolla/tags/<distro>.yml` files in `../stackhpc-kayobe-config` repository (relative to the current working directory) will be promoted to releases.
263+
259264
## Other utilities
260265

261266
* `dev-pulp-distribution-list.yml`: List available distributions in `ark`.

0 commit comments

Comments
 (0)