aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel P. Berrangé <berrange@redhat.com>2024-04-15 18:56:35 +0100
committerDaniel P. Berrangé <berrange@redhat.com>2024-04-19 11:55:09 +0100
commit0242bd3bfdb616e876437085dfac0b18cc7e6632 (patch)
tree0643a7fc03b82630181ca40731a46ce07ab9f524
parent2f20fa467b11ddb54d9ae3cf63d43d2178e42b80 (diff)
downloadlibvirt-ci-0242bd3bfdb616e876437085dfac0b18cc7e6632.zip
libvirt-ci-0242bd3bfdb616e876437085dfac0b18cc7e6632.tar.gz
libvirt-ci-0242bd3bfdb616e876437085dfac0b18cc7e6632.tar.bz2
containers: introduce 'cirrus-vars' command
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é <berrange@redhat.com>
-rw-r--r--containers/cirrus-run/Dockerfile2
-rwxr-xr-xcontainers/cirrus-run/cirrus-vars.py19
2 files changed, 21 insertions, 0 deletions
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)