Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
bb0fea6
feat: add environment variables
jackhodgkiss Sep 28, 2023
21686bb
feat: add `concurrency_group` to `tempest`
jackhodgkiss Sep 28, 2023
4759aaf
fix: use `snake_case` for `inputs`
jackhodgkiss Sep 28, 2023
99dfc11
feat!: add multiple environment support to tempest
jackhodgkiss Sep 28, 2023
51c6b8c
fix: use `snake_case` for `tempest` vars
jackhodgkiss Sep 28, 2023
1d0afd2
feat: add environment support to `generic`
jackhodgkiss Sep 28, 2023
c42b868
feat: add environment support to `build-kayobe`
jackhodgkiss Sep 28, 2023
f17aaea
feat: add environment support to `config-diff`
jackhodgkiss Sep 28, 2023
cc800ca
fix: add missing `environment` input
jackhodgkiss Sep 28, 2023
266741c
fix: remove unwanted whitespace
jackhodgkiss Sep 28, 2023
cdc046f
fix: cannot concatenate between str and list
jackhodgkiss Sep 28, 2023
63164b7
fix: add missing newline
jackhodgkiss Sep 28, 2023
a145abe
feat: test both single and multiple environments
jackhodgkiss Sep 28, 2023
742d01e
fix: remove excess newlines
jackhodgkiss Sep 28, 2023
c47bd9f
fix: support `ghcr.io` with multiple environments
jackhodgkiss Sep 28, 2023
c3ff892
fix: artifact name collision
jackhodgkiss Sep 28, 2023
61cce9d
feat: test registry support with custom password
jackhodgkiss Sep 28, 2023
e59e242
feat: use unsafe map
jackhodgkiss Sep 28, 2023
566cfef
fix: use plaintext password in test
jackhodgkiss Sep 28, 2023
3a8128a
fix: use `github_environment_selector`
jackhodgkiss Oct 3, 2023
980a27c
fix: improve templating of `inputs`
jackhodgkiss Oct 3, 2023
a05b502
feat: only pass `KAYOBE_ENVIRONMENT` if required
jackhodgkiss Oct 3, 2023
ab277bc
feat: allow arguments to be overriden with mult env
jackhodgkiss Oct 3, 2023
a7fcbe3
fix: improve `single` environment support
jackhodgkiss Oct 3, 2023
ef730a4
fix: customise `TEMPEST_OPENRC`
jackhodgkiss Oct 3, 2023
0229ce1
feat: allow registry attributes to be overridden
jackhodgkiss Oct 4, 2023
ba886a1
feat: improve testing of `github` role
jackhodgkiss Oct 4, 2023
b440bf1
fix: add `inventory` to playbook
jackhodgkiss Oct 4, 2023
3ce4141
fix: `format` func call
jackhodgkiss Oct 4, 2023
860f674
fix: `format` syntax
jackhodgkiss Oct 4, 2023
8203621
fix: linting issues
jackhodgkiss Oct 4, 2023
780a235
feat: add support for selecting `release`
jackhodgkiss Oct 13, 2023
f979b70
fix: `prepate` -> `prepare`
jackhodgkiss Oct 13, 2023
26d9b64
fix: add `github_image_tag`
jackhodgkiss Oct 13, 2023
20f2d6d
fix: single environment config diff
jackhodgkiss Oct 13, 2023
5617be6
Revert "fix: single environment config diff"
jackhodgkiss Oct 13, 2023
53a7d0e
fix: single environment config diff
jackhodgkiss Oct 13, 2023
51a9b17
typo: add missing `e`
jackhodgkiss Oct 15, 2023
02931bc
fix: `github_environment_selector` value
jackhodgkiss Oct 15, 2023
9777ab2
fix: mark `github_image_tag` as `unsafe`
jackhodgkiss Oct 15, 2023
ee23057
feat: add support for sharing registry
jackhodgkiss Oct 17, 2023
7dabf14
Merge pull request #8 from stackhpc/github-mult-env
jackhodgkiss Oct 17, 2023
612c1b7
fix: remove unused variable from `tests`
jackhodgkiss Oct 23, 2023
7827460
feat: remove rally registry settings
jackhodgkiss Oct 23, 2023
1009a06
fix: use newer environment variable
jackhodgkiss Oct 23, 2023
44ed47f
feat: use `.gitreview` for selecting release
jackhodgkiss Oct 23, 2023
9a47c26
feat: empty var for `github_environment_selector`
jackhodgkiss Oct 23, 2023
45c95a0
Update roles/github/README.md
jackhodgkiss Oct 23, 2023
85612c5
feat: remove `header.yml.j2`
jackhodgkiss Oct 23, 2023
e0d46e8
feat: remove `KAYOBE_ENVIRONMENT`
jackhodgkiss Oct 24, 2023
5e107cb
fix: undefined variable for `single` env workflows
jackhodgkiss Oct 24, 2023
1f242d5
feat: disable `buildx` step by default
jackhodgkiss Oct 24, 2023
a2dd70e
Revert "feat: remove `header.yml.j2`"
jackhodgkiss Oct 24, 2023
932b690
fix!: backwards compatibility with nested vars
jackhodgkiss Oct 24, 2023
51dee17
feat: minor changes to `README.md`
jackhodgkiss Oct 24, 2023
26870a3
feat: update README.md
jackhodgkiss Oct 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ exclude_paths:

skip_list:
- galaxy[no-changelog]
- meta-runtime[unsupported-version]
24 changes: 19 additions & 5 deletions .github/workflows/test-collection.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ jobs:
test:
name: Test github role
runs-on: ubuntu-latest
strategy:
matrix:
name:
- none_default
- single_default
- input_default
- none_custom_registry
- single_custom_registry
- input_custom_registry
- none_custom_kayobe_argument
- single_custom_kayobe_argument
- input_custom_kayobe_argument
- reference

steps:
- name: Check out the codebase.
uses: actions/checkout@v3
Expand All @@ -19,13 +33,13 @@ jobs:
- name: Install Ansible
run: pip3 install ansible

- name: Test the playbook.
run: ansible-playbook tests/test.yml
- name: Test the playbook ${{ matrix.name }}
run: "ansible-playbook -i tests/inventory/hosts.yml tests/test.yml --limit ${{ matrix.name }}"
env:
ANSIBLE_FORCE_COLOR: '1'

- name: Upload workflows produced
- name: Upload workflows produced ${{ matrix.name }}
uses: actions/upload-artifact@v3
with:
name: github_kayobe_workflows
path: tests/.github/workflows
name: "${{ format('github_kayobe_workflows_{0}', matrix.name) }}"
path: "${{ format('tests/.github/{0}', matrix.name) }}"
14 changes: 8 additions & 6 deletions roles/github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,25 @@ The following variables can be used to make small adjustments to the composition

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

`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`.

`github_kayobe_environments`: list of environments the workflows should target. Only has effect when `github_environment_selector` is `input` or `single`.

`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).

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

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

`github_registry_username`: username used to authenticate with the docker registry.

`github_registry_password`: password used to authenticate with the docker registry.
`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.

`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`.

`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.
`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.

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

`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.
`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.

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

Expand Down Expand Up @@ -141,7 +143,7 @@ The following example playbook will generate a series of `reference` workflows w
- name: Write Kayobe Automation Workflows for GitHub
hosts: localhost
roles:
- stackhpc.kayobe_automation_workflows.github
- stackhpc.kayobe_workflows.github
```

License
Expand Down
35 changes: 25 additions & 10 deletions roles/github/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
---
github_output_directory: .github/workflows

github_runs_on: self-hosted
github_environment_selector:

github_registry_url: ghcr.io
github_kayobe_environments: []

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

github_registry_password: !unsafe "${{ secrets.GITHUB_TOKEN }}"
github_registry: {}

github_image_name: kayobe

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

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

Expand All @@ -23,7 +23,7 @@ github_kayobe_hook: ""

github_final_hook: ""

github_buildx_enabled: true
github_buildx_enabled: false

github_buildx_inline_config: ""

Expand All @@ -36,26 +36,36 @@ github_tempest_test_suites: |
- tempest-full

github_kayobe_limit_input: |
kayobeLimit:
kayobe_limit:
description: |
The ansible limit to use when running kayobe playbooks.

github_kayobe_tags_input: |
kayobeTags:
kayobe_tags:
description: |
The ansible tags to use when running kayobe playbooks.

github_kolla_limit_input: |
kollaLimit:
kolla_limit:
description: |
The ansible limit to use for kolla-ansible playbooks.

github_kolla_tags_input: |
kollaTags:
kolla_tags:
description: |
The ansible tags to use when running kolla-ansible playbooks.

github_kayobe_environment_input: |
kayobe_environment:
description: |
Select the environment the kayobe workflow shall target.
type: choice
required: true
default: '{{ github_kayobe_environments | first }}'
options: {{ github_kayobe_environments }}

github_workflows:
- "{{ github_prepare_runner }}"
- "{{ github_build_kayobe_image }}"
- "{{ github_run_kolla_config_diff }}"
- "{{ github_run_infra_vm_host_configure }}"
Expand All @@ -79,6 +89,10 @@ github_workflows:
- "{{ github_run_seed_vm_provision }}"
- "{{ github_run_tempest }}"

github_prepare_runner:
file_name: prepare-runner.yml
use_bespoke: true

github_build_kayobe_image:
file_name: build-kayobe-docker-image.yml
use_bespoke: true
Expand Down Expand Up @@ -225,3 +239,4 @@ github_run_tempest:
file_name: run-tempest.yml
use_bespoke: true
test_suites: "{{ github_tempest_test_suites }}"
concurrency_group: tempest
26 changes: 20 additions & 6 deletions roles/github/templates/build-kayobe-docker-image.yml.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<%- if github_environment_selector == 'input' -%>
<%- set github_runs_on = github_runs_on + ['${{ matrix.environment }}'] -%>
<%- set _ = github_default_registry.update({"url": "${{ vars[format('{0}_REGISTRY_URL', matrix.environment)] }}" }) -%>
<%- set _ = github_default_registry.update({"username": "${{ vars[format('{0}_REGISTRY_USERNAME', matrix.environment)] }}" }) -%>
<%- set _ = github_default_registry.update({"password": "${{ secrets[format('{0}_REGISTRY_PASSWORD', matrix.environment)] }}" }) -%>
<%- endif -%>
name: %% format_file_name(workflow.file_name, is_title=true) %%

on:
Expand All @@ -8,13 +14,21 @@ env:
KAYOBE_USER_GID: 1000

jobs:
prepare-runner:
uses: ./.github/workflows/prepare-runner.yml
%% format_file_name(workflow.file_name) %%:
<%- if github_environment_selector == 'input' and (github_registry.share | default(github_default_registry.share)) is false +%>
strategy:
matrix:
environment: %% github_kayobe_environments %%
<%- endif +%>
runs-on: %% github_runs_on %%
container:
image: docker:24.0-git
permissions:
contents: read
packages: %% 'write' if github_registry_url == 'ghcr.io' else 'none' %%
packages: %% 'write' if (github_registry.url | default(github_default_registry.url)) == 'ghcr.io' else 'none' %%
needs: prepare-runner
steps:
<% if github_checkout_hook | length >= 1 %>
%% github_checkout_hook | indent(width=6, first=false) %%
Expand All @@ -28,9 +42,9 @@ jobs:
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: %% github_registry_url %%
username: %% github_registry_username %%
password: %% github_registry_password %%
registry: %% github_registry.url | default(github_default_registry.url) %%
username: %% github_registry.username | default(github_default_registry.username) %%
password: %% github_registry.password | default(github_default_registry.password) %%

<% if github_buildx_enabled %>
- name: Set up Docker Buildx
Expand Down Expand Up @@ -60,8 +74,8 @@ jobs:
BASE_IMAGE=%% github_kayobe_base_image %%
push: true
tags: |
%% github_registry_url %%/%% github_image_name %%:latest
%% github_registry_url %%/%% github_image_name %%:${{ github.sha }}
%% github_registry.url | default(github_default_registry.url) %%/%% github_image_name %%:%% github_image_tag %%
%% github_registry.url | default(github_default_registry.url) %%/%% github_image_name %%:${{ github.sha }}
<% if not github_buildx_enable_provenance %>
provenance: false
<% endif %>
Expand Down
35 changes: 26 additions & 9 deletions roles/github/templates/generic.yml.j2
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
<% include "header.yml.j2" +%>

<%- if github_environment_selector == 'input' -%>
<%- set github_runs_on = github_runs_on + ['${{ inputs.kayobe_environment }}'] -%>
<%- set _ = workflow.update({"concurrency_group": "format('{0}-{1}', " + workflow.concurrency_group + ", '${{ inputs.kayobe_environment }}')" }) -%>
<%- set _ = github_default_registry.update({"url": "${{ vars[format('{0}_REGISTRY_URL', inputs.kayobe_environment)] }}" }) -%>
<%- set _ = github_default_registry.update({"username": "${{ vars[format('{0}_REGISTRY_USERNAME', inputs.kayobe_environment)] }}" }) -%>
<%- set _ = github_default_registry.update({"password": "${{ secrets[format('{0}_REGISTRY_PASSWORD', inputs.kayobe_environment)] }}" }) -%>
<%- set _ = github_default_kayobe_arguments.update({"KAYOBE_AUTOMATION_SSH_PRIVATE_KEY": "${{ secrets[format('{0}_KAYOBE_AUTOMATION_SSH_PRIVATE_KEY', inputs.kayobe_environment)] }}" }) -%>
<%- set _ = github_default_kayobe_arguments.update({"KAYOBE_VAULT_PASSWORD": "${{ secrets[format('{0}_KAYOBE_VAULT_PASSWORD', inputs.kayobe_environment)] }}" }) -%>
<%- set _ = github_kayobe_arguments.update({"KAYOBE_ENVIRONMENT": '${{ inputs.kayobe_environment }}'}) -%>
<%- endif -%>
<%- if github_environment_selector == 'single' -%>
<%- set _ = github_kayobe_arguments.update({"KAYOBE_ENVIRONMENT": github_kayobe_environments | first}) -%>
<%- endif -%>
%% lookup('template', 'header.yml.j2') %%
jobs:
prepare-runner:
uses: ./.github/workflows/prepare-runner.yml
%% format_file_name(workflow.file_name) %%:
runs-on: %% github_runs_on %%
permissions:
contents: %% 'write' if 'KAYOBE_AUTOMATION_PR_TYPE' in workflow.arguments | flatten else 'read' %%
packages: %% 'read' if github_registry_url == 'ghcr.io' else 'none' %%
packages: %% 'read' if (github_registry.url | default(github_default_registry.url)) == 'ghcr.io' else 'none' %%
pull-requests: %% 'write' if 'KAYOBE_AUTOMATION_PR_TYPE' in workflow.arguments | flatten else 'none' %%
container:
image: %% github_registry_url %%/%% github_image_name %%:%% github_image_tag %%
image: %% github_registry.url | default(github_default_registry.url) %%/%% github_image_name %%:%% github_image_tag %%
credentials:
username: %% github_registry_username %%
password: %% github_registry_password %%
username: %% github_registry.username | default(github_default_registry.username) %%
password: %% github_registry.password | default(github_default_registry.password) %%
concurrency:
group: %% workflow.concurrency_group %%
cancel-in-progress: false
timeout-minutes: %% github_timeout %%
needs: prepare-runner
steps:
<% if github_checkout_hook | length >= 1 %>
%% github_checkout_hook | indent(width=6, first=false) %%
Expand All @@ -37,9 +52,11 @@ jobs:
/src/.automation/pipeline/%% workflow.file_name[4:-4] %%.sh
<%- if workflow.arguments is defined +%>
env:
KAYOBE_ENVIRONMENT: '%% github_kayobe_arguments.KAYOBE_ENVIRONMENT | default(github_default_kayobe_arguments.KAYOBE_ENVIRONMENT) %%'
KAYOBE_AUTOMATION_SSH_PRIVATE_KEY: '%% github_kayobe_arguments.KAYOBE_AUTOMATION_SSH_PRIVATE_KEY | default(github_default_kayobe_arguments.KAYOBE_AUTOMATION_SSH_PRIVATE_KEY) %%'
KAYOBE_VAULT_PASSWORD: '%% github_kayobe_arguments.KAYOBE_VAULT_PASSWORD | default(github_default_kayobe_arguments.KAYOBE_VAULT_PASSWORD) %%'
<% if github_environment_selector is not none %>
KAYOBE_ENVIRONMENT: '%% github_kayobe_arguments.KAYOBE_ENVIRONMENT %%'
<% endif %>
KAYOBE_AUTOMATION_SSH_PRIVATE_KEY: "%% github_kayobe_arguments.KAYOBE_AUTOMATION_SSH_PRIVATE_KEY | default(github_default_kayobe_arguments.KAYOBE_AUTOMATION_SSH_PRIVATE_KEY) %%"
KAYOBE_VAULT_PASSWORD: "%% github_kayobe_arguments.KAYOBE_VAULT_PASSWORD | default(github_default_kayobe_arguments.KAYOBE_VAULT_PASSWORD) %%"
<%- for argument in workflow.arguments | flatten +%>
%% argument %%: '%% github_kayobe_arguments[argument] | default(github_default_kayobe_arguments[argument]) %%'
<%- endfor +%>
Expand Down
37 changes: 25 additions & 12 deletions roles/github/templates/header.yml.j2
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
name: %% format_file_name(workflow.file_name, is_title=true) %%
{%- macro format_file_name(file_name, is_title=false, is_subtitle=false) -%}
{%- set formatted_name = file_name | splitext | first -%}
{%- if is_title -%}
{%- set formatted_name = formatted_name | replace('-', ' ') | title | regex_replace('Vm','VM') -%}
{%- endif -%}
{%- if is_subtitle -%}
{%- set formatted_name = formatted_name | replace('-', ' ') | capitalize | regex_replace('vm','VM') -%}
{%- endif -%}
{{ formatted_name }}
{%- endmacro -%}
name: {{ format_file_name(workflow.file_name, is_title=true) }}

on:
<%- if workflow.trigger is defined +%>
<%- for trigger_name in workflow.trigger.keys() +%>
<%- if trigger_name == 'schedule' +%>
{%- if workflow.trigger is defined +%}
{%- for trigger_name in workflow.trigger.keys() +%}
{%- if trigger_name == 'schedule' +%}
schedule:
- cron: '%% workflow.trigger['schedule']['cron'] %%'
<%- elif trigger_name == 'workflow_dispatch' +%>
- cron: '{{ workflow.trigger['schedule']['cron'] }}'
{%- elif trigger_name == 'workflow_dispatch' +%}
workflow_dispatch:
<%- if workflow.trigger['workflow_dispatch'] is not none +%>
{%- if workflow.trigger['workflow_dispatch'] is not none +%}
inputs:
%% workflow.trigger['workflow_dispatch'] | flatten | join('') | indent(6) | trim %%
<%- endif +%>
<%- endif +%>
<%- endfor +%>
<%- endif +%>
{{ workflow.trigger['workflow_dispatch'] | flatten | join('') | indent(6) | trim }}
{%- if github_environment_selector == 'input' +%}
{{ github_kayobe_environment_input | flatten | join('') | indent(6) | trim }}
{%- endif +%}
{%- endif +%}
{%- endif +%}
{%- endfor +%}
{%- endif -%}
28 changes: 28 additions & 0 deletions roles/github/templates/prepare-runner.yml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: %% format_file_name(workflow.file_name, is_title=true) %%

on:
workflow_call:
outputs:
openstack_release:
description: "The version of OpenStack/Kayobe to be used by the runner."
value: ${{ jobs.prepare-runner.outputs.openstack_release }}

jobs:
prepare-runner:
runs-on: %% github_runs_on %%
container:
image: alpine:latest
permissions:
contents: read
packages: read
outputs:
openstack_release: ${{ steps.openstack_release.outputs.openstack_release }}
steps:
- name: Checkout kayobe config
uses: actions/checkout@v3

- name: Extract OpenStack Release
id: openstack_release
run: |
BRANCH=$(awk -F'=' '/defaultbranch/ {print $2}' .gitreview)
echo "openstack_release=${BRANCH}" | sed "s|stable/||" >> $GITHUB_OUTPUT
Loading