Skip to content

Commit 17e0fdc

Browse files
authored
refactor: render the templates with envsubst
In-place sed replacements mutate tracked template files and silently leave literal placeholders behind when a variable name changes or is unset. Rendering through envsubst with explicit unset-variable guards keeps the source templates clean and fails fast when a required value is missing. Signed-off-by: Fabian Wiesel <fabian.wiesel@sap.com>
1 parent a719873 commit 17e0fdc

5 files changed

Lines changed: 44 additions & 29 deletions

File tree

‎.github/actions/test/integration/build/action.yml‎

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,24 @@ runs:
9595
- name: Generate ignition
9696
shell: bash
9797
run: |
98+
set -Eeuo pipefail
9899
ssh-keygen -t ed25519 -f "/opt/ssh_host_ed25519_key" -N "" -C "user" -q
99100
chmod 600 /opt/ssh_host_ed25519_key
100101
SSH_KEY=$(cat /opt/ssh_host_ed25519_key.pub)
101102
echo "SSH_KEY=$SSH_KEY" >> $GITHUB_ENV
102-
cp ./.github/actions/test/integration/build/dev-user-butane.yaml ./.github/actions/test/integration/build/dev-user-butane-hv1.yaml
103-
yq '.storage.files += load("./.github/actions/test/integration/build/root-hints.yaml")' ./.github/actions/test/integration/build/dev-user-butane.yaml > ./.github/actions/test/integration/build/dev-user-butane-hv2.yaml
104-
105-
sed -i "s|SSH_KEY_GOES_HERE|$SSH_KEY|g" ./.github/actions/test/integration/build/dev-user-butane-hv1.yaml
106-
sed -i "s|SSH_KEY_GOES_HERE|$SSH_KEY|g" ./.github/actions/test/integration/build/dev-user-butane-hv2.yaml
107-
108103
PASSWORD=$(openssl passwd "password")
109104
echo "PASSWORD=$PASSWORD" >> $GITHUB_ENV
110-
sed -i "s|PASSWORD_GOES_HERE|$PASSWORD|g" ./.github/actions/test/integration/build/dev-user-butane-hv1.yaml
111-
sed -i "s|PASSWORD_GOES_HERE|$PASSWORD|g" ./.github/actions/test/integration/build/dev-user-butane-hv2.yaml
112-
sed -i "s|TAG_GOES_HERE|${{ inputs.image_tag }}|g" ./.github/actions/test/integration/build/dev-user-butane-hv1.yaml
113-
sed -i "s|TAG_GOES_HERE|${{ inputs.image_tag }}|g" ./.github/actions/test/integration/build/dev-user-butane-hv2.yaml
105+
: "${SSH_KEY:?the shared test SSH key is not set}"
106+
: "${PASSWORD:?the guest password is not set}"
107+
: "${TAG:?the image tag is not set}"
108+
109+
envsubst '${SSH_KEY} ${PASSWORD} ${TAG}' \
110+
< ./.github/actions/test/integration/build/dev-user-butane.yaml \
111+
> ./.github/actions/test/integration/build/dev-user-butane-hv1.yaml
112+
113+
yq '.storage.files += load("./.github/actions/test/integration/build/root-hints.yaml")' ./.github/actions/test/integration/build/dev-user-butane.yaml \
114+
| envsubst '${SSH_KEY} ${PASSWORD} ${TAG}' \
115+
> ./.github/actions/test/integration/build/dev-user-butane-hv2.yaml
114116
115117
butane --pretty --strict ./.github/actions/test/integration/build/dev-user-butane-hv1.yaml > "/opt/${TAG}-hv1.ign"
116118
butane --pretty --strict ./.github/actions/test/integration/build/dev-user-butane-hv2.yaml > "/opt/${TAG}-hv2.ign"
@@ -128,9 +130,16 @@ runs:
128130
- name: Generate ubuntu cloud-init
129131
shell: bash
130132
run: |
131-
sed -i "s|SSH_KEY_GOES_HERE|$SSH_KEY|g" ./.github/actions/test/integration/build/user-data
132-
sed -i "s|PASSWORD_GOES_HERE|$PASSWORD|g" ./.github/actions/test/integration/build/user-data
133-
genisoimage -output /opt/ubuntu-cloud-init-ds.iso -volid cidata -joliet -rock ./.github/actions/test/integration/build/meta-data ./.github/actions/test/integration/build/user-data
133+
set -Eeuo pipefail
134+
: "${SSH_KEY:?the shared test SSH key is not set}"
135+
: "${PASSWORD:?the guest password is not set}"
136+
137+
RENDER_DIR=$(mktemp -d)
138+
trap 'rm -rf "$RENDER_DIR"' EXIT
139+
envsubst '${SSH_KEY} ${PASSWORD}' \
140+
< ./.github/actions/test/integration/build/user-data \
141+
> "$RENDER_DIR/user-data"
142+
genisoimage -output /opt/ubuntu-cloud-init-ds.iso -volid cidata -joliet -rock ./.github/actions/test/integration/build/meta-data "$RENDER_DIR/user-data"
134143
135144
# - name: Upload artifacts
136145
# uses: actions/upload-artifact@v4

‎.github/actions/test/integration/build/dev-user-butane.yaml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version: 1.3.0
33
passwd:
44
users:
55
- name: root
6-
password_hash: "PASSWORD_GOES_HERE"
6+
password_hash: "${PASSWORD}"
77
storage:
88
files:
99
- path: /etc/ssh/sshd_config
@@ -20,7 +20,7 @@ storage:
2020
- path: /etc/ssh/authorized_keys
2121
mode: 0600
2222
contents:
23-
inline: "SSH_KEY_GOES_HERE"
23+
inline: "${SSH_KEY}"
2424
- path: /etc/hosts
2525
mode: 0644
2626
overwrite: true
@@ -51,7 +51,7 @@ storage:
5151
# pull the image from GHCR instead of keppel
5252
OCI_REPO=ghcr.io/gardenlinux/gardenlinux-sci
5353
# point to a custom tag to download for the persist step
54-
OCI_TAG=TAG_GOES_HERE
54+
OCI_TAG=${TAG}
5555
# Enable unlimited core dumps for all systemd services
5656
- path: /etc/systemd/system.conf.d/10-core.conf
5757
mode: 0644

‎.github/actions/test/integration/build/user-data‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ users:
33
- name: root
44
shell: /bin/bash
55
ssh_authorized_keys:
6-
- "SSH_KEY_GOES_HERE"
7-
hashed_passwd: "PASSWORD_GOES_HERE"
6+
- "${SSH_KEY}"
7+
hashed_passwd: "${PASSWORD}"
88

99
disable_root: false
1010

‎.github/actions/test/integration/setup/action.yml‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,19 @@ runs:
1515
- name: Copy ignition file
1616
shell: bash
1717
run: |
18+
set -Eeuo pipefail
19+
: "${TAG:?the image tag is not set}"
1820
sudo cp "/opt/${TAG}-hv1.ign" /var/lib/libvirt/images/HV1.ign
1921
sudo cp "/opt/${TAG}-hv2.ign" /var/lib/libvirt/images/HV2.ign
2022
2123
- name: Create HyperVisor 1
2224
shell: bash
2325
run: |
24-
cp ./.github/actions/test/integration/setup/hv.xml ./.github/actions/test/integration/setup/hv1.xml
25-
sed -i "s|HV_NAME_GOES_HERE|HV1|g" ./.github/actions/test/integration/setup/hv1.xml
26-
sed -i "s|MAC_GOES_HERE|52:54:00:12:34:56|g" ./.github/actions/test/integration/setup/hv1.xml
26+
set -Eeuo pipefail
27+
: "${TAG:?the image tag is not set}"
28+
HV_NAME=HV1 MAC=52:54:00:12:34:56 envsubst '${HV_NAME} ${MAC}' \
29+
< ./.github/actions/test/integration/setup/hv.xml \
30+
> ./.github/actions/test/integration/setup/hv1.xml
2731
sudo cp "/opt/${TAG}.qcow2" /var/lib/libvirt/images/HV1.qcow2
2832
2933
sudo virsh define ./.github/actions/test/integration/setup/hv1.xml
@@ -32,9 +36,11 @@ runs:
3236
- name: Create HyperVisor 2
3337
shell: bash
3438
run: |
35-
cp ./.github/actions/test/integration/setup/hv.xml ./.github/actions/test/integration/setup/hv2.xml
36-
sed -i "s|HV_NAME_GOES_HERE|HV2|g" ./.github/actions/test/integration/setup/hv2.xml
37-
sed -i "s|MAC_GOES_HERE|52:54:00:65:43:21|g" ./.github/actions/test/integration/setup/hv2.xml
39+
set -Eeuo pipefail
40+
: "${TAG:?the image tag is not set}"
41+
HV_NAME=HV2 MAC=52:54:00:65:43:21 envsubst '${HV_NAME} ${MAC}' \
42+
< ./.github/actions/test/integration/setup/hv.xml \
43+
> ./.github/actions/test/integration/setup/hv2.xml
3844
sudo cp "/opt/${TAG}.qcow2" /var/lib/libvirt/images/HV2.qcow2
3945
4046
sudo virsh define ./.github/actions/test/integration/setup/hv2.xml

‎.github/actions/test/integration/setup/hv.xml‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
2-
<name>HV_NAME_GOES_HERE</name>
2+
<name>${HV_NAME}</name>
33
<memory unit='GiB'>6</memory>
44
<vcpu>4</vcpu>
55
<os firmware='efi'>
@@ -14,24 +14,24 @@
1414
<devices>
1515
<disk type='file' device='disk'>
1616
<driver name='qemu' type='qcow2' />
17-
<source file='/var/lib/libvirt/images/HV_NAME_GOES_HERE.qcow2' />
17+
<source file='/var/lib/libvirt/images/${HV_NAME}.qcow2' />
1818
<target dev='vda' bus='virtio' />
1919
</disk>
2020
<interface type='network'>
21-
<mac address='MAC_GOES_HERE' />
21+
<mac address='${MAC}' />
2222
<source network='default' />
2323
<model type='virtio' />
2424
</interface>
2525
<console type='pty'>
2626
<target type='serial' port='0' />
2727
</console>
2828
<serial type='file'>
29-
<source path='/var/log/HV_NAME_GOES_HERE.log' />
29+
<source path='/var/log/${HV_NAME}.log' />
3030
<target port='0' />
3131
</serial>
3232
</devices>
3333
<qemu:commandline>
3434
<qemu:arg value='-fw_cfg' />
35-
<qemu:arg value='name=opt/com.coreos/config,file=/var/lib/libvirt/images/HV_NAME_GOES_HERE.ign' />
35+
<qemu:arg value='name=opt/com.coreos/config,file=/var/lib/libvirt/images/${HV_NAME}.ign' />
3636
</qemu:commandline>
3737
</domain>

0 commit comments

Comments
 (0)