From 8d54e4855c386e6805c8e84dc36330006e2d4787 Mon Sep 17 00:00:00 2001 From: Chris Evich Date: Wed, 13 May 2020 10:48:21 -0400 Subject: Cirrus: Fix image-name hints This properly prints out image-name hints when executing the hack script without any arguments. It is required due to changes made by Ed for test-name beatification. An identical change was made and reviewed by Ed in the containers/storage repo. Signed-off-by: Chris Evich --- hack/get_ci_vm.sh | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'hack/get_ci_vm.sh') diff --git a/hack/get_ci_vm.sh b/hack/get_ci_vm.sh index 7e31c19c6..1d48f0996 100755 --- a/hack/get_ci_vm.sh +++ b/hack/get_ci_vm.sh @@ -67,13 +67,6 @@ delvm() { cleanup } -image_hints() { - _BIS=$(egrep -m 1 '_BUILT_IMAGE_SUFFIX:[[:space:]+"[[:print:]]+"' "$LIBPODROOT/.cirrus.yml" | cut -d: -f 2 | tr -d '"[:blank:]') - egrep '[[:space:]]+[[:alnum:]].+_CACHE_IMAGE_NAME:[[:space:]+"[[:print:]]+"' \ - "$LIBPODROOT/.cirrus.yml" | cut -d: -f 2 | tr -d '"[:blank:]' | \ - sed -r -e "s/\\\$[{]_BUILT_IMAGE_SUFFIX[}]/$_BIS/" | sort -u -} - show_usage() { echo -e "\n${RED}ERROR: $1${NOR}" echo -e "${YEL}Usage: $(basename $0) [-m ] [-u ] ${NOR}" @@ -90,17 +83,34 @@ show_usage() { } get_env_vars() { - python -c ' -import yaml + # Deal with both YAML and embedded shell-like substitutions in values + # if substitution fails, fall back to printing naked env. var as-is. + python3 -c ' +import yaml,re env=yaml.load(open(".cirrus.yml"), Loader=yaml.SafeLoader)["env"] -keys=[k for k in env if "ENCRYPTED" not in str(env[k])] +dollar_env_var=re.compile(r"\$(\w+)") +dollarcurly_env_var=re.compile(r"\$\{(\w+)\}") +class ReIterKey(dict): + def __missing__(self, key): + # Cirrus-CI provides some runtime-only env. vars. Avoid + # breaking this hack-script if/when any are present in YAML + return "${0}".format(key) +rep=r"{\1}" # Convert env vars markup to -> str.format_map(re_iter_key) markup +out=ReIterKey() for k,v in env.items(): v=str(v) - if "ENCRYPTED" not in v and "ADD_SECOND_PARTITION" not in v: - print("{0}=\"{1}\"".format(k, v)), + if "ENCRYPTED" not in v: + out[k]=dollar_env_var.sub(rep, dollarcurly_env_var.sub(rep, v)) +for k,v in out.items(): + print("{0}=\"{1}\"".format(k, v.format_map(out))) ' } +image_hints() { + get_env_vars | fgrep '_CACHE_IMAGE_NAME' | awk -F "=" '{print $2}' +} + + parse_args(){ echo -e "$USAGE_WARNING" -- cgit v1.2.3-54-g00ecf