Last active
August 16, 2021 16:52
-
-
Save gpaterno/c9090e9a4d628867230512232e2d3e17 to your computer and use it in GitHub Desktop.
Docker env file to kube configmap
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 | |
## | |
## Script to generate a kube-compatible configmap out | |
## of a docker env file. might be handy for | |
## the ops guys that deal with devs | |
## | |
## (c) 2020 Giuseppe Paterno' <gpaterno@gpaterno.com> | |
## | |
ENVFILE=${ENVFILE:-"../.env_prod"} | |
MAPNAME="prometeon-website" | |
# Usage | |
usage() { | |
echo "Usage: $0 [-e <env file>] [-n <map name>]" 1>&2 | |
exit 1 | |
} | |
# Get option | |
while getopts ":e:n:" o; do | |
case "${o}" in | |
n) | |
MAPNAME=${OPTARG} | |
;; | |
e) | |
ENVFILE=${OPTARG} | |
;; | |
*) | |
usage | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
cat << __EOF__ | |
apiVersion: v1 | |
kind: ConfigMap | |
metadata: | |
creationTimestamp: null | |
name: $MAPNAME | |
data: | |
__EOF__ | |
## Output the env file and transfor | |
if [ -f $ENVFILE ] | |
then | |
cat $ENVFILE | awk -F= 'BEGIN{ OFS = ":"} ; !/^#/ && !/^$/ { print " " $1, " " "\"" $2 "\""}' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment