-
Notifications
You must be signed in to change notification settings - Fork 58
/
templatize.sh
executable file
·151 lines (139 loc) · 3.65 KB
/
templatize.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/bash
PROJECT_ROOT_DIR=$(dirname "$(realpath "${BASH_SOURCE[0]}")")
# Default values
CLOUD="${CLOUD:-public}"
REGION="${REGION:-westus3}"
CXSTAMP="${CXSTAMP:-1}"
EXTRA_ARGS=""
# Function to display usage
usage() {
echo "Usage: $0 deploy_env input output [-c cloud] [-r region] [-x cxstamp] [-e]"
echo " deploy_env Deployment environment"
echo " input Optional input file"
echo " output Optional output file"
echo " -i Set the input file same as second arg"
echo " -o Set the output file same as third arg"
echo " -c Set the cloud (default: public)"
echo " -r Set the region (default: westus3)"
echo " -x Set the cxstamp (default: 1)"
echo " -e Extra args for config interpolation"
echo " -p Pipeline to inspect"
echo " -s Pipeline step to inspect"
exit 1
}
# Check if at least one positional argument is provided
if [ "$#" -lt 1 ]; then
usage
fi
# Positional arguments
DEPLOY_ENV=$1
shift
if [ "$#" -ge 1 ] && [[ ! "$1" =~ ^- ]]; then
INPUT=$1
shift
fi
if [ "$#" -ge 1 ] && [[ ! "$1" =~ ^- ]]; then
OUTPUT=$1
shift
fi
# Parse optional flags
while getopts "c:r:x:e:i:o:p:s:" opt; do
case ${opt} in
c)
CLOUD=${OPTARG}
;;
r)
REGION=${OPTARG}
;;
x)
CXSTAMP=${OPTARG}
;;
e)
EXTRA_ARGS="--extra-args ${OPTARG}"
;;
i)
INPUT=${OPTARG}
;;
o)
OUTPUT=${OPTARG}
;;
p)
PIPELINE=${OPTARG}
;;
s)
PIPELINE_STEP=${OPTARG}
;;
*)
usage
;;
esac
done
# short names from EV2 prod ServiceConfig
case ${REGION} in
eastus)
REGION_SHORT="use"
;;
westus)
REGION_SHORT="usw"
;;
centralus)
REGION_SHORT="usc"
;;
northcentralus)
REGION_SHORT="usnc"
;;
southcentralus)
REGION_SHORT="ussc"
;;
westus2)
REGION_SHORT="usw2"
;;
westus3)
REGION_SHORT="usw3"
;;
*)
echo "unsupported region: ${REGION}"
exit 1
esac
if [ "$DEPLOY_ENV" == "personal-dev" ]; then
REGION_STAMP="${REGION_SHORT}${USER:0:4}"
else
CLEAN_DEPLOY_ENV=$(echo "${DEPLOY_ENV}" | tr -cd '[:alnum:]')
REGION_STAMP="${CLEAN_DEPLOY_ENV}"
fi
make -s -C ${PROJECT_ROOT_DIR}/tooling/templatize templatize
TEMPLATIZE="${PROJECT_ROOT_DIR}/tooling/templatize/templatize"
CONFIG_FILE=${CONFIG_FILE:-${PROJECT_ROOT_DIR}/config/config.yaml}
if [ -n "$INPUT" ] && [ -n "$OUTPUT" ]; then
$TEMPLATIZE generate \
--config-file=${CONFIG_FILE} \
--cloud=${CLOUD} \
--deploy-env=${DEPLOY_ENV} \
--region=${REGION} \
--region-short=${REGION_STAMP} \
--stamp=${CXSTAMP} \
--input=${INPUT} \
--output=${OUTPUT} \
${EXTRA_ARGS}
elif [ -n "$PIPELINE" ] && [ -n "$PIPELINE_STEP" ]; then
$TEMPLATIZE pipeline inspect \
--config-file=${CONFIG_FILE} \
--cloud=${CLOUD} \
--deploy-env=${DEPLOY_ENV} \
--region=${REGION} \
--region-short=${REGION_STAMP} \
--stamp=${CXSTAMP} \
--pipeline-file=${PIPELINE} \
--step=${PIPELINE_STEP} \
--scope vars \
--format makefile
else
$TEMPLATIZE inspect \
--config-file=${CONFIG_FILE} \
--cloud=${CLOUD} \
--deploy-env=${DEPLOY_ENV} \
--region=${REGION} \
--region-short=${REGION_STAMP} \
--stamp=${CXSTAMP} \
${EXTRA_ARGS}
fi