Skip to content

Commit

Permalink
test upload images commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bertiethorpe committed Aug 21, 2024
1 parent fd6abef commit a4d2ab7
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/bin/get-s3-image.sh
Original file line number Diff line number Diff line change
@@ -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
49 changes: 49 additions & 0 deletions .github/workflows/upload-release-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

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: openstack
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
pip install -U pip
pip install -r requirements.txt
ansible --version
ansible-galaxy collection install openstack.cloud
. .github/bin/get-s3-image.sh

0 comments on commit a4d2ab7

Please sign in to comment.