Skip to content

Commit 513ad1c

Browse files
authored
Merge pull request #430 from stackhpc/feat/fatimage-auto-upload
Add workflow for fat image uploads to client sites
2 parents ebbb308 + ebc94c2 commit 513ad1c

File tree

3 files changed

+95
-1
lines changed

3 files changed

+95
-1
lines changed

Diff for: .github/bin/get-s3-image.sh

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
#####
4+
# This script looks for an image in OpenStack and if not found, downloads from
5+
# S3 bucket, and then uploads to OpenStack
6+
#####
7+
8+
set -ex
9+
10+
image_name=$1
11+
bucket_name=$2
12+
echo "Checking if image $image_name exists in OpenStack"
13+
image_exists=$(openstack image list --name "$image_name" -f value -c Name)
14+
15+
if [ -n "$image_exists" ]; then
16+
echo "Image $image_name already exists in OpenStack."
17+
else
18+
echo "Image $image_name not found in OpenStack. Getting it from S3."
19+
20+
wget https://object.arcus.openstack.hpc.cam.ac.uk/swift/v1/AUTH_3a06571936a0424bb40bc5c672c4ccb1/$bucket_name/$image_name --progress=dot:giga
21+
22+
echo "Uploading image $image_name to OpenStack..."
23+
openstack image create --file $image_name --disk-format qcow2 $image_name --progress
24+
25+
echo "Image $image_name has been uploaded to OpenStack."
26+
fi

Diff for: .github/workflows/upload-release-image.yml.sample

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# This workflow can be used to fetch images published by StackHPC and upload them to a client's OpenStack.
2+
# The workflow takes two inputs:
3+
# - image name
4+
# - s3 bucket name
5+
# and first checks to see if the image exists in the target OpenStack. If the image doesn't exist, it is downloaded
6+
# from StackHPC's public S3 bucket and then uploaded to the target OpenStack.
7+
#
8+
# To use this workflow in a downstream ansible-slurm-appliance repository simply copy it into .github/workflows
9+
# and give it an appropriate name, e.g.
10+
# cp .github/workflows/upload-s3-image.yml.sample .github/workflows/upload-s3-image.yml
11+
#
12+
# In order for the workflow to access the target OpenStack, an application credential clouds.yaml file must be
13+
# added as a repository secret named OS_CLOUD_YAML.
14+
# Details on the contents of the clouds.yaml file can be found at https://docs.openstack.org/keystone/latest/user/application_credentials.html
15+
16+
name: Upload release images to client sites from s3
17+
on:
18+
workflow_dispatch:
19+
inputs:
20+
image_name:
21+
type: string
22+
description: Image name from: (https://object.arcus.openstack.hpc.cam.ac.uk/swift/v1/AUTH_3a06571936a0424bb40bc5c672c4ccb1/{BUCKET_NAME})
23+
required: true
24+
bucket_name:
25+
type: choice
26+
required: true
27+
description: Bucket name
28+
options:
29+
- openhpc-images
30+
# - openhpc-images-prerelease
31+
32+
jobs:
33+
image_upload:
34+
runs-on: ubuntu-22.04
35+
concurrency: ${{ github.ref }}
36+
env:
37+
OS_CLOUD: openstack
38+
steps:
39+
- uses: actions/checkout@v4
40+
41+
- name: Write clouds.yaml
42+
run: |
43+
mkdir -p ~/.config/openstack/
44+
echo "${{ secrets.OS_CLOUD_YAML }}" > ~/.config/openstack/clouds.yaml
45+
shell: bash
46+
47+
- name: Upload latest image if missing
48+
run: |
49+
python3 -m venv venv
50+
. venv/bin/activate
51+
pip install -U pip
52+
pip install $(grep -o 'python-openstackclient[><=0-9\.]*' requirements.txt)
53+
bash .github/bin/get-s3-image.sh ${{ inputs.image_name }} ${{ inputs.bucket_name }}
54+
55+
- name: Cleanup OpenStack Image (on error or cancellation)
56+
if: cancelled()
57+
run: |
58+
. venv/bin/activate
59+
image_hanging=$(openstack image list --name ${{ inputs.image_name }} -f value -c ID -c Status | grep -v ' active$' | awk '{print $1}')
60+
if [ -n "$image_hanging" ]; then
61+
echo "Cleaning up OpenStack image with ID: $image_hanging"
62+
openstack image delete $image_hanging
63+
else
64+
echo "No image ID found, skipping cleanup."
65+
fi
66+
shell: bash

Diff for: README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,6 @@ Please see the [monitoring-and-logging.README.md](docs/monitoring-and-logging.RE
149149

150150
The `.github` directory contains a set of sample workflows which can be used by downstream site-specific configuration repositories to simplify ongoing maintainence tasks. These include:
151151

152-
- An [upgrade check](.github/workflows/upgrade-check.yml.sample) workflow which automatically checks this upstream stackhpc/ansible-slurm-appliance repo for new releases and proposes a pull request to the downstream site-specific repo when a new release is published.
152+
- An [upgrade check](.github/workflows/upgrade-check.yml.sample) workflow which automatically checks this upstream stackhpc/ansible-slurm-appliance repo for new releases and proposes a pull request to the downstream site-specific repo when a new release is published.
153+
154+
- An [image upload](.github/workflows/upload-s3-image.yml.sample) workflow which takes an image name, downloads it from StackHPC's public S3 bucket if available, and uploads it to the target OpenStack cloud.

0 commit comments

Comments
 (0)