Skip to content

Commit a725683

Browse files
authored
Merge pull request #753 from stackhpc/add-kayobe-workflows
Add Kayobe Workflows [GitHub]
2 parents d6a8607 + 9e0032a commit a725683

File tree

9 files changed

+294
-0
lines changed

9 files changed

+294
-0
lines changed

doc/source/configuration/ci-cd.rst

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
=====
2+
CI/CD
3+
=====
4+
5+
Concepts
6+
========
7+
8+
The CI/CD system developed for managing Kayobe based OpenStack clouds is composed of three main components; workflows, runners and kayobe automation.
9+
Firstly, the workflows are files which describe a series of tasks to be performed in relation to the deployed cloud.
10+
These workflows are executed on request, on schedule or in response to an event such as a pull request being opened.
11+
The workflows are designed to carry out various day-to-day activites such as; running Tempest tests, configuring running services or displaying the change to configuration files if a pull request is merged.
12+
Secondly, in order for the workflows to run against a cloud we would need private runners present within the cloud positioned in such a way they can reach the internal network and public API.
13+
Deployment of private runners is supported by all major providers with the use of community developed Ansible roles.
14+
Finally, due to the requirement that we support various different platforms tooling in the form of `Kayobe automation <https://github.com/stackhpc/kayobe-automation/>`__ was developed.
15+
This tooling is not tied to any single CI/CD platform as all tasks are a series of shell script and Ansible playbooks which are designed to run in a purpose build kayobe container.
16+
This is complemented by the use of an Ansible collection known as `stackhpc.kayobe_workflows <https://github.com/stackhpc/ansible-collection-kayobe-workflows/>`__ which aims to provide users with a quick and easy way of customising all workflows to fit within a customer's cloud.
17+
18+
Currently we support the creation and deployment of workflows for GitHub with Gitlab support being actively worked upon.
19+
20+
Kayobe Automation
21+
-----------------
22+
23+
`Kayobe automation <https://github.com/stackhpc/kayobe-automation/>`__ is a collection of scripts and tools that automate kayobe operations.
24+
It is deployed and controlled by CI/CD platforms such as GitHub actions and GitLab pipelines.
25+
Kayobe automation provides users with an easy process to perform tasks such as: overcloud service deploy, config-diff, tempest testing, and many more.
26+
With it being integrated into platforms such as GitHub or GitLab it builds a close relationship between the contents of the deployments kayobe configuration and what is currently deployed.
27+
This is because operations such as opening a pull request will trigger a config diff to be generated providing insight on what impact it might have on services or a tempest test that could be scheduled to run daily providing knowledge of faults earlier than before.
28+
29+
Workflows
30+
---------
31+
32+
Kayobe automation has been designed to be independent of any CI/CD platform with all tasks running inside of a purpose built Kayobe container.
33+
However, platform specific workflows need to be deployed to bridge the gap between the contents of Kayobe Automation and these CI/CD platforms.
34+
Workflows are templated for each Kayobe configuration repository, ensuring appropriate workflow input parameters are defined, and any necessary customisations can be applied.
35+
The templating of workflows is offered through the `stackhpc.kayobe_workflows <https://github.com/stackhpc/ansible-collection-kayobe-workflows/>`__ collection which currently supports GitHub workflows.
36+
37+
Runners
38+
-------
39+
40+
Runners are purpose built services tied to a particular service vendor such as GitHub Actions or GitLab CI.
41+
These services will listen for jobs which have been tagged appropriately and dispatched to these specific runners.
42+
The runners will need to be deployed using existing roles and playbooks whereby the binary/package is downloaded and registered using a special token.
43+
In some deployments runner hosts can be shared between environments however this is not always true and dedicated hosts will need to be used for each environment you intend to deploy kayobe automation within.
44+
45+
GitHub Actions
46+
=================
47+
48+
To enable CI/CD where GitHub Actions is used please follow the steps described below starting with the deployment of the runners.
49+
50+
Runner Deployment
51+
-----------------
52+
53+
1. Identify a suitable host for hosting the runners.
54+
GitHub runners need to be deployed on a host which has not had Docker deployed using kolla.
55+
This is because GitHub runners cannot provide `network options when running in a container <https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idcontaineroptions>`__.
56+
57+
Ideally an Infra VM could be used here or failing that the control host.
58+
Wherever it is deployed the host will need access to the :code:`admin_network`, :code:`public_network` and the :code:`pulp registry` on the seed.
59+
60+
2. Edit the environment's :code:`${KAYOBE_CONFIG_PATH}/environments/${KAYOBE_ENVIRONMENT}/inventory/groups` to add the predefined :code:`github-runners` group to :code:`infra-vms`
61+
62+
.. code-block:: ini
63+
64+
[infra-vms:children]
65+
github-runners
66+
67+
3. Edit the environment's :code:`${KAYOBE_CONFIG_PATH}/environments/${KAYOBE_ENVIRONMENT}/inventory/hosts` to define the host(s) that will host the runners.
68+
69+
.. code-block:: ini
70+
71+
[github-runners]
72+
prod-runner-01
73+
74+
4. Provide all the relevant Kayobe :code:`group_vars` for :code:`github-runners` under :code:`${KAYOBE_CONFIG_PATH}/environments/${KAYOBE_ENVIRONMENT}/inventory/group_vars/github-runners`
75+
* `infra-vms` ensuring all required `infra_vm_extra_network_interfaces` are defined
76+
* `network-interfaces`
77+
* `python-interpreter.yml` ensuring that `ansible_python_interpreter: /usr/bin/python3` has been set
78+
79+
5. Edit the ``${KAYOBE_CONFIG_PATH}/inventory/group_vars/github-runners/runners.yml`` file which will contain the variables required to deploy a series of runners.
80+
Below is a core set of variables that will require consideration and modification for successful deployment of the runners.
81+
The number of runners deployed can be configured by removing and extending the dict :code:`github-runners`.
82+
As for how many runners present three is suitable number as this would prevent situations where long running jobs could halt progress other tasks whilst waiting for a free runner.
83+
You might want to increase the number of runners if usage demands it or new workflows make use of multiple parallel jobs.
84+
85+
Note :code:`github_registry` and the elements of the dict control the registry settings for pulling and pushing container images used by the workflows.
86+
In the example below the registry settings have been adapted to demonstrate what a shared registry between environments might look like.
87+
This values maybe suitable for your deployment providing all environments can reach the same registry.
88+
If the all of the environments use their own registry and nothing is shared between them then :code:`github_registry` can omitted from the file and the template will expect environment specific secrets and variables to be added to the repository settings.
89+
This is discussed further in the next section.
90+
91+
.. code-block:: yaml
92+
93+
---
94+
runner_user: VM_USER_NAME_HERE
95+
github_account: ORG_NAME_HERE
96+
github_repo: KAYOBE_CONFIG_REPO_NAME_HERE
97+
access_token: "{{ secrets_github_access_token }}"
98+
99+
default_runner_labels:
100+
- kayobe
101+
- openstack
102+
- "{{ kayobe_environment | default(omit) }}"
103+
104+
github_registry:
105+
url: pulp.example.com
106+
username: admin
107+
password: ${{ secrets.REGISTRY_PASSWORD }}
108+
share: true
109+
110+
github_runners:
111+
runner_01: {}
112+
runner_02: {}
113+
runner_03: {}
114+
115+
6. Obtain a personal access token that would enable the registration of GitHub runners against the `github_account` and `github_repo` defined above.
116+
This token ideally should be `fine-grained personal access token <https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-fine-grained-personal-access-token>`__ which may require the organisation to enable such tokens beforehand.
117+
Steps can be found `here <https://docs.github.com/en/organizations/managing-programmatic-access-to-your-organization/setting-a-personal-access-token-policy-for-your-organization>`__.
118+
The repository permissions for a fine-grained personal access token should be; :code:`Actions: R/W, Administration: R/W, Metadata: R`
119+
Once the key has been obtained, add it to :code:`secrets.yml` under :code:`secrets_github_access_token`
120+
121+
7. If the host is an actual Infra VM then please refer to upstream `Infrastructure VMs <https://docs.openstack.org/kayobe/latest/configuration/reference/infra-vms.html>`__ documentation for additional configuration and steps.
122+
123+
8. Run :code:`kayobe playbook run ${KAYOBE_CONFIG_PATH}/ansible/deploy-github-runner.yml`
124+
125+
9. Check runners have registered properly by visiting the repository's :code:`Action` tab -> :code:`Runners` -> :code:`Self-hosted runners`
126+
127+
10. Repeat the above steps for each environment you intend to deploy runners within.
128+
You can share the fine-grained access token between environments.
129+
130+
Workflow Deployment
131+
-------------------
132+
133+
1. Edit :code:`${KAYOBE_CONFIG_PATH}/inventory/group_vars/github-writer/writer.yml` in the base configuration making the appropriate changes to your deployments specific needs. See documentation for `stackhpc.kayobe_workflows.github <https://github.com/stackhpc/ansible-collection-kayobe-workflows/tree/main/roles/github>`__.
134+
135+
2. Run :code:`kayobe playbook run ${KAYOBE_CONFIG_PATH}/ansible/write-github-workflows.yml`
136+
137+
3. Add all required secrets and variables to repository either via the GitHub UI or GitHub CLI (may require repository owner)
138+
139+
+----------------------------------------------------------------------------------+
140+
| Secrets |
141+
+===================================+==============================================+
142+
| Single Environment | Multiple Environments |
143+
+-----------------------------------+----------------------------------------------+
144+
| KAYOBE_AUTOMATION_SSH_PRIVATE_KEY | <ENV_NAME>_KAYOBE_AUTOMATION_SSH_PRIVATE_KEY |
145+
+-----------------------------------+----------------------------------------------+
146+
| KAYOBE_VAULT_PASSWORD | <ENV_NAME>_KAYOBE_VAULT_PASSWORD |
147+
+-----------------------------------+----------------------------------------------+
148+
| REGISTRY_PASSWORD | <ENV_NAME>_REGISTRY_PASSWORD |
149+
+-----------------------------------+----------------------------------------------+
150+
| TEMPEST_OPENRC | <ENV_NAME>_TEMPEST_OPENRC |
151+
+-----------------------------------+----------------------------------------------+
152+
153+
+-------------------------------------------------------+
154+
| VARIABLES |
155+
+====================+==================================+
156+
| Single Environment | Multiple Environments |
157+
+--------------------+----------------------------------+
158+
| REGISTRY_URL | <ENV_NAME>_REGISTRY_URL |
159+
+--------------------+----------------------------------+
160+
| REGISTRY_USERNAME | <ENV_NAME>_REGISTRY_USERNAME |
161+
+--------------------+----------------------------------+
162+
163+
Note the above tables shows the secrets and variables one may need to add to GitHub for a successful deployment.
164+
When adding secrets and variables make sure to adhere to the naming standards and ensure the :code:`<ENV_NAME>` is replaced with all supported kayobe environments in uppercase.
165+
166+
4. Commit and push all newly generated workflows found under :code:`.github/workflows`
167+
168+
Final Steps
169+
-----------
170+
171+
Some final steps include the following: running config-diff will require that :code:`.automation.conf/config.sh` contains a list :code:`KAYOBE_CONFIG_VAULTED_FILES_PATHS_EXTRA` of all vaulted files contained within the config.
172+
All such files can be found with :code:`grep -r "$ANSIBLE_VAULT;1.1;AES256" .` though make sure NOT to include `kolla/passwords.yml` and `secrets.yml`
173+
Also make sure tempest has been configured appropriately in :code:`.automation.conf/config.sh` to meet the limitations of a given deployment such as not using a too high of :code:`TEMPEST_CONCURRENCY` value and that overrides and load/skips lists are correct.
174+
Finally, once all the workflows and configuration has been pushed and reviewed you can build a kayobe image using the `Build Kayobe Docker Image` workflow. Once it is successfully built and pushed to a container registry, other workflows can be used.
175+
176+
Sometimes the kayobe docker image must be rebuilt the reasons for this include but are not limited to the following;
177+
178+
* Change :code:`$KAYOBE_CONFIG_PATH/ansible/requirements.yml`
179+
* Change to requirements.txt
180+
* Update Kayobe
181+
* Update kolla-ansible
182+
* UID/GID collision when deploying workflows to a new environment
183+
* Prior to deployment of new a OpenStack release

doc/source/configuration/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ the various features provided.
1818
wazuh
1919
vault
2020
magnum-capi
21+
ci-cd
2122
security-hardening
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
- name: Deploy GitHub Runner
3+
hosts: github-runners
4+
become: yes
5+
roles:
6+
- role: geerlingguy.pip
7+
- role: geerlingguy.docker
8+
tasks:
9+
- name: Deploy runners
10+
ansible.builtin.include_role:
11+
role: monolithprojects.github_actions_runner
12+
vars:
13+
runner_name: "{{ ansible_facts.nodename }}-{{ runner.key }}"
14+
runner_dir: "{{ base_runner_dir }}/{{ runner.key }}"
15+
runner_labels: "{{ runner.value.labels | default(default_runner_labels) }}"
16+
runner_state: "{{ runner.value.state | default('started') }}"
17+
with_dict:
18+
"{{ github_runners }}"
19+
loop_control:
20+
loop_var: runner
21+
22+
# FIXME: Sometimes the runner service is not running at the end of the role.
23+
# Start the service manually.
24+
- name: Ensure runner service is running
25+
ansible.builtin.service:
26+
name: actions.runner.{{ github_account }}-{{ github_repo }}.{{ ansible_facts.nodename }}-{{ runner.key }}.service
27+
state: started
28+
enabled: true
29+
become: true
30+
when: runner_state | default('started') == 'started'
31+
with_dict:
32+
"{{ github_runners }}"
33+
loop_control:
34+
loop_var: runner

etc/kayobe/ansible/requirements.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ collections:
1010
version: 0.4.1
1111
- name: stackhpc.hashicorp
1212
version: 2.4.0
13+
- name: stackhpc.kayobe_workflows
14+
version: 1.0.2
1315
roles:
1416
- src: stackhpc.vxlan
1517
- name: ansible-lockdown.rhel8_cis
@@ -28,3 +30,9 @@ roles:
2830
- name: wazuh-ansible
2931
src: https://github.com/stackhpc/wazuh-ansible
3032
version: stackhpc
33+
- name: geerlingguy.pip
34+
version: 2.2.0
35+
- name: monolithprojects.github_actions_runner
36+
version: 1.18.5
37+
- src: https://github.com/stackhpc/ansible-role-docker.git
38+
name: geerlingguy.docker
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
- name: Write Kayobe Automation Workflows for GitHub
3+
hosts: github-writer
4+
vars:
5+
github_output_directory: "{{ kayobe_config_path }}/../../.github/workflows"
6+
roles:
7+
- stackhpc.kayobe_workflows.github
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
runner_user: "{{ kayobe_ansible_user }}"
3+
github_account: "{{ undef(hint='Name of customer's GitHub account') }}"
4+
github_repo: "{{ undef(hint='Name of customer's kayobe config repository') }}"
5+
access_token: "{{ secrets_github_access_token }}"
6+
7+
base_runner_dir: /opt/actions-runner
8+
9+
default_runner_labels:
10+
- kayobe
11+
- openstack
12+
- "{{ kayobe_environment }}"
13+
14+
# Dictionary of GitHub runners to be deployed to each runner host.
15+
# Each dict item can be provided with optional attributes
16+
# * labels - provide a list of labels for a specific runner
17+
# overriding the contents of `default_runner_labels`
18+
# * state - either `started`` or `absent`. By default it will
19+
# be started if however the runner needs to be removed
20+
# then setting it to `absent` will unregister the runner with
21+
# GitHub and remove it from the system.
22+
# Example
23+
# github_runners:
24+
# runner_01: {}
25+
# runner_02:
26+
# labels: ['foo', 'bar', 'baz']
27+
# runner_03:
28+
# state: absent
29+
github_runners:
30+
runner_01: {}
31+
runner_02: {}
32+
runner_03: {}
33+
34+
docker_users:
35+
- "{{ runner_user }}"
36+
37+
pip_install_packages:
38+
- name: docker
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
# Configuration of GitHub workflows generated with stackhpc.kayobe_workflows.github should go here.
3+
# See documentation for more information
4+
# https://github.com/stackhpc/ansible-collection-kayobe-workflows/blob/main/roles/github/README.md
5+
6+
###############################################################################
7+
# Dummy variable to allow Ansible to accept this file.
8+
workaround_ansible_issue_8743: yes

etc/kayobe/inventory/groups

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ seed-hypervisor
3131
seed
3232
overcloud
3333

34+
[github-runners]
35+
# Empty group to provide declaration of github-runner group.
36+
37+
[github-writer]
38+
localhost
39+
3440
###############################################################################
3541
# Overcloud groups.
3642

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
features:
3+
- |
4+
Adds support for deploying GitHub runners and creating GitHub workflows
5+
for use within Kayobe Automation. Two playbooks and their requirements
6+
have been added to `ansible/` in addition to the relevant groups defined
7+
with some useful default variables where appropriate. Finally,
8+
documentation has been added to cover how to deploy these runners and
9+
workflows.

0 commit comments

Comments
 (0)