From 0242bd3bfdb616e876437085dfac0b18cc7e6632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Date: Mon, 15 Apr 2024 18:56:35 +0100 Subject: containers: introduce 'cirrus-vars' command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The gitlab CI config file has to pass various variables into the cirrus CI config file to control the build process. This is done by a giant sed command in the cirrus build template. This is inflexible since the set of substitutions is hardcoded. This new 'cirrus-vars' command can replace any variable @NAME@ with the corresponding value from the $NAME environment variable. Signed-off-by: Daniel P. Berrangé --- containers/cirrus-run/Dockerfile | 2 ++ containers/cirrus-run/cirrus-vars.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100755 containers/cirrus-run/cirrus-vars.py diff --git a/containers/cirrus-run/Dockerfile b/containers/cirrus-run/Dockerfile index 165f4a8..c59809c 100644 --- a/containers/cirrus-run/Dockerfile +++ b/containers/cirrus-run/Dockerfile @@ -1,3 +1,5 @@ FROM docker.io/library/python:3.9-alpine +COPY cirrus-vars.py /usr/bin/cirrus-vars + RUN pip3 install cirrus-run==1.0.1 diff --git a/containers/cirrus-run/cirrus-vars.py b/containers/cirrus-run/cirrus-vars.py new file mode 100755 index 0000000..3d863e7 --- /dev/null +++ b/containers/cirrus-run/cirrus-vars.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 + +import os +import re +import sys + +var = re.compile(r'@([a-zA-Z0-9_]+)@') + + +# Return empty string if var is not set, since not all +# OS targets require all vars to be set. +def get_env(matchobj): + return os.environ.get(matchobj.group(1), '') + + +for line in sys.stdin: + print(var.sub(get_env, line), end='') + +sys.exit(0) -- cgit v1.1