forked from deployKF/deployKF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_with_gomplate.sh
61 lines (51 loc) · 2.26 KB
/
gen_with_gomplate.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env bash
set -euo pipefail
THIS_SCRIPT_PATH=$(cd "$(dirname "$0")" && pwd)
cd "$THIS_SCRIPT_PATH"
GENERATOR_SOURCE_PATH="./generator"
GENERATOR_RUNTIME_PATH="$GENERATOR_SOURCE_PATH/runtime"
GENERATOR_OUTPUT_PATH="./GENERATOR_OUTPUT"
CUSTOM_VALUES_PATH="./sample-values.yaml"
# clean the generator output directory
# NOTE: we only clean the output directory if a '.deploykf_output' marker file is present
if [ -d "$GENERATOR_OUTPUT_PATH" ]; then
if [ -f "$GENERATOR_OUTPUT_PATH/.deploykf_output" ]; then
rm -rf "$GENERATOR_OUTPUT_PATH"
else
echo "ERROR: output directory '$GENERATOR_OUTPUT_PATH' is not safe to clean, no '.deploykf_output' marker found"
exit 1
fi
fi
# create the generator output directory and marker file
mkdir -p "$GENERATOR_OUTPUT_PATH"
echo -n "{}" > "$GENERATOR_OUTPUT_PATH/.deploykf_output"
# create the runtime directory
mkdir -p "$GENERATOR_RUNTIME_PATH"
# populate the runtime templates
echo -n "$GENERATOR_SOURCE_PATH/templates" > "$GENERATOR_RUNTIME_PATH/input_dir"
echo -n "$GENERATOR_OUTPUT_PATH" > "$GENERATOR_RUNTIME_PATH/output_dir"
# suppress the generation of empty files
export GOMPLATE_SUPPRESS_EMPTY=true
# PHASE 1: render our `.gomplateignore_template` files
gomplate \
--input-dir="$GENERATOR_SOURCE_PATH/templates" \
--output-map="$GENERATOR_SOURCE_PATH/templates/{{< .in | strings.ReplaceAll \".gomplateignore_template\" \".gomplateignore\" >}}" \
--include ".gomplateignore_template" \
--left-delim "{{<" \
--right-delim ">}}" \
--datasource "Values_default=$GENERATOR_SOURCE_PATH/default_values.yaml" \
--datasource "Values_custom=$CUSTOM_VALUES_PATH" \
--context "Values=merge:Values_custom|Values_default" \
--template "helpers=$GENERATOR_SOURCE_PATH/helpers/" \
--template "runtime=$GENERATOR_SOURCE_PATH/runtime/"
# PHASE 2: populate generator output directory
gomplate \
--input-dir="$GENERATOR_SOURCE_PATH/templates" \
--output-dir="$GENERATOR_OUTPUT_PATH" \
--left-delim "{{<" \
--right-delim ">}}" \
--datasource "Values_default=$GENERATOR_SOURCE_PATH/default_values.yaml" \
--datasource "Values_custom=$CUSTOM_VALUES_PATH" \
--context "Values=merge:Values_custom|Values_default" \
--template "helpers=$GENERATOR_SOURCE_PATH/helpers/" \
--template "runtime=$GENERATOR_SOURCE_PATH/runtime/"