Matt Pryor 413957e36c
Use a dependencies file (#55)
* First pass at reading dependencies from file

* Write to a file first

* Add manifest fetch

* Check manifest download

* See if job outputs support fromJSON

* Try again

* Try download from manifest

* Use explicit skip steps

* Use explicit image output name for curl

* See if complex matrix values work

* Re-enable tests in PR workflow

* Use deps file in tests

* Debug outputs

* Use toJSON

* Extract matrix outputs properly

* Reinstate tests

* Remove debug statements

* [skip ci] don't run CI on edited PRs

* [skip ci] Remove edited trigger from PR workflow
2023-07-26 15:37:54 +01:00

43 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
set -ex
#####
# This script uploads an image to OpenStack unless already present
#####
[ -z "$IMAGE_NAME" ] && echo "IMAGE_NAME is required" >&2 && exit 1
[ -z "$IMAGE_URL" ] && echo "IMAGE_URL is required" >&2 && exit 1
# Default the GITHUB_OUTPUT to stdout
GITHUB_OUTPUT="${GITHUB_OUTPUT:-/dev/stdout}"
# Try to find the ID of an existing image with the required name
# NOTE: This command is allowed/expected to fail sometimes
IMAGE_ID="$(openstack image show -f value -c id "$IMAGE_NAME" || true)"
# If there is an existing image, we are done
if [ -n "$IMAGE_ID" ]; then
echo "image-id=${IMAGE_ID}" >> "$GITHUB_OUTPUT"
exit
fi
# If not, download the image and upload it to Glance
IMAGE_FNAME="${IMAGE_NAME}.${IMAGE_DISK_FORMAT:-qcow2}"
curl -Lo "$IMAGE_FNAME" --progress-bar "$IMAGE_URL"
IMAGE_ID="$(
openstack image create \
--progress \
--private \
--container-format "${IMAGE_CONTAINER_FORMAT:-bare}" \
--disk-format "${IMAGE_DISK_FORMAT:-qcow2}" \
--file "$IMAGE_FNAME" \
--property hw_scsi_model=virtio-scsi \
--property hw_disk_bus=scsi \
--format value \
--column id \
"$IMAGE_NAME"
)"
echo "image-id=${IMAGE_ID}" >> "$GITHUB_OUTPUT"