Skip to content

Commit d0de34b

Browse files
committed
feat: update ci-cd documentation
Includes steps for deploying GitLab runners, generating pipelines and deploying OpenBao for secret management.
1 parent 609b6be commit d0de34b

File tree

1 file changed

+201
-1
lines changed

1 file changed

+201
-1
lines changed

doc/source/configuration/ci-cd.rst

Lines changed: 201 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ CI/CD
55
Concepts
66
========
77

8-
The CI/CD system developed for managing Kayobe based OpenStack clouds is composed of three main components; workflows, runners and kayobe automation.
8+
The CI/CD system developed for managing Kayobe based OpenStack clouds is composed of four main components; workflows, runners, OpenBao and kayobe automation.
99
Firstly, the workflows are files which describe a series of tasks to be performed in relation to the deployed cloud.
1010
These workflows are executed on request, on schedule or in response to an event such as a pull request being opened.
1111
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.
1212
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.
1313
Deployment of private runners is supported by all major providers with the use of community developed Ansible roles.
14+
Thirdly, OpenBao is used to store secrets on the same virtual machine the runners are hosted within.
15+
This provides a secure way of storing secrets and variables which can be accessed by the runners when executing workflows and ensures that secrets never have to leave the cloud.
1416
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.
1517
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.
1618
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.
@@ -42,6 +44,12 @@ These services will listen for jobs which have been tagged appropriately and dis
4244
The runners will need to be deployed using existing roles and playbooks whereby the binary/package is downloaded and registered using a special token.
4345
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.
4446

47+
OpenBao
48+
-------
49+
50+
OpenBao is recommended when deploying kayobe automation to achieve a simple and secure way of storing secrets.
51+
OpenBao can easily be configured to hold the secrets for all environments and only permit access to the runners which require them utilising different authorisation mechanisms such as GitLab's JWT (JSON Web Token).
52+
4553
GitHub Actions
4654
=================
4755

@@ -181,3 +189,195 @@ Sometimes the kayobe docker image must be rebuilt the reasons for this include b
181189
* Update kolla-ansible
182190
* UID/GID collision when deploying workflows to a new environment
183191
* Prior to deployment of new a OpenStack release
192+
193+
GitLab Pipelines
194+
================
195+
196+
To enable CI/CD where GitLab Pipelines is used please follow the steps described below starting with the deployment of the runners.
197+
198+
Runner Deployment
199+
-----------------
200+
201+
1. Identify a suitable host for hosting the runners.
202+
Ideally an infra-vm would be deployed to allow for easily compartmentalising the runners from the rest of the environment.
203+
8 VCPUs and 16GB of RAM is recommended for the guest machine however this may need to be adjusted for larger deployments.
204+
Whether the host is in an infra-vm or not it will need access to the :code:`admin_network` or :code:`provision_oc_network`, :code:`public_network` and the :code:`pulp registry` on the seed.
205+
The steps will assume that an infra-vm will be used for the purpose of hosting the runners.
206+
207+
2. Edit the environment's :code:`${KAYOBE_CONFIG_PATH}/environments/${KAYOBE_ENVIRONMENT}/inventory/hosts` to define the host(s) that will host the runners.
208+
209+
.. code-block:: ini
210+
211+
[github-runners]
212+
gitlab-runner-01
213+
214+
4. Provide all the relevant Kayobe :code:`group_vars` for :code:`gitlab-runners` under :code:`${KAYOBE_CONFIG_PATH}/environments/${KAYOBE_ENVIRONMENT}/inventory/group_vars/gitlab-runners`
215+
* `infra-vms` ensuring all required `infra_vm_extra_network_interfaces` are defined
216+
* `network-interfaces`
217+
218+
5. Edit the ``${KAYOBE_CONFIG_PATH}/inventory/group_vars/gitlab-runners/runners.yml`` file which will contain the variables required to deploy a series of runners.
219+
Below is an example of how GitLab runners can be configured for deployment.
220+
In this example we have two runners, one for production and one for staging and will both be deployed on the same host.
221+
This might not be possible for all deployments as multiple environments may require different runners as no single runner can serve all environments.
222+
Note a GitLab runner can run multiple jobs concurrently so deploying a single runner per environment is recommended.
223+
224+
.. code-block:: yaml
225+
226+
---
227+
gitlab_runner_coordinator_url: "https://gitlab.example.com"
228+
gitlab_runner_runners:
229+
- name: "Kayobe Automation Runner [Production] #1"
230+
executor: docker
231+
docker_image: 'alpine'
232+
token: "{{ secrets_gitlab_production_runner_token }}"
233+
env_vars:
234+
- "GIT_CONFIG_COUNT=1"
235+
- "GIT_CONFIG_KEY_0=safe.directory"
236+
- "GIT_CONFIG_VALUE_0=*"
237+
tags:
238+
- kayobe
239+
- openstack
240+
- production
241+
docker_volumes:
242+
- "/var/run/docker.sock:/var/run/docker.sock"
243+
- "/opt/.docker/config.json:/root/.docker/config.json:ro"
244+
- "/cache"
245+
extra_configs:
246+
runners.docker:
247+
network_mode: host
248+
- name: "Kayobe Automation Runner [Staging] #1"
249+
executor: docker
250+
docker_image: 'alpine'
251+
token: "{{ secrets_gitlab_staging_runner_token }}"
252+
env_vars:
253+
- "GIT_CONFIG_COUNT=1"
254+
- "GIT_CONFIG_KEY_0=safe.directory"
255+
- "GIT_CONFIG_VALUE_0=*"
256+
tags:
257+
- kayobe
258+
- openstack
259+
- staging
260+
docker_volumes:
261+
- "/var/run/docker.sock:/var/run/docker.sock"
262+
- "/opt/.docker/config.json:/root/.docker/config.json:ro"
263+
- "/cache"
264+
extra_configs:
265+
runners.docker:
266+
network_mode: host
267+
268+
6. Obtain a runner token for each runner that is required for deployment.
269+
This token can be obtained by visiting the GitLab project -> Settings -> CI/CD -> Runners -> New project runner -> Complete the form and copy the token.
270+
Once the token has been obtained, add it to :code:`secrets.yml` under :code:`secrets_gitlab_production_runner_token` and :code:`secrets_gitlab_staging_runner_token`
271+
272+
7. Deploy the infra-vm
273+
274+
.. code-block:: bash
275+
276+
kayobe infra vm provision --limit gitlab-runner-01
277+
278+
8. Perform a host configure against the infra-vm
279+
280+
.. code-block:: bash
281+
282+
kayobe infra vm host configure --limit gitlab-runner-01
283+
284+
9. Run :code:`kayobe playbook run ${KAYOBE_CONFIG_PATH}/ansible/deploy-gitlab-runner.yml`
285+
286+
10. Check runners have registered properly by visiting the repository's :code:`CI/CD` tab -> :code:`Runners`
287+
288+
11. The contents of :code:`/opt/.docker/config.json` on the runner should be added to GitLab CI/CD settings as a sercret variable.
289+
This is required to allow the runners to pull images from the registry.
290+
Visit the GitLab project -> Settings -> CI/CD -> Variables -> Add a new variable with the key :code:`DOCKER_CONFIG_JSON` and the value of the contents of :code:`/opt/.docker/config.json`
291+
292+
OpenBao Deployment
293+
------------------
294+
295+
OpenBao must be installed on the same host as the runners.
296+
If you have multiple environments that each have the own runners then OpenBao must be installed on each host.
297+
However, if you have a single host that is shared between environments then OpenBao only needs to be installed once and can be achieved by running the following playbook.
298+
299+
.. code-block:: bash
300+
301+
kayobe playbook run ${KAYOBE_CONFIG_PATH}/ansible/deploy-openbao-kayobe-automation.yml
302+
303+
.. note::
304+
305+
If you are sharing OpenBao between environments then you will need to rerun the playbook under each environment to ensure that the correct secrets are available to the runners.
306+
You may use :code:`--tags add_secrets` to skip the deployment within other environments.
307+
For this to work you will need to copy :code:`vault/vault-automation-keys.json` from the first environment to the other environments in addition to copying the host definition of the gitlab runner add network IP.
308+
309+
Once the above playbook has been applied you need to grab the root token from :code:`vault/vault-automation-keys.json` as you will need this to enable JWT support.
310+
This would also be an opportune time to encrypt the :code:`vault/vault-automation-keys.json` to protect the contents.
311+
312+
In order to enable JWT support the following steps must be carried out within the openbao container on the runner host.
313+
314+
1. SSH into the runner host
315+
316+
2. Run :code:`sudo docker exec -it bao sh`
317+
318+
3. Run :code:`export BAO_AUTH_ADDR=http://127.0.0.1:8200`
319+
320+
4. Run :code:`bao login` and use root token
321+
322+
5. Run the following to enable and configure JWT support
323+
324+
.. note::
325+
326+
The following steps are an example and should be adapted to suit your deployment.
327+
For example project_id within the gitlab role will need ID of the project that the runners are registered against.
328+
This can acquired by visiting the project -> Settings -> General -> General project settings -> Project ID.
329+
330+
.. code-block:: bash
331+
332+
bao auth enable jwt
333+
bao policy write kayobe-automation - <<EOF
334+
path "kayobe-automation/*" {
335+
capabilities = [ "read" ]
336+
}
337+
EOF
338+
bao write auth/jwt/role/gitlab - <<EOF
339+
{
340+
"role_type": "jwt",
341+
"token_explicit_max_ttl": 60,
342+
"user_claim": "user_email",
343+
"bound_audiences": "http://127.0.0.1:8200",
344+
"bound_claims": {
345+
"project_id": "ADD_PROJECT_ID_HERE"
346+
},
347+
"policies": ["kayobe-automation"]
348+
}
349+
EOF
350+
bao write auth/jwt/config \
351+
jwks_url="https://gitlab.example.com/oauth/discovery/keys" \
352+
bound_issuer="https://gitlab.example.com" \
353+
354+
GitLab Pipelines
355+
----------------
356+
357+
1. Edit :code:`${KAYOBE_CONFIG_PATH}/inventory/group_vars/gitlab-writer/writer.yml` in the base configuration making the appropriate changes to your deployments specific needs. See documentation for `stackhpc.kayobe_workflows.gitlab <https://github.com/stackhpc/ansible-collection-kayobe-workflows/tree/main/roles/gitlab>`__.
358+
Following the instructions in the documentation will allow you to customise the workflows to fit within your deployment.
359+
For example disabling jobs that might not be relevant such as physical network configuration or overcloud host provision in clouds where this is absent.
360+
Also consider the impact runbooks might have as the runbooks are designed with a particular cloud in mind and may not be suitable for all deployments such as hyperconverged deployments with Ceph on hypervisors.
361+
362+
2. Run :code:`kayobe playbook run ${KAYOBE_CONFIG_PATH}/ansible/write-gitlab-pipelines.yml`
363+
364+
3. Commit and push all newly generated pipelines found under root of the repository.
365+
366+
Things to consider
367+
==================
368+
369+
- Adjust General Pipeline settings by visiting the project -> Settings -> CI/CD -> General pipelines
370+
- Disable :code:`Public Pipelines`
371+
- Disable :code:`Auto-cancel redundant pipelines`
372+
- Disable :code:`Prevent outdated deployment jobs`
373+
- Increase :code:`Timeout` to :code:`12h`
374+
375+
- Disable Auto DevOps in the GitLab project settings by visiting the project -> Settings -> CI/CD -> Auto DevOps -> Disable Auto DevOps
376+
377+
Sometimes the kayobe docker image must be rebuilt the reasons for this include but are not limited to the following;
378+
379+
* Change :code:`$KAYOBE_CONFIG_PATH/ansible/requirements.yml`
380+
* Change to requirements.txt
381+
* Update Kayobe
382+
* Update kolla-ansible
383+
* Prior to deployment of new a OpenStack release

0 commit comments

Comments
 (0)