-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy path4-fly-patch-products.sh
executable file
·110 lines (96 loc) · 3.6 KB
/
4-fly-patch-products.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
#! /bin/bash
set -euo pipefail
show_usage () {
pipeline_name=$1
cat << EOF
Usage: $(basename "$0") -t <Concourse target name> -p <PCF platform code> -n <pipeline name> [OPTION]
-t <Concourse target name> the logged in fly's target name
-p <PCF platform code> the PCF platform code the pipeline is created for, e.g. prod
-n <pipeline name> the pipeline name
-s <true/false to specify stemcell> true/false to indicate whether to specify stemcell
-o <ops files seperated by comma> the ops files, seperated by comma, e.g. file1.yml,file2.yml
-h display this help and exit
Examples:
$(basename "$0") -t prod -p prod -n ${pipeline_name}
$(basename "$0") -t prod -p prod -n ${pipeline_name} -s true
$(basename "$0") -t prod -p prod -n ${pipeline_name} -o ops-file1.yml
$(basename "$0") -t prod -p prod -n ${pipeline_name} -o ops-file1.yml,ops-file1.yml
EOF
}
opt_t='' # fly target name
opt_p='' # PCF platform code
opt_n='' # pipeline name
opt_s='' # true/false flag wether to specify stemcell
opt_o=() # ops files seperated by comma
suggested_pipeline_name="install-upgrade-products"
while getopts "t:p:n:s:o:h" opt; do
case $opt in
t) opt_t=$OPTARG
;;
p) opt_p=$OPTARG
;;
n) opt_n=$OPTARG
;;
s) opt_s=$OPTARG
;;
o) opt_o+=("$OPTARG")
;;
h)
show_usage "$suggested_pipeline_name"
exit 0
;;
?)
show_usage "$suggested_pipeline_name" >&2
exit 1
;;
esac
done
if [ -z "$opt_t" ] || [ -z "$opt_p" ] || [ -z "$opt_n" ]; then
echo -e "ERROR: please specify Concourse's target name with '-t', PCF platform code with '-p', and pipeline name with '-n' \n"
show_usage "$suggested_pipeline_name"
exit 0
fi
if ! [ -x "$(command -v ytt)" ]; then
echo "ytt tool is required. Please get it from https://github.com/k14s/ytt/releases"
exit 1
fi
config_file="cat"
if [[ ${#opt_o[@]} > 0 ]]; then
if ! [ -x "$(command -v yaml-patch)" ]; then
echo "yaml-patch tool is required for ops-files. Please get it from https://github.com/krishicks/yaml-patch/releases"
exit 1
fi
config_file=" yaml-patch "
for ops_file in "${opt_o[@]}"; do
config_file+=" -o ${ops_file} "
done
fi
if [ "$opt_s" == "true" ] ; then
fly -t $opt_t set-pipeline -p $opt_n \
-c <( ytt template \
-f pipelines/patch-products-with-specific-stemcell.yml \
-f templates/functions.lib.yml \
-f templates/groups.lib.yml \
-f templates/resource-types.lib.yml \
-f templates/resources-patch-with-specific-stemcell.lib.yml \
-f templates/jobs-common.lib.yml \
-f templates/jobs-patch-with-specific-stemcell.lib.yml \
-f vars-$opt_p/vars-products.yml \
| $config_file \
) \
-l vars-$opt_p/vars-common.yml
else
fly -t $opt_t set-pipeline -p $opt_n \
-c <( ytt template \
-f pipelines/patch-products.yml \
-f templates/functions.lib.yml \
-f templates/groups.lib.yml \
-f templates/resource-types.lib.yml \
-f templates/resources-patch.lib.yml \
-f templates/jobs-common.lib.yml \
-f templates/jobs-patch.lib.yml \
-f vars-$opt_p/vars-products.yml \
| $config_file \
) \
-l vars-$opt_p/vars-common.yml
fi