From 42b45287e4d4c2da12782fc5fd6bfbe1867f3726 Mon Sep 17 00:00:00 2001 From: bertiethorpe Date: Wed, 21 Aug 2024 12:49:32 +0000 Subject: [PATCH] test upload images commit --- .github/bin/get-s3-image.sh | 35 ++++++++++++++++ .github/workflows/upload-release-image.yml | 46 ++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 .github/bin/get-s3-image.sh create mode 100644 .github/workflows/upload-release-image.yml diff --git a/.github/bin/get-s3-image.sh b/.github/bin/get-s3-image.sh new file mode 100644 index 000000000..b71a5ccc5 --- /dev/null +++ b/.github/bin/get-s3-image.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Variables (adjust these paths as necessary) +S3_BUCKET="s3://openhpc-images" +APPLIANCES_ENVIRONMENT_ROOT="$APPLIANCES_ENVIRONMENT_ROOT" +MAIN_TF="$APPLIANCES_ENVIRONMENT_ROOT/terraform/main.tf" + +echo "Extracting CI image name from $MAIN_TF" +ci_image=$(grep -oP 'openhpc-[0-9a-zA-Z-]+' "$MAIN_TF") + +echo "Checking if image $ci_image exists in OpenStack" +image_exists=$(openstack image list --name "$ci_image" -f value -c Name) + +if [ "$image_exists" == "$ci_image" ]; then + echo "Image $ci_image already exists in OpenStack." +else + echo "Image $ci_image not found in OpenStack. Checking S3 for the image..." + + # Check if the image exists in S3 + s3_exists=$(s3cmd ls "$S3_BUCKET/$ci_image.qcow2") + + if [ -n "$s3_exists" ]; then + echo "Image $ci_image found in S3. Downloading..." + + # Download the image from S3 + s3cmd get "$S3_BUCKET/$ci_image.qcow2" "$ci_image.qcow2" + + echo "Uploading image $ci_image to OpenStack..." + openstack image create --file "$ci_image.qcow2" --disk-format qcow2 "$ci_image" + + echo "Image $ci_image has been uploaded to OpenStack." + else + echo "Image $ci_image not found in S3. No further actions taken." + fi +fi \ No newline at end of file diff --git a/.github/workflows/upload-release-image.yml b/.github/workflows/upload-release-image.yml new file mode 100644 index 000000000..361afd6c6 --- /dev/null +++ b/.github/workflows/upload-release-image.yml @@ -0,0 +1,46 @@ + +name: Upload release images to client sites from s3 +on: + workflow_dispatch: + push: + branches: + - main + - master + - feat/fatimage-auto-upload + +jobs: + image_upload: + runs-on: ubuntu-22.04 + concurrency: ${{ github.ref }} + env: + OS_CLOUD: ${{ vars.OS_CLOUD }} + CI_CLOUD: ${{ vars.CI_CLOUD }} + + steps: + - uses: actions/checkout@v2 + + - name: Record which cloud CI is running on + run: | + echo CI_CLOUD: ${{ vars.CI_CLOUD }} + + - name: Write clouds.yaml + run: | + mkdir -p ~/.config/openstack/ + echo "${{ secrets[format('{0}_CLOUDS_YAML', vars.CI_CLOUD)] }}" > ~/.config/openstack/clouds.yaml + shell: bash + + - name: Write s3cmd configuration + run: | + echo "${{ secrets['ARCUS_S3CFG'] }}" > ~/.s3cfg + shell: bash + + - name: Install s3cmd + run: | + sudo apt-get --yes install s3cmd + + - name: Upload latest image if missing + run: | + /usr/bin/python3.10 -m venv venv + . venv/bin/activate + . environments/.stackhpc/activate + . .github/bin/get-s3-image.sh \ No newline at end of file