Skip to content

Instantly share code, notes, and snippets.

@gpaterno
Last active August 16, 2021 16:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gpaterno/c9090e9a4d628867230512232e2d3e17 to your computer and use it in GitHub Desktop.
Save gpaterno/c9090e9a4d628867230512232e2d3e17 to your computer and use it in GitHub Desktop.
Docker env file to kube configmap
#!/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