ci-automation: Add secrets handling

This commit is contained in:
Krzesimir Nowak 2022-05-05 16:57:06 +02:00
parent cd2f3f0d6c
commit 197e9a334f
3 changed files with 23 additions and 4 deletions

View File

@ -90,7 +90,8 @@ GCE_PARALLEL="${PARALLEL_TESTS:-4}"
# Use the "@PROTO@" "@ARCH@", "@CHANNEL@" and "@VERNUM@" placeholders. They will # Use the "@PROTO@" "@ARCH@", "@CHANNEL@" and "@VERNUM@" placeholders. They will
# be replaced. # be replaced.
DO_IMAGE_URL="${DEFAULT_HTTP_IMAGE_URL_TEMPLATE}/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_REGION='sfo3'
DO_MACHINE_SIZE='s-2vcpu-2gb' DO_MACHINE_SIZE='s-2vcpu-2gb'
DO_PARALLEL='8' DO_PARALLEL='8'
# DIGITALOCEAN_TOKEN_JSON env var is used for credentials, and should
# come from sdk_container/.env

View File

@ -273,3 +273,19 @@ function url_from_template() {
echo "${url}" echo "${url}"
} }
# -- # --
# Puts a secret into a file, while trying for the secret to not end up
# on a filesystem at all. Prints a path to a file with the secret in
# /proc.
function secret_to_file() {
local secret="${1}"; shift
local tmpfile=$(mktemp)
local fd
exec {fd}<>"${tmpfile}"
rm -f "${tmpfile}"
echo "${secret}" >&${fd}
echo "/proc/${$}/fd/${fd}"
}
# --

View File

@ -25,15 +25,17 @@ fi
image_name="ci-${CIA_VERNUM//+/-}" image_name="ci-${CIA_VERNUM//+/-}"
image_url="$(url_from_template "${DO_IMAGE_URL}" "${CIA_ARCH}" "${CIA_CHANNEL}" 'https' "${CIA_VERNUM}")" image_url="$(url_from_template "${DO_IMAGE_URL}" "${CIA_ARCH}" "${CIA_CHANNEL}" 'https' "${CIA_VERNUM}")"
config_file="$(secret_to_file "${DIGITALOCEAN_TOKEN_JSON}")"
ore do create-image \ ore do create-image \
--config-file="${DO_CONFIG_FILE}" \ --config-file="${config_file}" \
--region="${DO_REGION}" \ --region="${DO_REGION}" \
--name="${image_name}" \ --name="${image_name}" \
--url="${image_url}" --url="${image_url}"
trap 'ore do delete-image \ trap 'ore do delete-image \
--name="${image_name}" \ --name="${image_name}" \
--config-file="${DO_CONFIG_FILE}"' EXIT --config-file="${config_file}"' EXIT
set -x set -x
@ -42,7 +44,7 @@ timeout --signal=SIGQUIT 4h\
--do-size="${DO_MACHINE_SIZE}" \ --do-size="${DO_MACHINE_SIZE}" \
--do-region="${DO_REGION}" \ --do-region="${DO_REGION}" \
--basename="${image_name}" \ --basename="${image_name}" \
--do-config-file="${DO_CONFIG_FILE}" \ --do-config-file="${config_file}" \
--do-image="${image_name}" \ --do-image="${image_name}" \
--parallel="${DO_PARALLEL}" \ --parallel="${DO_PARALLEL}" \
--platform=do \ --platform=do \