Increase testability of shell scripts (#752)

This is a preparation for #724 (bash script testing) which would be too complex to review if done there.

Reviewed-on: https://gitea.com/gitea/helm-chart/pulls/752
Co-authored-by: justusbunsi <sk.bunsenbrenner@gmail.com>
Co-committed-by: justusbunsi <sk.bunsenbrenner@gmail.com>
This commit is contained in:
justusbunsi 2024-12-19 12:04:00 +00:00 committed by justusbunsi
parent 726b36c6d8
commit a79fd31f7e
7 changed files with 32 additions and 8 deletions

View File

@ -73,9 +73,9 @@ function env2ini::reload_preset_envs() {
env2ini::log " + '${setting}'"
export "${setting^^}=${value}" # '^^' makes the variable content uppercase
done < "/tmp/existing-envs"
done < "$TMP_EXISTING_ENVS_FILE"
rm /tmp/existing-envs
rm $TMP_EXISTING_ENVS_FILE
}
@ -124,13 +124,13 @@ function env2ini::generate_initial_secrets() {
}
# save existing envs prior to script execution. Necessary to keep order of preexisting and custom envs
env | (grep -e '^GITEA__' || [[ $? == 1 ]]) > /tmp/existing-envs
env | (grep -e '^GITEA__' || [[ $? == 1 ]]) > $TMP_EXISTING_ENVS_FILE
# MUST BE CALLED BEFORE OTHER CONFIGURATION
env2ini::generate_initial_secrets
env2ini::load_config_sources '/env-to-ini-mounts/inlines/'
env2ini::load_config_sources '/env-to-ini-mounts/additionals/'
env2ini::load_config_sources "$ENV_TO_INI_MOUNT_POINT/inlines/"
env2ini::load_config_sources "$ENV_TO_INI_MOUNT_POINT/additionals/"
# load existing envs to override auto generated envs
env2ini::reload_preset_envs

View File

@ -1,4 +1,4 @@
#!/usr/bin/env bash
set -eu
gpg --batch --import /raw/private.asc
gpg --batch --import "$TMP_RAW_GPG_KEY"

View File

@ -107,6 +107,10 @@ spec:
value: /data
- name: GITEA_TEMP
value: /tmp/gitea
- name: TMP_EXISTING_ENVS_FILE
value: /tmp/existing-envs
- name: ENV_TO_INI_MOUNT_POINT
value: /env-to-ini-mounts
{{- if .Values.deployment.env }}
{{- toYaml .Values.deployment.env | nindent 12 }}
{{- end }}
@ -149,6 +153,8 @@ spec:
env:
- name: GNUPGHOME
value: {{ .Values.signing.gpgHome }}
- name: TMP_RAW_GPG_KEY
value: /raw/private.asc
volumeMounts:
- name: init
mountPath: /usr/sbin

View File

@ -29,3 +29,19 @@ tests:
path: spec.template.metadata.labels
content:
hello: world
- it: "injects TMP_EXISTING_ENVS_FILE as environment variable to 'init-app-ini' init container"
template: templates/gitea/deployment.yaml
asserts:
- contains:
path: spec.template.spec.initContainers[1].env
content:
name: TMP_EXISTING_ENVS_FILE
value: /tmp/existing-envs
- it: "injects ENV_TO_INI_MOUNT_POINT as environment variable to 'init-app-ini' init container"
template: templates/gitea/deployment.yaml
asserts:
- contains:
path: spec.template.spec.initContainers[1].env
content:
name: ENV_TO_INI_MOUNT_POINT
value: /env-to-ini-mounts

View File

@ -28,6 +28,8 @@ tests:
value:
- name: GNUPGHOME
value: /data/git/.gnupg
- name: TMP_RAW_GPG_KEY
value: /raw/private.asc
- equal:
path: spec.template.spec.initContainers[2].volumeMounts
value:

View File

@ -19,7 +19,7 @@ tests:
#!/usr/bin/env bash
set -eu
gpg --batch --import /raw/private.asc
gpg --batch --import "$TMP_RAW_GPG_KEY"
- it: skips gpg script block for disabled signing
asserts:
- equal:

View File

@ -20,7 +20,7 @@ tests:
#!/usr/bin/env bash
set -eu
gpg --batch --import /raw/private.asc
gpg --batch --import "$TMP_RAW_GPG_KEY"
- it: skips gpg script block for disabled signing
set:
image.rootless: false