-
Notifications
You must be signed in to change notification settings - Fork 28
/
v2_set_pipeline
executable file
·136 lines (117 loc) · 4.29 KB
/
v2_set_pipeline
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
#!/bin/bash
set -e -o pipefail
ci_dir="$(cd "$(dirname "$0")"; pwd)/templates"
print_usage() {
echo "Usage:" >&2
echo " $0 <iaas> <deployment_configurations...> [testcase] " >&2
echo "" >&2
echo " valid iaas names:" >&2
for name in "${ci_dir}"/iaas/*.yml; do
local iaas_name
iaas_name="$(basename "${name}")"
echo " - ${iaas_name%.yml}" >&2
done
echo "" >&2
echo " valid deployment_configuration names:" >&2
for name in "${ci_dir}"/deployment-configurations/*.yml; do
local deployment_configuration
deployment_configuration="$(basename "${name}")"
echo " - ${deployment_configuration%.yml}" >&2
done
echo "" >&2
echo " valid testcases names:" >&2
for name in "${ci_dir}"/testcases/*.yml; do
local testcase_name
testcase_name="$(basename "${name}")"
echo " - ${testcase_name%.yml}" >&2
done
}
extract_deployment_configuration() {
local deployment_configuration="$1"
local pipeline_filename="${ci_dir}/deployment-configurations/${deployment_configuration}.yml"
if [ ! -f "${pipeline_filename}" ]; then
pipeline_filename="${ci_dir}/deployment-configurations/${deployment_configuration}"
if [ ! -f "${pipeline_filename}" ]; then
echo "Unknown deployment configuration name: ${deployment_configuration}" >&2
print_usage
exit 1
fi
fi
deployment_configuration=$(basename "${pipeline_filename}")
echo -n "${deployment_configuration%.*}"
}
extract_testcase() {
local testcase="$1"
local pipeline_filename="${ci_dir}/testcases/${testcase}.yml"
if [ ! -f "${pipeline_filename}" ]; then
pipeline_filename="${ci_dir}/testcases/${testcase}"
if [ ! -f "${pipeline_filename}" ]; then
echo "Unknown testcase name: ${testcase}" >&2
print_usage
exit 1
fi
fi
testcase=$(basename "${pipeline_filename}")
echo -n "${testcase%.*}"
}
canonicalize_iaas_name() {
local iaas=$1
if [[ ${iaas} == *"vsphere"* ]]; then
iaas="vsphere"
fi
echo -n "${iaas}"
}
main() {
local deployment_configurations pipeline_config iaas_name testcase
if [[ $# -lt 2 ]]; then
print_usage
exit 1
fi
iaas_name=${1}
shift
while (( "$#" )); do
if [[ $# -eq 1 ]]; then
testcase=$(extract_testcase "${1}")
shift
else
deployment_configurations="${deployment_configurations} $(extract_deployment_configuration "${1}")"
shift
fi
done
pipeline_config=$(cat "$ci_dir"/template.yml)
local iaas_ops_file="${ci_dir}/iaas/${iaas_name}.yml"
local testcase_ops_file="${ci_dir}/testcases/${testcase}.yml"
local iaas_testcase_ops_file="${ci_dir}/iaas-testcase-ops-files/${iaas_name}-${testcase}.yml"
for deployment_configuration in ${deployment_configurations}; do
local deployment_configuration_ops_file="${ci_dir}/deployment-configurations/${deployment_configuration}.yml"
local iaas_deployment_configuration_ops_file="${ci_dir}/iaas-deployment-configuration-ops-files/${iaas_name}-${deployment_configuration}.yml"
if [ -f "${deployment_configuration_ops_file}" ]; then
pipeline_config=$(bosh int <(echo "${pipeline_config}") --ops-file "${deployment_configuration_ops_file}")
fi
if [ -f "${iaas_deployment_configuration_ops_file}" ]; then
pipeline_config=$(bosh int <(echo "${pipeline_config}") --ops-file "${iaas_deployment_configuration_ops_file}")
fi
done
if [ -f "${iaas_ops_file}" ]; then
pipeline_config=$(bosh int <(echo "${pipeline_config}") --ops-file "${iaas_ops_file}")
fi
if [ -f "${testcase_ops_file}" ]; then
pipeline_config=$(bosh int <(echo "${pipeline_config}") --ops-file "${testcase_ops_file}" -v iaas="${iaas_name}")
fi
if [ -f "${iaas_testcase_ops_file}" ]; then
pipeline_config=$(bosh int <(echo "${pipeline_config}") --ops-file "${iaas_testcase_ops_file}")
fi
fly --target kubo sync > /dev/null
local joined_configurations="$(echo "${deployment_configurations}" | tr ' ' '_')"
local pipeline_name="${iaas_name}${joined_configurations}_${testcase}"
echo "Setting pipeline ${pipeline_name}"
fly --target kubo set-pipeline \
--config <(echo "${pipeline_config}") \
--pipeline "$pipeline_name" \
-v locks="${iaas_name}" \
-v iaas="$(canonicalize_iaas_name "${iaas_name}")" \
-v pipeline-name="$pipeline_name"
}
pushd "${ci_dir}" > /dev/null
main "$@"
popd > /dev/null