Skip to content

Commit 055e5ef

Browse files
committed
test upload images commit
1 parent fd6abef commit 055e5ef

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

.github/bin/get-s3-image.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
set -x
4+
5+
# Variables (adjust these paths as necessary)
6+
S3_BUCKET="s3://openhpc-images"
7+
APPLIANCES_ENVIRONMENT_ROOT="$APPLIANCES_ENVIRONMENT_ROOT"
8+
MAIN_TF="$APPLIANCES_ENVIRONMENT_ROOT/terraform/main.tf"
9+
10+
echo "Extracting CI image name from $MAIN_TF"
11+
ci_image=$(grep -oP 'openhpc-[0-9a-zA-Z-]+' "$MAIN_TF")
12+
13+
echo "Checking if image $ci_image exists in OpenStack"
14+
image_exists=$(openstack image list --name "$ci_image" -f value -c Name)
15+
16+
if [ "$image_exists" == "$ci_image" ]; then
17+
echo "Image $ci_image already exists in OpenStack."
18+
else
19+
echo "Image $ci_image not found in OpenStack. Checking S3 for the image..."
20+
21+
# Check if the image exists in S3
22+
s3_exists=$(s3cmd ls "$S3_BUCKET/$ci_image.qcow2")
23+
24+
if [ -n "$s3_exists" ]; then
25+
echo "Image $ci_image found in S3. Downloading..."
26+
27+
# Download the image from S3
28+
s3cmd get "$S3_BUCKET/$ci_image.qcow2" "$ci_image.qcow2"
29+
30+
echo "Uploading image $ci_image to OpenStack..."
31+
openstack image create --file "$ci_image.qcow2" --disk-format qcow2 "$ci_image"
32+
33+
echo "Image $ci_image has been uploaded to OpenStack."
34+
else
35+
echo "Image $ci_image not found in S3. No further actions taken."
36+
fi
37+
fi
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
name: Upload release images to client sites from s3
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
- master
9+
- feat/fatimage-auto-upload
10+
11+
jobs:
12+
image_upload:
13+
runs-on: ubuntu-22.04
14+
concurrency: ${{ github.ref }}
15+
env:
16+
OS_CLOUD: openstack
17+
CI_CLOUD: ${{ vars.CI_CLOUD }}
18+
19+
steps:
20+
- uses: actions/checkout@v2
21+
22+
- name: Record which cloud CI is running on
23+
run: |
24+
echo CI_CLOUD: ${{ vars.CI_CLOUD }}
25+
26+
- name: Write clouds.yaml
27+
run: |
28+
mkdir -p ~/.config/openstack/
29+
echo "${{ secrets[format('{0}_CLOUDS_YAML', vars.CI_CLOUD)] }}" > ~/.config/openstack/clouds.yaml
30+
shell: bash
31+
32+
- name: Write s3cmd configuration
33+
run: |
34+
cat <<EOF > ~/.s3cfg
35+
access_key =
36+
secret_key =
37+
host_base = object.arcus.openstack.hpc.cam.ac.uk/swift/v1/AUTH_3a06571936a0424bb40bc5c672c4ccb1
38+
host_bucket = %(bucket)s.object.arcus.openstack.hpc.cam.ac.uk/swift/v1/AUTH_3a06571936a0424bb40bc5c672c4ccb1
39+
use_https = True
40+
signature_v2 = True
41+
EOF
42+
shell: bash
43+
44+
- name: Install s3cmd
45+
run: |
46+
sudo apt-get --yes install s3cmd
47+
48+
- name: Upload latest image if missing
49+
run: |
50+
/usr/bin/python3.10 -m venv venv
51+
. venv/bin/activate
52+
pip install -U pip
53+
pip install -r requirements.txt
54+
ansible --version
55+
. environments/.stackhpc/activate
56+
ansible-galaxy collection install openstack.cloud
57+
. .github/bin/get-s3-image.sh -o

0 commit comments

Comments
 (0)