Skip to content

Commit d444661

Browse files
authored
Merge pull request #7 from stackhpc/github-multiple-environment-support
GitHub multiple environment support
2 parents b4a8545 + 26870a3 commit d444661

24 files changed

+358
-110
lines changed

.ansible-lint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ exclude_paths:
44

55
skip_list:
66
- galaxy[no-changelog]
7+
- meta-runtime[unsupported-version]

.github/workflows/test-collection.yml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@ jobs:
77
test:
88
name: Test github role
99
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
name:
13+
- none_default
14+
- single_default
15+
- input_default
16+
- none_custom_registry
17+
- single_custom_registry
18+
- input_custom_registry
19+
- none_custom_kayobe_argument
20+
- single_custom_kayobe_argument
21+
- input_custom_kayobe_argument
22+
- reference
23+
1024
steps:
1125
- name: Check out the codebase.
1226
uses: actions/checkout@v3
@@ -19,13 +33,13 @@ jobs:
1933
- name: Install Ansible
2034
run: pip3 install ansible
2135

22-
- name: Test the playbook.
23-
run: ansible-playbook tests/test.yml
36+
- name: Test the playbook ${{ matrix.name }}
37+
run: "ansible-playbook -i tests/inventory/hosts.yml tests/test.yml --limit ${{ matrix.name }}"
2438
env:
2539
ANSIBLE_FORCE_COLOR: '1'
2640

27-
- name: Upload workflows produced
41+
- name: Upload workflows produced ${{ matrix.name }}
2842
uses: actions/upload-artifact@v3
2943
with:
30-
name: github_kayobe_workflows
31-
path: tests/.github/workflows
44+
name: "${{ format('github_kayobe_workflows_{0}', matrix.name) }}"
45+
path: "${{ format('tests/.github/{0}', matrix.name) }}"

roles/github/README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,25 @@ The following variables can be used to make small adjustments to the composition
3636

3737
`github_output_directory`: control the location where the workflows shall be written to.
3838

39+
`github_environment_selector`: control the type of environment support the workflows should be generated with. Either `single` for fixed environment or `input` whereby the environment is controlled at `workflow_dispatch`. No environment is the default by setting `github_environment_selector` to no value or `Null`.
40+
41+
`github_kayobe_environments`: list of environments the workflows should target. Only has effect when `github_environment_selector` is `input` or `single`.
42+
3943
`github_runs_on`: control which runner can accept this workflow. See GitHub for more information on [runs-on](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idruns-on).
4044

4145
`github_image_name`: name of the kayobe image defaults to `kayobe`.
4246

4347
`github_image_tag`: tag used to select kayobe image defaults to `latest`
4448

45-
`github_registry_username`: username used to authenticate with the docker registry.
46-
47-
`github_registry_password`: password used to authenticate with the docker registry.
49+
`github_registry`: dictionary containing keys that correspond to `url`, `username`, `password` and `share` for the registry to be used by the workflows. Defaults to `ghcr.io` and uses the actors token to login. The key `share` is to indiciate if the registry is shared between environments.
4850

4951
`github_kayobe_base_image`: select the base image used when building the kayobe docker image. Default is `quay.io/centos/centos:stream8` supports OpenStack Wallaby, Xena and Yoga. Zed and higher would require `quay.io/rockylinux/rockylinux:9`.
5052

51-
`github_kayobe_arguments`: a dictionary of arguments that can be used to override the default arguments found within `vars/main.yml`. For example if you wanted to change the value of `KAYOBE_ENVIRONMENT` from its default of `production` you can simply add `KAYOBE_ENVIRONMENT` to this dictionary and it will take precedence over the defaults.
53+
`github_kayobe_arguments`: a dictionary of arguments that can be used to override the default arguments found within `vars/main.yml`. For example if you wanted to change the value of `KAYOBE_AUTOMATION_PR_TITLE` from its default, you can do by simply adding `KAYOBE_AUTOMATION_PR_TITLE` to this dictionary and it will take precedence over the default.
5254

5355
`github_*_hook:` see section [Template Hooks](#template-hooks) for information about this variables
5456

55-
`github_buildx_enable`: In some deployments the build kayobe docker image workflow has had difficulties successfully pushing the image to container registries such as Pulp if buildx has been used. It situations where failure to push images is been experienced a user might wish to disable buildx. Buildx is enabled by default.
57+
`github_buildx_enable`: In some deployments the build kayobe docker image workflow has had difficulties successfully pushing the image to container registries such as Pulp if buildx has been used. It situations where failure to push images is been experienced a user might wish to disable buildx. Buildx is disabled by default.
5658

5759
`github_buildx_inline_config`: provide configuration parameters to buildx. Useful for connecting to insecure docker registry.
5860

@@ -141,7 +143,7 @@ The following example playbook will generate a series of `reference` workflows w
141143
- name: Write Kayobe Automation Workflows for GitHub
142144
hosts: localhost
143145
roles:
144-
- stackhpc.kayobe_automation_workflows.github
146+
- stackhpc.kayobe_workflows.github
145147
```
146148

147149
License

roles/github/defaults/main.yml

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
---
22
github_output_directory: .github/workflows
33

4-
github_runs_on: self-hosted
4+
github_environment_selector:
55

6-
github_registry_url: ghcr.io
6+
github_kayobe_environments: []
77

8-
github_registry_username: !unsafe "${{ github.actor }}"
8+
github_runs_on: [self-hosted]
99

10-
github_registry_password: !unsafe "${{ secrets.GITHUB_TOKEN }}"
10+
github_registry: {}
1111

1212
github_image_name: kayobe
1313

14-
github_image_tag: latest
14+
github_image_tag: !unsafe "${{ needs.prepare-runner.outputs.openstack_release }}-latest"
1515

1616
github_kayobe_base_image: "quay.io/centos/centos:stream8"
1717

@@ -23,7 +23,7 @@ github_kayobe_hook: ""
2323

2424
github_final_hook: ""
2525

26-
github_buildx_enabled: true
26+
github_buildx_enabled: false
2727

2828
github_buildx_inline_config: ""
2929

@@ -36,26 +36,36 @@ github_tempest_test_suites: |
3636
- tempest-full
3737
3838
github_kayobe_limit_input: |
39-
kayobeLimit:
39+
kayobe_limit:
4040
description: |
4141
The ansible limit to use when running kayobe playbooks.
4242
4343
github_kayobe_tags_input: |
44-
kayobeTags:
44+
kayobe_tags:
4545
description: |
4646
The ansible tags to use when running kayobe playbooks.
4747
4848
github_kolla_limit_input: |
49-
kollaLimit:
49+
kolla_limit:
5050
description: |
5151
The ansible limit to use for kolla-ansible playbooks.
5252
5353
github_kolla_tags_input: |
54-
kollaTags:
54+
kolla_tags:
5555
description: |
5656
The ansible tags to use when running kolla-ansible playbooks.
5757
58+
github_kayobe_environment_input: |
59+
kayobe_environment:
60+
description: |
61+
Select the environment the kayobe workflow shall target.
62+
type: choice
63+
required: true
64+
default: '{{ github_kayobe_environments | first }}'
65+
options: {{ github_kayobe_environments }}
66+
5867
github_workflows:
68+
- "{{ github_prepare_runner }}"
5969
- "{{ github_build_kayobe_image }}"
6070
- "{{ github_run_kolla_config_diff }}"
6171
- "{{ github_run_infra_vm_host_configure }}"
@@ -79,6 +89,10 @@ github_workflows:
7989
- "{{ github_run_seed_vm_provision }}"
8090
- "{{ github_run_tempest }}"
8191

92+
github_prepare_runner:
93+
file_name: prepare-runner.yml
94+
use_bespoke: true
95+
8296
github_build_kayobe_image:
8397
file_name: build-kayobe-docker-image.yml
8498
use_bespoke: true
@@ -225,3 +239,4 @@ github_run_tempest:
225239
file_name: run-tempest.yml
226240
use_bespoke: true
227241
test_suites: "{{ github_tempest_test_suites }}"
242+
concurrency_group: tempest

roles/github/templates/build-kayobe-docker-image.yml.j2

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
<%- if github_environment_selector == 'input' -%>
2+
<%- set github_runs_on = github_runs_on + ['${{ matrix.environment }}'] -%>
3+
<%- set _ = github_default_registry.update({"url": "${{ vars[format('{0}_REGISTRY_URL', matrix.environment)] }}" }) -%>
4+
<%- set _ = github_default_registry.update({"username": "${{ vars[format('{0}_REGISTRY_USERNAME', matrix.environment)] }}" }) -%>
5+
<%- set _ = github_default_registry.update({"password": "${{ secrets[format('{0}_REGISTRY_PASSWORD', matrix.environment)] }}" }) -%>
6+
<%- endif -%>
17
name: %% format_file_name(workflow.file_name, is_title=true) %%
28

39
on:
@@ -8,13 +14,21 @@ env:
814
KAYOBE_USER_GID: 1000
915

1016
jobs:
17+
prepare-runner:
18+
uses: ./.github/workflows/prepare-runner.yml
1119
%% format_file_name(workflow.file_name) %%:
20+
<%- if github_environment_selector == 'input' and (github_registry.share | default(github_default_registry.share)) is false +%>
21+
strategy:
22+
matrix:
23+
environment: %% github_kayobe_environments %%
24+
<%- endif +%>
1225
runs-on: %% github_runs_on %%
1326
container:
1427
image: docker:24.0-git
1528
permissions:
1629
contents: read
17-
packages: %% 'write' if github_registry_url == 'ghcr.io' else 'none' %%
30+
packages: %% 'write' if (github_registry.url | default(github_default_registry.url)) == 'ghcr.io' else 'none' %%
31+
needs: prepare-runner
1832
steps:
1933
<% if github_checkout_hook | length >= 1 %>
2034
%% github_checkout_hook | indent(width=6, first=false) %%
@@ -28,9 +42,9 @@ jobs:
2842
- name: Log in to the Container registry
2943
uses: docker/login-action@v2
3044
with:
31-
registry: %% github_registry_url %%
32-
username: %% github_registry_username %%
33-
password: %% github_registry_password %%
45+
registry: %% github_registry.url | default(github_default_registry.url) %%
46+
username: %% github_registry.username | default(github_default_registry.username) %%
47+
password: %% github_registry.password | default(github_default_registry.password) %%
3448

3549
<% if github_buildx_enabled %>
3650
- name: Set up Docker Buildx
@@ -60,8 +74,8 @@ jobs:
6074
BASE_IMAGE=%% github_kayobe_base_image %%
6175
push: true
6276
tags: |
63-
%% github_registry_url %%/%% github_image_name %%:latest
64-
%% github_registry_url %%/%% github_image_name %%:${{ github.sha }}
77+
%% github_registry.url | default(github_default_registry.url) %%/%% github_image_name %%:%% github_image_tag %%
78+
%% github_registry.url | default(github_default_registry.url) %%/%% github_image_name %%:${{ github.sha }}
6579
<% if not github_buildx_enable_provenance %>
6680
provenance: false
6781
<% endif %>

roles/github/templates/generic.yml.j2

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,36 @@
1-
<% include "header.yml.j2" +%>
2-
1+
<%- if github_environment_selector == 'input' -%>
2+
<%- set github_runs_on = github_runs_on + ['${{ inputs.kayobe_environment }}'] -%>
3+
<%- set _ = workflow.update({"concurrency_group": "format('{0}-{1}', " + workflow.concurrency_group + ", '${{ inputs.kayobe_environment }}')" }) -%>
4+
<%- set _ = github_default_registry.update({"url": "${{ vars[format('{0}_REGISTRY_URL', inputs.kayobe_environment)] }}" }) -%>
5+
<%- set _ = github_default_registry.update({"username": "${{ vars[format('{0}_REGISTRY_USERNAME', inputs.kayobe_environment)] }}" }) -%>
6+
<%- set _ = github_default_registry.update({"password": "${{ secrets[format('{0}_REGISTRY_PASSWORD', inputs.kayobe_environment)] }}" }) -%>
7+
<%- set _ = github_default_kayobe_arguments.update({"KAYOBE_AUTOMATION_SSH_PRIVATE_KEY": "${{ secrets[format('{0}_KAYOBE_AUTOMATION_SSH_PRIVATE_KEY', inputs.kayobe_environment)] }}" }) -%>
8+
<%- set _ = github_default_kayobe_arguments.update({"KAYOBE_VAULT_PASSWORD": "${{ secrets[format('{0}_KAYOBE_VAULT_PASSWORD', inputs.kayobe_environment)] }}" }) -%>
9+
<%- set _ = github_kayobe_arguments.update({"KAYOBE_ENVIRONMENT": '${{ inputs.kayobe_environment }}'}) -%>
10+
<%- endif -%>
11+
<%- if github_environment_selector == 'single' -%>
12+
<%- set _ = github_kayobe_arguments.update({"KAYOBE_ENVIRONMENT": github_kayobe_environments | first}) -%>
13+
<%- endif -%>
14+
%% lookup('template', 'header.yml.j2') %%
315
jobs:
16+
prepare-runner:
17+
uses: ./.github/workflows/prepare-runner.yml
418
%% format_file_name(workflow.file_name) %%:
519
runs-on: %% github_runs_on %%
620
permissions:
721
contents: %% 'write' if 'KAYOBE_AUTOMATION_PR_TYPE' in workflow.arguments | flatten else 'read' %%
8-
packages: %% 'read' if github_registry_url == 'ghcr.io' else 'none' %%
22+
packages: %% 'read' if (github_registry.url | default(github_default_registry.url)) == 'ghcr.io' else 'none' %%
923
pull-requests: %% 'write' if 'KAYOBE_AUTOMATION_PR_TYPE' in workflow.arguments | flatten else 'none' %%
1024
container:
11-
image: %% github_registry_url %%/%% github_image_name %%:%% github_image_tag %%
25+
image: %% github_registry.url | default(github_default_registry.url) %%/%% github_image_name %%:%% github_image_tag %%
1226
credentials:
13-
username: %% github_registry_username %%
14-
password: %% github_registry_password %%
27+
username: %% github_registry.username | default(github_default_registry.username) %%
28+
password: %% github_registry.password | default(github_default_registry.password) %%
1529
concurrency:
1630
group: %% workflow.concurrency_group %%
1731
cancel-in-progress: false
1832
timeout-minutes: %% github_timeout %%
33+
needs: prepare-runner
1934
steps:
2035
<% if github_checkout_hook | length >= 1 %>
2136
%% github_checkout_hook | indent(width=6, first=false) %%
@@ -37,9 +52,11 @@ jobs:
3752
/src/.automation/pipeline/%% workflow.file_name[4:-4] %%.sh
3853
<%- if workflow.arguments is defined +%>
3954
env:
40-
KAYOBE_ENVIRONMENT: '%% github_kayobe_arguments.KAYOBE_ENVIRONMENT | default(github_default_kayobe_arguments.KAYOBE_ENVIRONMENT) %%'
41-
KAYOBE_AUTOMATION_SSH_PRIVATE_KEY: '%% github_kayobe_arguments.KAYOBE_AUTOMATION_SSH_PRIVATE_KEY | default(github_default_kayobe_arguments.KAYOBE_AUTOMATION_SSH_PRIVATE_KEY) %%'
42-
KAYOBE_VAULT_PASSWORD: '%% github_kayobe_arguments.KAYOBE_VAULT_PASSWORD | default(github_default_kayobe_arguments.KAYOBE_VAULT_PASSWORD) %%'
55+
<% if github_environment_selector is not none %>
56+
KAYOBE_ENVIRONMENT: '%% github_kayobe_arguments.KAYOBE_ENVIRONMENT %%'
57+
<% endif %>
58+
KAYOBE_AUTOMATION_SSH_PRIVATE_KEY: "%% github_kayobe_arguments.KAYOBE_AUTOMATION_SSH_PRIVATE_KEY | default(github_default_kayobe_arguments.KAYOBE_AUTOMATION_SSH_PRIVATE_KEY) %%"
59+
KAYOBE_VAULT_PASSWORD: "%% github_kayobe_arguments.KAYOBE_VAULT_PASSWORD | default(github_default_kayobe_arguments.KAYOBE_VAULT_PASSWORD) %%"
4360
<%- for argument in workflow.arguments | flatten +%>
4461
%% argument %%: '%% github_kayobe_arguments[argument] | default(github_default_kayobe_arguments[argument]) %%'
4562
<%- endfor +%>
Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
1-
name: %% format_file_name(workflow.file_name, is_title=true) %%
1+
{%- macro format_file_name(file_name, is_title=false, is_subtitle=false) -%}
2+
{%- set formatted_name = file_name | splitext | first -%}
3+
{%- if is_title -%}
4+
{%- set formatted_name = formatted_name | replace('-', ' ') | title | regex_replace('Vm','VM') -%}
5+
{%- endif -%}
6+
{%- if is_subtitle -%}
7+
{%- set formatted_name = formatted_name | replace('-', ' ') | capitalize | regex_replace('vm','VM') -%}
8+
{%- endif -%}
9+
{{ formatted_name }}
10+
{%- endmacro -%}
11+
name: {{ format_file_name(workflow.file_name, is_title=true) }}
212

313
on:
4-
<%- if workflow.trigger is defined +%>
5-
<%- for trigger_name in workflow.trigger.keys() +%>
6-
<%- if trigger_name == 'schedule' +%>
14+
{%- if workflow.trigger is defined +%}
15+
{%- for trigger_name in workflow.trigger.keys() +%}
16+
{%- if trigger_name == 'schedule' +%}
717
schedule:
8-
- cron: '%% workflow.trigger['schedule']['cron'] %%'
9-
<%- elif trigger_name == 'workflow_dispatch' +%>
18+
- cron: '{{ workflow.trigger['schedule']['cron'] }}'
19+
{%- elif trigger_name == 'workflow_dispatch' +%}
1020
workflow_dispatch:
11-
<%- if workflow.trigger['workflow_dispatch'] is not none +%>
21+
{%- if workflow.trigger['workflow_dispatch'] is not none +%}
1222
inputs:
13-
%% workflow.trigger['workflow_dispatch'] | flatten | join('') | indent(6) | trim %%
14-
<%- endif +%>
15-
<%- endif +%>
16-
<%- endfor +%>
17-
<%- endif +%>
23+
{{ workflow.trigger['workflow_dispatch'] | flatten | join('') | indent(6) | trim }}
24+
{%- if github_environment_selector == 'input' +%}
25+
{{ github_kayobe_environment_input | flatten | join('') | indent(6) | trim }}
26+
{%- endif +%}
27+
{%- endif +%}
28+
{%- endif +%}
29+
{%- endfor +%}
30+
{%- endif -%}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: %% format_file_name(workflow.file_name, is_title=true) %%
2+
3+
on:
4+
workflow_call:
5+
outputs:
6+
openstack_release:
7+
description: "The version of OpenStack/Kayobe to be used by the runner."
8+
value: ${{ jobs.prepare-runner.outputs.openstack_release }}
9+
10+
jobs:
11+
prepare-runner:
12+
runs-on: %% github_runs_on %%
13+
container:
14+
image: alpine:latest
15+
permissions:
16+
contents: read
17+
packages: read
18+
outputs:
19+
openstack_release: ${{ steps.openstack_release.outputs.openstack_release }}
20+
steps:
21+
- name: Checkout kayobe config
22+
uses: actions/checkout@v3
23+
24+
- name: Extract OpenStack Release
25+
id: openstack_release
26+
run: |
27+
BRANCH=$(awk -F'=' '/defaultbranch/ {print $2}' .gitreview)
28+
echo "openstack_release=${BRANCH}" | sed "s|stable/||" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)