Skip to content

Commit 2208301

Browse files
committed
Add an image-build and test-deploy workflow
1 parent d5a3502 commit 2208301

File tree

6 files changed

+185
-0
lines changed

6 files changed

+185
-0
lines changed
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
2+
name: Build, deploy and promote a new OHPC image
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
promote_community:
7+
description: 'Set the community property on a successfully tested image'
8+
required: true
9+
default: false
10+
type: boolean
11+
pull_request:
12+
push:
13+
branches:
14+
- main
15+
tags:
16+
- '*'
17+
jobs:
18+
build-deploy-promote:
19+
name: Build, deploy and promote a new OHPC image
20+
if: github.repository == 'stackhpc/caas-slurm-appliance'
21+
concurrency: ${{ github.ref }}
22+
runs-on: ubuntu-20.04
23+
env:
24+
ANSIBLE_FORCE_COLOR: True
25+
OS_CLOUD: openstack
26+
OS_CLIENT_CONFIG_FILE: ${{ github.workspace }}/clouds.yaml
27+
EXTRA_VARS_FILE: .github/extra_vars/arcus.yml
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@v3
31+
with:
32+
submodules: true
33+
34+
- name: Install ansible etc
35+
run: dev/setup-env.sh
36+
37+
- name: Write clouds.yaml
38+
run: |
39+
echo "${CLOUDS_YAML}" > ${OS_CLIENT_CONFIG_FILE}
40+
shell: bash
41+
env:
42+
CLOUDS_YAML: ${{ secrets.CLOUDS_YAML }}
43+
44+
- name: Build OHPC image
45+
id: build
46+
run: |
47+
source venv/bin/activate
48+
ansible-playbook \
49+
-i image-build/hosts \
50+
-e @${EXTRA_VARS_FILE} \
51+
-e '{"write_cluster_image_uuid_file": true}' \
52+
-e image_build_cluster_id="image-build-${GITHUB_SHA::7}" \
53+
image-build.yml
54+
echo "CLUSTER_IMAGE=$(cat cluster_image_uuid.txt)" >> $GITHUB_OUTPUT
55+
env:
56+
PACKER_LOG_PATH: ${{ github.workspace }}/packer-build.log
57+
58+
- name: Remove image build infra
59+
run: |
60+
source venv/bin/activate
61+
ansible-playbook \
62+
-i image-build/hosts \
63+
-e @${EXTRA_VARS_FILE} \
64+
-e cluster_state=absent \
65+
-e image_build_cluster_id="image-build-${GITHUB_SHA::7}" \
66+
image-build.yml
67+
if: always()
68+
69+
- name: Deploy a cluster based on the new OPHC image
70+
id: deploy
71+
run: |
72+
source venv/bin/activate
73+
ansible-playbook \
74+
-i image-build/hosts \
75+
-e @${EXTRA_VARS_FILE} \
76+
-e cluster_image=${{ steps.build.outputs.CLUSTER_IMAGE }} \
77+
-e cluster_name="caas-ci-${GITHUB_SHA::7}" \
78+
slurm-infra.yml
79+
env:
80+
SLURM_INFRA_HIDE_DEBUG_OUTPUT: True
81+
if: success()
82+
83+
- name: Remove cluster based on the new OHPC image
84+
run: |
85+
source venv/bin/activate
86+
ansible-playbook \
87+
-i image-build/hosts \
88+
-e @${EXTRA_VARS_FILE} \
89+
-e cluster_image=${{ steps.build.outputs.CLUSTER_IMAGE }} \
90+
-e cluster_state=absent \
91+
-e cluster_name="caas-ci-${GITHUB_SHA::7}" \
92+
slurm-infra.yml
93+
if: |
94+
( success() || failure() || cancelled() ) &&
95+
steps.build.outcome == 'success'
96+
97+
- name: Delete built image after testing
98+
run: |
99+
source venv/bin/activate
100+
ansible-playbook \
101+
-i image-build/hosts \
102+
-e cluster_image=${{ steps.build.outputs.CLUSTER_IMAGE }} \
103+
-e '{"cluster_image_delete": true}' \
104+
image-build/image-delete-or-promote.yml
105+
if: |
106+
( success() || failure() || cancelled() ) &&
107+
steps.build.outcome == 'success' &&
108+
github.event_name == 'pull_request'
109+
110+
- name: Promote built image from Private to Community after testing
111+
run: |
112+
source venv/bin/activate
113+
ansible-playbook \
114+
-i image-build/hosts \
115+
-e cluster_image=${{ steps.build.outputs.CLUSTER_IMAGE }} \
116+
-e '{"cluster_image_promote_community": true}' \
117+
image-build/image-delete-or-promote.yml
118+
if: |
119+
success() &&
120+
steps.build.outcome == 'success' &&
121+
steps.deploy.outcome == 'success' &&
122+
(( github.event_name == 'workflow_dispatch' && inputs.promote_community == true )
123+
|| github.event_name == 'push' )
124+
125+
- name: Upload packer build log artifact
126+
uses: actions/upload-artifact@v3
127+
with:
128+
name: packer-build-log
129+
path: ${{ github.workspace }}/packer-build.log
130+
if: failure() || success()

dev/setup-env.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
/usr/bin/python3.8 -m venv venv
5+
source venv/bin/activate
6+
pip install -U pip
7+
pip install -r requirements.txt
8+
ansible --version
9+
# Install ansible dependencies ...
10+
ansible-galaxy role install -r requirements.yml --force
11+
ansible-galaxy collection install -r requirements.yml --force

image-build.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,12 @@
2121
- name: Print cluster_image UUID
2222
debug:
2323
msg: "{{ cluster_image }}"
24+
25+
- name: Write cluster_image UUID to file
26+
copy:
27+
dest: "{{ playbook_dir }}/cluster_image_uuid.txt"
28+
content: "{{ cluster_image }}"
29+
when:
30+
- write_cluster_image_uuid_file is defined
31+
- write_cluster_image_uuid_file
2432
when: cluster_state is not defined or (cluster_state is defined and cluster_state != "absent")
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
- hosts: openstack
2+
tasks:
3+
- block:
4+
# Use command module because openstack.image doesn't
5+
# support setting the community property
6+
- name: Set image community property
7+
command:
8+
cmd: >-
9+
openstack image set --community {{ cluster_image }}
10+
changed_when: true
11+
when:
12+
- cluster_image_promote_community is defined
13+
- cluster_image_promote_community
14+
15+
- name: Delete image
16+
openstack.cloud.image:
17+
name: "{{ cluster_image }}"
18+
state: absent
19+
when:
20+
- cluster_image_delete is defined
21+
- cluster_image_delete
22+
23+
when: cluster_image is defined

requirements.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ansible==6.0.0
2+
openstacksdk<0.99.0
3+
python-openstackclient
4+
jmespath
5+
passlib[bcrypt]==1.7.4
6+
cookiecutter
7+
selinux # this is a shim to avoid having to use --system-site-packages, you still need sudo yum install libselinux-python3
8+
netaddr
9+
matplotlib

slurm-infra.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,12 @@
121121

122122
# Write the outputs as the final task
123123
- hosts: localhost
124+
vars:
125+
hide_debug_outputs: "{{ lookup('ansible.builtin.env', 'SLURM_INFRA_HIDE_DEBUG_OUTPUT', default=false) | bool }}"
124126
tasks:
125127
- debug: var=outputs
128+
when:
129+
- not hide_debug_outputs
126130
vars:
127131
# Ansible has a fit when there are two 'hostvars' evaluations in a resolution chain,
128132
# so we have to repeat logic here unfortunately

0 commit comments

Comments
 (0)