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 @@ ...@@ -2,17 +2,37 @@
2 2
3 set -e 3 set -e
4 4
5 INKLUSTER_IMAGE=brainfood/inkluster-dev 5 declare -A defaults=(
6 [INKLUSTER_IMAGE]=brainfood/inkluster-dev
7 [INKLUSTER_VOLUME_NAME]=""
8 )
9
10 declare -a config_files=()
6 11
7 if [[ -e .inkluster.env ]]; then 12 if [[ -e .inkluster.env ]]; then
8 . .inkluster.env 13 config_files+=("$PWD/.inkluster.env")
9 fi 14 fi
10 15
16 declare -A config=()
17
18 # This copies ENV settings into the config, that haven't been set on the command line.
19 for setting in "${!defaults[@]}"; do
20 [[ ${!setting} ]] && eval config[$setting]="${!setting}"
21 done
22
11 declare -a REST=() 23 declare -a REST=()
12 while [[ $# -gt 0 ]]; do 24 while [[ $# -gt 0 ]]; do
13 case "$1" in 25 case "$1" in
26 (-c)
27 config_files+=("$2")
28 shift 2
29 ;;
30 (-i)
31 config[INKLUSTER_IMAGE]="$2"
32 shift 2
33 ;;
14 (-v) 34 (-v)
15 INKLUSTER_VOLUME_NAME="$2" 35 config[INKLUSTER_VOLUME_NAME]="$2"
16 shift 2 36 shift 2
17 ;; 37 ;;
18 (*) 38 (*)
...@@ -21,6 +41,28 @@ while [[ $# -gt 0 ]]; do ...@@ -21,6 +41,28 @@ while [[ $# -gt 0 ]]; do
21 esac 41 esac
22 done 42 done
23 43
44 # Now we copy the config settings into ENV
45 for config_file in "${config_files[@]}"; do
46 if [[ ! -e $config_file ]]; then
47 echo "Config file $config_file does not exist!" 1>&2
48 exit 1
49 fi
50 . "$config_file"
51 config_dir="${config_file%/*}"
52 [[ $config_dir = $config_file ]] && config_dir="$PWD"
53 if [[ -e $config_dir/values/apiserver-env.yaml ]]; then
54 buildName="$(sed -n -e 's/^buildName: "\(.*\)"$/\1/p' "$config_dir/values/apiserver-env.yaml")"
55 [[ $buildName && -z $INKLUSTER_VOLUME_NAME ]] && INKLUSTER_VOLUME_NAME="$buildName"
56 fi
57 done
58
59 # Any settings read from the config files, but not yet set, get applied.
60 for setting in "${!defaults[@]}"; do
61 [[ -n ${!setting} && -z ${config[$setting]} ]] && eval config[$setting]="${!setting}"
62 [[ -z ${config[$setting]} ]] && eval config[$setting]="${defaults[$setting]}"
63 eval $setting=\"\${config[$setting]}\"
64 done
65
24 has_volume= 66 has_volume=
25 if [[ $INKLUSTER_VOLUME_NAME ]]; then 67 if [[ $INKLUSTER_VOLUME_NAME ]]; then
26 docker volume inspect "inkluster-$INKLUSTER_VOLUME_NAME" 1>/dev/null 2>/dev/null || has_volume=1 68 docker volume inspect "inkluster-$INKLUSTER_VOLUME_NAME" 1>/dev/null 2>/dev/null || has_volume=1
......