Last active
March 19, 2018 20:29
-
-
Save simbo1905/21bd94a28c460b295c2fbef7a2bb6a71 to your computer and use it in GitHub Desktop.
loads an .env file containing key=value environment variables into an openshift secret `NAME=example ./create-env-secret.sh .env`
This file contains hidden or 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 | |
if [ "$NAME" = "" ] | |
then | |
echo "You must set NAME of the secet as an env var" | |
exit 1 | |
else | |
echo "Creating secet/$NAME" | |
fi | |
if [ -z "$1" ]; then | |
echo "No .env argument supplied. Exiting" | |
exit 1 | |
fi | |
if [ ! -f "$1" ]; then | |
echo "$1 is not a file. Exiting" | |
exit 1 | |
fi | |
# oddly bash refused to run on file `.env` so copy it to a temp file first | |
FILE=/tmp/$$ | |
cp $1 $FILE | |
awk "BEGIN {FS = \"=\" ; print \"apiVersion: v1\nkind: Secret\nmetadata:\n name: $NAME\nstringData:\"} NF==2 && \$1 !~ /#.*/ && \$2 !~ /^$/{print \" \" \$1 \": \x22\" \$2 \"\x22\"}" $FILE | sed 's/""/"/g' | oc create -f - | |
rm $FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment