forked from nemonik/hands-on-DevOps-gen2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.env
308 lines (230 loc) · 7.13 KB
/
.env
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
#!/usr/bin/env bash
# Copyright (C) 2021 Michael Joseph Walsh - All Rights Reserved
# You may use, distribute and modify this code under the
# terms of the the license.
#
# You should have received a copy of the license with
# this file. If not, please email <[email protected]>
## Returns the image's name when messaged.
##
## For example when messaged "redis:5.0.9" this function
## will echo "redis".
##
cat_rendered_templates=false
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
## Checks if we have all the commands we need
##
function has_cmds() {
for command in "${commands[@]}"; do
if ! hash command 2>/dev/null; then
warn "$command doesn't exist in path!"
exit 1
fi
done
notify "Appear to have all the commands..."
}
function get_image_name() {
IFS=':' read -ra parts <<< "$1"
if [ ${#parts[@]} == 1 ]; then
## no tag, so return the messaged value
##
echo $1
else
echo "${parts[0]}"
fi
}
## Returns the image's tag when messaged .
##
## For example when messaged "redis:5.0.9" this function
## will echo "5.0.9".
##
function get_image_tag() {
IFS=':' read -ra parts <<< "$1"
if [ ${#parts[@]} == 1 ]; then
## Not tag, so return "latest"
##
echo "latest"
else
echo "${parts[1]}"
fi
}
## Call envsbt to replace the environment variables
## in a template and saves the resulting file.
##
function template_file() {
notify "Using the $1 template to generate the $2:"
envsubst <$1 > $2
if [ "$cat_rendered_templates" == true ]; then
cat $2
fi
}
## When messaged a hashmap of images it will
## pull them from the docker hub, tag them for
## private container regitry and push them it
## into it. It will also create variables for
## the image name and tage using they key for
## each image.
##
function images_into_registry() {
notify "Pulling images and placing into k3d-registry..."
# images passed by reference
local -n images=$1
for image in "${!images[@]}"; do
local image_name=$(get_image_name ${images[$image]})
local image_tag=$(get_image_tag ${images[$image]})
eval "${image}_image_name=\"${image_name}\""
eval "${image}_image_tag=\"${image_tag}\""
notify "Pulling, tagging and pushing ${image_name}:${image_tag} into ${registry_name}:${regsitry_port} container image repository..."
docker pull ${images[$image]}
docker tag ${images[$image]} ${registry_name}:${registry_port}/${images[$image]}
docker push ${registry_name}:${registry_port}/${images[$image]}
done
}
## Echo text messaged in green to notify.
##
function notify() {
local green='\033[0;32m'
local no_color='\033[0m'
echo -e "${green}$1${no_color}"
}
## Echo text messaged in red to indicate an error.
##
function error() {
local red='\033[0;31m'
local no_color='\033[0m'
echo -e "${red}$1${no_color}"
}
## Echo text message in yellow to indicate a warning.
##
function warn() {
local yellow='\033[1;33m'
local no_color='\033[0m'
echo -e "${yellow}$1${no_color}"
}
## Echo text message in blue to indicate asking for input.
##
function ask_for_input() {
local light_blue='\033[1;34m'
local no_color='\033[0m'
echo -e "${light_blue}$1${no_color}"
}
if [ ! $skip_encrypted_variables ]; then
notify "Attempting to load secrets from ${SCRIPT_DIR}/vault..."
if file $SCRIPT_DIR/vault | grep -q "openssl"; then
if [ -z "$VAULT_PASSWORD" ]; then
ask_for_input "Enter vault password to decrypt vault to access secured variables in ${SCRIPT_DIR}/vault:"
read VAULT_PASSWORD
else
warn "Using VAULT_PASSWORD env variable to access secured variables contained in the ${SCRIPT_DIR}/vault..."
fi
eval "$(openssl enc -base64 -d -aes-256-cbc -md sha512 -pbkdf2 -iter 100000 -salt -pass pass:${VAULT_PASSWORD} -in ${SCRIPT_DIR}/vault)"
else
warn "${SCRIPT_DIR}/vault was found unecrypted and used..."
source ${SCRIPT_DIR}/vault
fi
fi
## Set variables for project
##
notify "Setting unsecured variables into current context..."
domain="nemonik.com"
## Container registry
##
registry_name="k3d-registry.nemonik.com"
#registry_name="k3d-registry.localhost"
registry_port="5000"
## K3d cluster
##
# The cluster's name must be limited to 'Aa-Zz', '0-9' or '-' characters
k3d_cluster_name="hands-on-devops-class"
k3d_server_count="1"
k3d_agent_count="1"
## Traefik
#
traefik_version="2.2.8"
traefik_namespace="traefik"
# traefik_tls_crt is in ./vault
# traefik_tls_key is in ./vault
declare -A traefik_images=( \
["traefik"]="traefik:${traefik_version}" )
## Used for testing
##
test_namespace="test"
test_fdqn="test.${domain}"
test_protocol="https"
declare -A test_images=( \
["nginx"]="nginx:1.19-alpine" )
## Taiga
##
taiga_version="latest"
taiga_namespace="taiga"
taiga_fdqn="taiga.${domain}"
taiga_protocol="https"
taiga_port=443
taiga_user=root
taiga_password=password
declare -A taiga_images=( \
["rabbitmq"]="rabbitmq:3-management-alpine" \
["taiga_back"]="taigaio/taiga-back:${taiga_version}" \
["postgres"]="postgres:12.3" \
["taiga_events"]="taigaio/taiga-events:${taiga_version}" \
["taiga_front"]="taigaio/taiga-front:${taiga_version}" \
["nginx"]="nginx:1.19-alpine" \
["taiga_protected"]="taigaio/taiga-protected:${taiga_version}" )
## GitLab
##
gitlab_version="13.12.0"
gitlab_namespace="gitlab"
gitlab_fdqn="gitlab.${domain}"
gitlab_protocol="https"
gitlab_port=443
declare -A gitlab_images=( \
["redis"]="redis:5.0.9" \
["postgresql"]="sameersbn/postgresql:11-20200524" \
["gitlab"]="sameersbn/gitlab:${gitlab_version}" )
## Drone
##
drone_namespace="drone"
drone_fdqn="drone.${domain}"
drone_protocol="https"
drone_runner_replica_count=1
# declare -A drone_images=( \
# ["postgresql"]="sameersbn/postgresql:11-20200524" \
# ["drone"]="nemonik/drone:1.9.0" \
# ["drone_runner_kube"]="drone/drone-runner-kube:1.0.0-beta.6" \
# ["kubernetes_secrets"]="drone/kubernetes-secrets:latest" )
declare -A drone_images=( \
["postgresql"]="sameersbn/postgresql:11-20200524" \
["drone"]="nemonik/drone:latest" \
["drone_runner_kube"]="drone/drone-runner-kube:latest" \
["kubernetes_secrets"]="drone/kubernetes-secrets:latest" )
## PlantUML Server
##
plantuml_server_namespace="plantuml"
plantuml_server_fdqn="plantuml.${domain}"
plantuml_server_protocol="https"
declare -A plantuml_server_images=( \
["plantuml_server"]="plantuml/plantuml-server:latest" )
## SonarQube
##
sonarqube_namespace="sonarqube"
sonarqube_fdqn="sonar.${domain}"
sonarqube_protocol="https"
sonarqube_port="443"
declare -A sonarqube_images=( \
["sonarqube"]="sonarqube:8.5.1-community" \
["busybox"]="busybox:1.32" \
["postgresql"]="bitnami/postgresql:11.7.0-debian-10-r26" )
## Heimdall2
##
heimdall_namespace="heimdall2"
heimdall_fdqn="heimdall.${domain}"
heimdall_protocol="https"
heimdall_port="443"
heimdall_database_password=`openssl rand -hex 33`
heimdall_jwt_secret=`openssl rand -hex 64`
declare -A heimdall_images=( \
["postgres"]="postgres:13" \
["heimdall"]="mitre/heimdall2:2.4.8" )
## CoreDNS entries
##
coredns_entries=( "${gitlab_fdqn}" "${drone_fdqn}" "${taiga_fdqn}" "${sonarqube_fdqn}" "${plantuml_server_fdqn}" "${heimdall_fdqn}" "${registry_name}" "helloworld.nemonik.com")