b40395da by Adam Heath

Add config file and defaults support, and then for each config_file/dir,

if there is a values/apiserver-env.yaml, attempt to look at a buildName
setting, which then becomes the volume name.
1 parent 08acffb2
Showing 1 changed file with 45 additions and 3 deletions
......@@ -2,17 +2,37 @@
set -e
INKLUSTER_IMAGE=brainfood/inkluster-dev
declare -A defaults=(
[INKLUSTER_IMAGE]=brainfood/inkluster-dev
[INKLUSTER_VOLUME_NAME]=""
)
declare -a config_files=()
if [[ -e .inkluster.env ]]; then
. .inkluster.env
config_files+=("$PWD/.inkluster.env")
fi
declare -A config=()
# This copies ENV settings into the config, that haven't been set on the command line.
for setting in "${!defaults[@]}"; do
[[ ${!setting} ]] && eval config[$setting]="${!setting}"
done
declare -a REST=()
while [[ $# -gt 0 ]]; do
case "$1" in
(-c)
config_files+=("$2")
shift 2
;;
(-i)
config[INKLUSTER_IMAGE]="$2"
shift 2
;;
(-v)
INKLUSTER_VOLUME_NAME="$2"
config[INKLUSTER_VOLUME_NAME]="$2"
shift 2
;;
(*)
......@@ -21,6 +41,28 @@ while [[ $# -gt 0 ]]; do
esac
done
# Now we copy the config settings into ENV
for config_file in "${config_files[@]}"; do
if [[ ! -e $config_file ]]; then
echo "Config file $config_file does not exist!" 1>&2
exit 1
fi
. "$config_file"
config_dir="${config_file%/*}"
[[ $config_dir = $config_file ]] && config_dir="$PWD"
if [[ -e $config_dir/values/apiserver-env.yaml ]]; then
buildName="$(sed -n -e 's/^buildName: "\(.*\)"$/\1/p' "$config_dir/values/apiserver-env.yaml")"
[[ $buildName && -z $INKLUSTER_VOLUME_NAME ]] && INKLUSTER_VOLUME_NAME="$buildName"
fi
done
# Any settings read from the config files, but not yet set, get applied.
for setting in "${!defaults[@]}"; do
[[ -n ${!setting} && -z ${config[$setting]} ]] && eval config[$setting]="${!setting}"
[[ -z ${config[$setting]} ]] && eval config[$setting]="${defaults[$setting]}"
eval $setting=\"\${config[$setting]}\"
done
has_volume=
if [[ $INKLUSTER_VOLUME_NAME ]]; then
docker volume inspect "inkluster-$INKLUSTER_VOLUME_NAME" 1>/dev/null 2>/dev/null || has_volume=1
......