Skip to content

Instantly share code, notes, and snippets.

@sloev
Created May 18, 2021 12:19
Show Gist options
  • Select an option

  • Save sloev/6419f007e646c3b8c13dd983606a1699 to your computer and use it in GitHub Desktop.

Select an option

Save sloev/6419f007e646c3b8c13dd983606a1699 to your computer and use it in GitHub Desktop.
render yaml template and concat
#!/bin/bash
# EXAMPLE:
# $ cat production.env
#
# DB_HOST="foo=bar bas=10"
# DB_PORT=5432
# DB_PASSWORD=$DB_PASSWORD
#
# $ cat test.yaml
# ...
# - name: "DB_HOST"
# value: "$DB_HOST"
# - name: "DB_PORT"
# value: "$DB_PORT"
# - name: "DB_PASSWORD"
# value: "$DB_PASSWORD"
#
# you run render and it will expand `$DB_HOST` to the env-var `DB_HOST` and `$DB_PORT` to the one described as `5432`:
#
# $ DB_PASSWORD=foobarbaz render production.env test.yaml
# - name: "DB_HOST"
# value: "foo=bar bas=10"
# - name: "DB_PORT"
# value: "5432"
# - name: "DB_PASSWORD"
# value: "foobarbaz"
if (($# < 2)); then
echo "usage:
render production.env YAML_FILE_PATHS
example:
render config_production.txt service.yaml loadbalancer.yaml db.yaml
"
exit 1
fi
for ((i=2; i<=$#; i++))
do
(set -a; source $1; set +a; envsubst < ${!i})
printf "\n---\n"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment