From 3b09e5da75ef75039fbc1912f3b9e908060894bb Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Thu, 5 May 2022 16:51:46 +0200 Subject: [PATCH] ci-automation: Add URL template handling --- ci-automation/ci-config.env | 6 ++++-- ci-automation/ci_automation_common.sh | 21 ++++++++++++++++++++ ci-automation/vendor-testing/digitalocean.sh | 4 +--- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/ci-automation/ci-config.env b/ci-automation/ci-config.env index cfb4af96dd..0913f61746 100644 --- a/ci-automation/ci-config.env +++ b/ci-automation/ci-config.env @@ -17,6 +17,8 @@ CONTAINER_REGISTRY="ghcr.io/flatcar-linux" GC_BUCKET="flatcar-linux" +DEFAULT_HTTP_IMAGE_URL_TEMPLATE="@PROTO@://${BUILDCACHE_SERVER}/images/@ARCH@/@VERNUM@" + if ! command -v pigz > /dev/null; then # No PIGZ on Flatcar PIGZ="docker run --rm -i ghcr.io/flatcar-linux/pigz --fast" @@ -85,9 +87,9 @@ GCE_PARALLEL="${PARALLEL_TESTS:-4}" # -- Digital Ocean -- -# Use the "@ARCH@", "@CHANNEL@" and "@VERNUM@" placeholders. They will +# Use the "@PROTO@" "@ARCH@", "@CHANNEL@" and "@VERNUM@" placeholders. They will # be replaced. -DO_IMAGE_URL="https://${BUILDCACHE_SERVER}/images/@ARCH@/@VERNUM@/flatcar_production_digitalocean_image.bin.bz2" +DO_IMAGE_URL="${DEFAULT_HTTP_IMAGE_URL_TEMPLATE}/flatcar_production_digitalocean_image.bin.bz2" DO_CONFIG_FILE='do-token.json' DO_REGION='sfo3' DO_MACHINE_SIZE='s-2vcpu-2gb' diff --git a/ci-automation/ci_automation_common.sh b/ci-automation/ci_automation_common.sh index 82cf997d2f..f7d4039a74 100644 --- a/ci-automation/ci_automation_common.sh +++ b/ci-automation/ci_automation_common.sh @@ -224,3 +224,24 @@ function docker_image_from_registry_or_buildcache() { docker_image_from_buildcache "${image}" "${version}" } # -- + +# Substitutes fields in the passed template and prints the +# result. Followed by the template, the parameters used for +# replacement are in alphabetical order: arch, channel, proto and +# vernum. +function url_from_template() { + local template="${1}"; shift + local arch="${1}"; shift + local channel="${1}"; shift + local proto="${1}"; shift + local vernum="${1}"; shift + local url="${template}" + + url="${url//@ARCH@/${arch}}" + url="${url//@CHANNEL@/${channel}}" + url="${url//@PROTO@/${proto}}" + url="${url//@VERNUM@/${vernum}}" + + echo "${url}" +} +# -- diff --git a/ci-automation/vendor-testing/digitalocean.sh b/ci-automation/vendor-testing/digitalocean.sh index 5de9120d0b..000172a47c 100755 --- a/ci-automation/vendor-testing/digitalocean.sh +++ b/ci-automation/vendor-testing/digitalocean.sh @@ -38,9 +38,7 @@ if [[ "${channel}" = 'developer' ]]; then fi image_name="ci-${vernum//+/-}" testscript="$(basename "$0")" -image_url="${DO_IMAGE_URL//@ARCH@/${arch}}" -image_url="${image_url//@CHANNEL@/${channel}}" -image_url="${image_url//@VERNUM@/${vernum}}" +image_url="$(url_from_template "${DO_IMAGE_URL}" "${arch}" "${channel}" 'https' "${vernum}")" ore do create-image \ --config-file="${DO_CONFIG_FILE}" \