Created
September 30, 2022 09:09
-
-
Save alombarte/794fb5db18cb27ebbfca88626f86d5ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Entrypoint with password replacement based on ___PLACEHOLDERS___ | |
# Only works in bash, does not work on sh (e.g.: Alpine) | |
FILE_TO_REPLACE="krakend.json" | |
passwords_to_replace="$(grep -o '___.*___' $FILE_TO_REPLACE | sed 's/___//g' | sort | uniq )" | |
for pass in $passwords_to_replace; do | |
if [ "x${!pass}" = 'x' ]; then | |
echo "[KO] Environment variable '$pass' is not declared and the configuration replacement failed!" | |
else | |
# Replace the ___PLACEHOLDER___ entry by its value | |
sed -i "s#___${pass}___#${!pass}#" $FILE_TO_REPLACE | |
echo "[OK] ${pass} written" | |
fi | |
done | |
# BONUS: Are there remaining placeholders? | |
PENDING_REPLACEMENTS="$(grep ___ $FILE_TO_REPLACE)" | |
if [ "x$PENDING_REPLACEMENTS" = 'x' ]; then | |
echo "[OK] All passwords have been set" | |
else | |
echo "[KO] The following passwords weren't retrieved:" | |
echo "$PENDING_REPLACEMENTS" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment