Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
26 changes: 26 additions & 0 deletions .github/bin/get-s3-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

#####
# This script looks for an image in OpenStack and if not found, downloads from
# S3 bucket, and then uploads to OpenStack
#####

set -ex

image_name=$1
bucket_name=$2
echo "Checking if image $image_name exists in OpenStack"
image_exists=$(openstack image list --name "$image_name" -f value -c Name)

if [ "$image_exists" == "$image_name" ]; then
echo "Image $image_name already exists in OpenStack."
else
echo "Image $image_name not found in OpenStack. Getting it from S3."

wget https://object.arcus.openstack.hpc.cam.ac.uk/swift/v1/AUTH_3a06571936a0424bb40bc5c672c4ccb1/$bucket_name/$image_name --progress=dot:giga

echo "Uploading image $image_name to OpenStack..."
openstack image create --file "$image_name" --disk-format qcow2 "$image_name" --progress

echo "Image $image_name has been uploaded to OpenStack."
fi
67 changes: 67 additions & 0 deletions .github/workflows/upload-release-image.yml.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# This workflow dispatch is to be used on a downstream ansible-slurm-appliance repository. The workflow takes two inputs:
# image name, and s3 bucket name. The image is searched for in the environment set openstack, and if not found there,
# downloads it from the ARCUS S3 bucket specified. The workflow then uploads the image to the openstack.
#
# To use this workflow in a downstream ansible-slurm-appliance repository simply copy it into .github/workflows
# and give it an appropriate name, e.g.
# cp .github/workflows/upload-s3-image.yml.sample .github/workflows/upload-s3-image.yml
#
# In order for the workflow to access the openstack, credentials in the form of a clouds.yaml file must be provided by a
# secret. This secret should have the name OS_CLOUD_YAML to be found by the workflow.
# Details on the contents of the clouds.yaml file can be found at https://docs.openstack.org/keystone/latest/user/application_credentials.html

name: Upload release images to client sites from s3
on:
workflow_dispatch:
inputs:
image_name:
type: string
description: Image name from https://object.arcus.openstack.hpc.cam.ac.uk/swift/v1/AUTH_3a06571936a0424bb40bc5c672c4ccb1/{BUCKET_NAME}/
required: true
bucket_name:
type: choice
required: true
description: Bucket name
options:
- openhpc-images
# - openhpc-images-prerelease

jobs:
image_upload:
runs-on: ubuntu-22.04
concurrency: ${{ github.ref }}
env:
OS_CLOUD: openstack
steps:
- uses: actions/checkout@v4

- name: Write clouds.yaml
run: |
mkdir -p ~/.config/openstack/
echo "${{ secrets.OS_CLOUD_YAML }}" > ~/.config/openstack/clouds.yaml
shell: bash

- name: Upload latest image if missing
run: |
python3 -m venv venv
. venv/bin/activate
pip install -U pip
pip install $(grep -o 'python-openstackclient[><=0-9\.]*' requirements.txt)
bash .github/bin/get-s3-image.sh ${{ inputs.image_name }} ${{ inputs.bucket_name }}

- name: Cleanup OpenStack Image (on error or cancellation)
if: cancelled()
run: |
. venv/bin/activate
image_hanging=$(openstack image list --name ${{ inputs.image_name }} -f value -c ID)
if [ -n "$image_hanging" ]; then
echo "Cleaning up OpenStack image with ID: $image_hanging"
openstack image delete $image_hanging
else
echo "No image ID found, skipping cleanup."
fi
shell: bash

- name: Confirm Success
if: success()
run: echo "Deployment succeeded, no cleanup needed."
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,6 @@ Please see the [monitoring-and-logging.README.md](docs/monitoring-and-logging.RE

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:

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

- An [image upload](.github/workflows/upload-s3-image.yml.sample) workflow dispatch which takes an image name, downloads it from ARCUS s3 bucket if available, and uploads to downstream environment openstack.
Loading