-
Notifications
You must be signed in to change notification settings - Fork 2
/
runonce
executable file
·643 lines (592 loc) · 35.7 KB
/
runonce
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
#!/bin/bash
local_admin_user="local-admin"
nexus_keycloak_plugin="0.5.0"
nexus_apk_plugin="0.0.26"
netcicd_pwd="netcicd01"
keycloak_pwd="Pa55w0rd"
keycloak_storepass="password"
jenkins_storepass="changeit"
nexus_storepass="password"
sp="/-\|"
sc=0
spin() {
printf -- "${sp:sc++:1} ( ${t} sec.) \r"
((sc==${#sp})) && sc=0
sleep 1
let t+=1
}
endspin() {
printf "\r%s\n" "$@"
}
echo "****************************************************************************************************************"
echo " Start clean"
echo "****************************************************************************************************************"
docker compose --project-name cicd-toolbox down --remove-orphans
docker compose --project-name cicd-toolbox rm -f
docker volume rm $(docker volume ls -q)
rm -f *_token
rm -f install_tests/log.html
rm -f install_tests/output.xml
rm -f install_tests/report.html
rm -f install_tests/*.png
rm -f install_tests/*.log
rm -rf install_log/*
rm *_log.html
rm *_report.html
rm *.xml
echo " "
echo "****************************************************************************************************************"
echo " Cleaning Vault"
echo "****************************************************************************************************************"
rm -f vault/certs/*.json
rm -f vault/certs/*.pem
rm -f vault/certs/*.crt
rm -f vault/certs/*.csr
rm -f vault/*.txt
#terraform -chdir=terraform/vault state rm $(terraform -chdir=terraform/vault state list)
echo " "
echo "****************************************************************************************************************"
echo " Cleaning LLDAP"
echo "****************************************************************************************************************"
rm -f lldap/data/*.crt
rm -rf lldap/data/*.pem
echo " "
echo "****************************************************************************************************************"
echo " Cleaning database"
echo "****************************************************************************************************************"
rm -f cicdtoolbox-db/docker-entrypoint-initdb-resources/*
echo " "
echo "****************************************************************************************************************"
echo " Cleaning Gitea"
echo "****************************************************************************************************************"
rm -f gitea/gitea.tooling.provider.test*
sudo rm -rf gitea/data/*
echo " "
echo "****************************************************************************************************************"
echo " Cleaning Jenkins"
echo "****************************************************************************************************************"
rm -f jenkins/jenkins.tooling*
rm -f jenkins_buildnode/*_secret.txt
rm -f jenkins_buildnode/agent.jar
rm -f jenkins_buildnode/jenkins-cli.jar
rm -f jenkins_buildnode/*_token
echo " "
echo "****************************************************************************************************************"
echo " Cleaning Nexus"
echo "****************************************************************************************************************"
rm -f nexus/keystore.jks
sudo rm -rf nexus/data/*
#sudo rm -rf nexus/*.kar
echo " "
echo "****************************************************************************************************************"
echo " Cleaning Argos"
echo "****************************************************************************************************************"
if [ -f "argos/compose-application.yml" ]; then
cp -p argos/compose-application.yml argos/application.yml
fi
echo "****************************************************************************************************************"
echo " Making sure all containers are reachable locally with the name in the"
echo " hosts file."
echo "****************************************************************************************************************"
echo " "
sudo chmod o+w /etc/hosts
if grep -q "mongodb" /etc/hosts; then
echo " mongodb exists in /etc/hosts, removing..."
sudo sed -i '/mongodb.internal.provider.test/d' /etc/hosts
fi
echo " Add mongodb to /etc/hosts"
sudo echo "172.16.9.3 mongodb.internal.provider.test" >> /etc/hosts
if grep -q "argos.services.provider.test" /etc/hosts; then
echo " Argos Notary Portal exists in /etc/hosts, removing..."
sudo sed -i '/argos.services.provider.test/d' /etc/hosts
fi
echo " Add Argos Notary Portal to /etc/hosts"
sudo echo "172.16.10.4 argos.services.provider.test" >> /etc/hosts
if grep -q "argos-service.tooling.provider.test" /etc/hosts; then
echo " Argos Service exists in /etc/hosts, removing..."
sudo sed -i '/argos-service.tooling.provider.test/d' /etc/hosts
fi
echo " Add Argos Service to /etc/hosts"
sudo echo "172.16.11.4 argos-service.tooling.provider.test" >> /etc/hosts
if grep -q "backstage" /etc/hosts; then
echo " Backstage exists in /etc/hosts, removing..."
sudo sed -i '/backstage.tooling.provider.test/d' /etc/hosts
fi
echo " Add Backstage to /etc/hosts"
sudo echo "172.16.11.14 backstage.tooling.provider.test" >> /etc/hosts
if grep -q "cicdtoolbox-db" /etc/hosts; then
echo " CICDtoolbox-db exists in /etc/hosts, removing..."
sudo sed -i '/cicdtoolbox-db.internal.provider.test/d' /etc/hosts
fi
echo " Add CICDtoolbox-db to /etc/hosts"
sudo echo "172.16.9.2 cicdtoolbox-db.internal.provider.test" >> /etc/hosts
if grep -q "gitea" /etc/hosts; then
echo " Gitea exists in /etc/hosts, removing..."
sudo sed -i '/gitea.tooling.provider.test/d' /etc/hosts
fi
echo " Add Gitea to /etc/hosts"
sudo echo "172.16.11.3 gitea.tooling.provider.test" >> /etc/hosts
if grep -q "loki" /etc/hosts; then
echo " Loki exists in /etc/hosts, removing..."
sudo sed -i '/loki.monitoring.provider.test/d' /etc/hosts
fi
echo " Add Loki to /etc/hosts"
sudo echo "172.16.13.4 loki.monitoring.provider.test" >> /etc/hosts
if grep -q "promtail" /etc/hosts; then
echo " Promtail exists in /etc/hosts, removing..."
sudo sed -i '/promtail.monitoring.provider.test/d' /etc/hosts
fi
echo " Add Promtail to /etc/hosts"
sudo echo "172.16.13.5 promtail.monitoring.provider.test" >> /etc/hosts
if grep -q "grafana" /etc/hosts; then
echo " Grafana exists in /etc/hosts, removing..."
sudo sed -i '/grafana.monitoring.provider.test/d' /etc/hosts
fi
echo " Add Grafana to /etc/hosts"
sudo echo "172.16.13.6 grafana.monitoring.provider.test" >> /etc/hosts
if grep -q "jenkins" /etc/hosts; then
echo " Jenkins exists in /etc/hosts, removing..."
sudo sed -i '/jenkins.tooling.provider.test/d' /etc/hosts
fi
echo " Add Jenkins to /etc/hosts"
sudo echo "172.16.11.8 jenkins.tooling.provider.test" >> /etc/hosts
if grep -q "build-dev" /etc/hosts; then
echo " Jenkins build-dev node exists in /etc/hosts, removing..."
sudo sed -i '/build-dev.delivery.provider.test/d' /etc/hosts
fi
echo " Add Jenkins build-dev node to /etc/hosts"
sudo echo "172.16.12.2 build-dev.delivery.provider.test" >> /etc/hosts
if grep -q "build-test" /etc/hosts; then
echo " Jenkins build-test node exists in /etc/hosts, removing..."
sudo sed -i '/build-test.delivery.provider.test/d' /etc/hosts
fi
echo " Add Jenkins build-test node to /etc/hosts"
sudo echo "172.16.12.3 build-test.delivery.provider.test" >> /etc/hosts
if grep -q "build-acc" /etc/hosts; then
echo " Jenkins build-acc node exists in /etc/hosts, removing..."
sudo sed -i '/build-acc.delivery.provider.test/d' /etc/hosts
fi
echo " Add Jenkins build-acc node to /etc/hosts"
sudo echo "172.16.12.4 build-acc.delivery.provider.test" >> /etc/hosts
if grep -q "build-prod" /etc/hosts; then
echo " Jenkins build-prod node exists in /etc/hosts, removing..."
sudo sed -i '/build-prod.delivery.provider.test/d' /etc/hosts
fi
echo " Add Jenkins build-prod node to /etc/hosts"
sudo echo "172.16.12.5 build-prod.delivery.provider.test" >> /etc/hosts
if grep -q "keycloak" /etc/hosts; then
echo " Keycloak exists in /etc/hosts, removing..."
sudo sed -i '/keycloak.services.provider.test/d' /etc/hosts
fi
echo " Add Keycloak to /etc/hosts"
sudo echo "172.16.10.11 keycloak.services.provider.test" >> /etc/hosts
if grep -q "ldap" /etc/hosts; then
echo " LLDAP exists in /etc/hosts, removing..."
sudo sed -i '/ldap.iam.provider.test/d' /etc/hosts
fi
echo " Add LLDAP to /etc/hosts"
sudo echo "172.16.8.11 ldap.iam.provider.test" >> /etc/hosts
if grep -q "nexus" /etc/hosts; then
echo " Nexus exists in /etc/hosts, removing..."
sudo sed -i '/nexus.tooling.provider.test/d' /etc/hosts
fi
echo " Add Nexus to /etc/hosts"
sudo echo "172.16.11.9 nexus.tooling.provider.test" >> /etc/hosts
if grep -q "nodered" /etc/hosts; then
echo " Node Red exists in /etc/hosts, removing..."
sudo sed -i '/nodered.tooling.provider.test/d' /etc/hosts
fi
echo " Add Node Red to /etc/hosts"
sudo echo "172.16.11.13 nodered.tooling.provider.test" >> /etc/hosts
if grep -q "portainer" /etc/hosts; then
echo " Portainer exists in /etc/hosts, removing..."
sudo sed -i '/portainer.monitoring.provider.test/d' /etc/hosts
fi
echo " Add Portainer to /etc/hosts"
sudo echo "172.16.13.3 portainer.monitoring.provider.test" >> /etc/hosts
if grep -q "restportal" /etc/hosts; then
echo " Provider REST portal exists in /etc/hosts, removing..."
sudo sed -i '/restportal.services.provider.test/d' /etc/hosts
fi
echo " Add Provider REST portal to /etc/hosts"
sudo echo "172.16.10.2 restportal.services.provider.test" >> /etc/hosts
if grep -q "consul" /etc/hosts; then
echo " Hashicorp Consul exists in /etc/hosts, removing..."
sudo sed -i '/consul.internal.provider.test/d' /etc/hosts
fi
echo " Add Hashicorp Consul to /etc/hosts"
sudo echo "172.16.9.4 consul.internal.provider.test" >> /etc/hosts
if grep -q "vault" /etc/hosts; then
echo " Hashicorp Vault exists in /etc/hosts, removing..."
sudo sed -i '/vault.internal.provider.test/d' /etc/hosts
fi
echo " Add Hashicorp Vault to /etc/hosts"
sudo echo "172.16.9.5 vault.internal.provider.test" >> /etc/hosts
if grep -q "redis" /etc/hosts; then
echo " Redis exists in /etc/hosts, removing..."
sudo sed -i '/redis.tooling.provider.test/d' /etc/hosts
fi
echo " Add Redis to /etc/hosts"
sudo echo "172.16.11.11 redis.tooling.provider.test" >> /etc/hosts
if grep -q "netbox" /etc/hosts; then
echo " Netbox exists in /etc/hosts, removing..."
sudo sed -i '/netbox.tooling.provider.test/d' /etc/hosts
fi
echo " Add Netbox to /etc/hosts"
sudo echo "172.16.11.12 netbox.tooling.provider.test" >> /etc/hosts
if grep -q "seleniumffhost" /etc/hosts; then
echo "Selenium Firefox testhost exists in /etc/hosts, removing..."
sudo sed -i '/seleniumffhost.internal.provider.test/d' /etc/hosts
fi
echo " Add Selenium Firefox testhost to /etc/hosts"
sudo echo "172.16.10.100 seleniumffhost.internal.provider.test" >> /etc/hosts
if grep -q "seleniumgchost" /etc/hosts; then
echo "Selenium Google Chrome testhost exists in /etc/hosts, removing..."
sudo sed -i '/seleniumgchost.internal.provider.test/d' /etc/hosts
fi
echo " Add Selenium Google Chrome testhost to /etc/hosts"
sudo echo "172.16.10.101 seleniumgchost.internal.provider.test" >> /etc/hosts
if grep -q "opennebula" /etc/hosts; then
echo "Opennebula Controller exists in /etc/hosts, removing..."
sudo sed -i '/opennebula.tooling.provider.test/d' /etc/hosts
fi
echo " Add Opennebula Controller to /etc/hosts"
sudo echo "172.16.10.30 opennebula.tooling.provider.test" >> /etc/hosts
if grep -q "minio" /etc/hosts; then
echo "Minio exists in /etc/hosts, removing..."
sudo sed -i '/minio.tooling.provider.test/d' /etc/hosts
fi
echo " Add Minio to /etc/hosts"
sudo echo "172.16.9.6 minio.tooling.provider.test" >> /etc/hosts
if grep -q "cml" /etc/hosts; then
echo " Cisco Modeling Labs exists in /etc/hosts, removing..."
sudo sed -i '/cml.tooling.provider.test/d' /etc/hosts
fi
echo " Add Cisco Modeling Labs to /etc/hosts"
sudo echo "10.10.20.161 cml.tooling.provider.test" >> /etc/hosts
sudo chmod o-w /etc/hosts
echo "****************************************************************************************************************"
echo " Setting up Chrome host for Selenium"
echo "****************************************************************************************************************"
docker compose --project-name cicd-toolbox up -d --build --no-deps seleniumgchost.internal.provider.test
echo "****************************************************************************************************************"
echo " Setting up Firefox host for Selenium"
echo "****************************************************************************************************************"
docker compose --project-name cicd-toolbox up -d --build --no-deps seleniumffhost.internal.provider.test
echo "****************************************************************************************************************"
echo " Setting up Vault"
echo "****************************************************************************************************************"
vault/vault_install.sh | tee install_log/vault_create.log
echo "****************************************************************************************************************"
echo " Collecting Nexus Keycloak plugin"
echo "****************************************************************************************************************"
if [ -f "nexus/nexus3-keycloak-plugin-$nexus_keycloak_plugin-bundle.kar" ]; then
echo " Nexus Keycloak plugin exists"
else
echo " Get Nexus Keycloak plugin"
wget --directory-prefix=nexus https://github.com/flytreeleft/nexus3-keycloak-plugin/releases/download/v$nexus_keycloak_plugin/nexus3-keycloak-plugin-$nexus_keycloak_plugin-bundle.kar
fi
echo " "
echo "****************************************************************************************************************"
echo " Collecting Nexus APK plugin and build .kar file"
echo "****************************************************************************************************************"
if [ -f "nexus/nexus-repository-apk-$nexus_apk_plugin-bundle.kar" ]; then
echo " Nexus apk plugin exists"
else
echo " Get Nexus apk plugin"
wget -O nexus/nexus-repository-apk-$nexus_apk_plugin-bundle.kar https://search.maven.org/remotecontent?filepath=org/sonatype/nexus/plugins/nexus-repository-apk/$nexus_apk_plugin/nexus-repository-apk-$nexus_apk_plugin-bundle.kar
fi
echo " "
echo "****************************************************************************************************************"
echo " git clone Nexus CasC plugin and build .kar file"
echo "****************************************************************************************************************"
if [ ! -f ./nexus/nexus-casc* ]; then
git clone https://github.com/AdaptiveConsulting/nexus-casc-plugin.git
cd nexus-casc-plugin
mvn package
cp target/*.kar ../nexus/
cd ..
rm -rf nexus-casc-plugin/
else
echo "Casc plugin exists, no need to build"
fi
echo " "
echo "****************************************************************************************************************"
echo " Creating LDAP server"
echo "****************************************************************************************************************"
cp vault/certs/ldap.iam.provider.test.* lldap/data/
docker compose --project-name cicd-toolbox up -d --build --remove-orphans ldap.iam.provider.test
echo " "
echo "****************************************************************************************************************"
echo " Saving CA self-signed certificate"
echo "****************************************************************************************************************"
cp vault/certs/ca.crt argos/ca.crt
cp vault/certs/ca.crt backstage/ca.crt
cp vault/certs/ca.crt cicdtoolbox-db/ca.crt
cp vault/certs/ca.crt gitea/ca.crt
cp vault/certs/ca.crt grafana/ca.crt
cp vault/certs/ca.crt jenkins/ca.crt
cp vault/certs/ca.crt jenkins_buildnode/ca.crt
cp vault/certs/ca.crt keycloak/ca.crt
cp vault/certs/ca.crt lldap/ca.crt
cp vault/certs/ca.crt loki/ca.crt
cp vault/certs/ca.crt netbox/ca.crt
cp vault/certs/ca.crt nexus/ca.crt
cp vault/certs/ca.crt nodered/ca.crt
cp vault/certs/ca.crt portainer/ca.crt
cp vault/certs/ca.crt promtail/ca.crt
cp vault/certs/ca.crt restportal/ca.crt
cp vault/certs/ca.crt opennebula/ca.crt
echo "****************************************************************************************************************"
echo " Saving database certificates"
echo "****************************************************************************************************************"
cp vault/certs/cicdtoolbox-db.internal.provider.test.pem cicdtoolbox-db/docker-entrypoint-initdb-resources/server.key
cp vault/certs/cicdtoolbox-db.internal.provider.test.crt cicdtoolbox-db/docker-entrypoint-initdb-resources/server.crt
cp vault/certs/ca.crt cicdtoolbox-db/docker-entrypoint-initdb-resources/root.crt
echo " "
echo "****************************************************************************************************************"
echo " Creating database"
echo "****************************************************************************************************************"
DOCKER_BUILDKIT=1 docker compose --project-name cicd-toolbox up -d --build cicdtoolbox-db.internal.provider.test
sleep 10
echo " "
echo "****************************************************************************************************************"
echo " Starting Keycloak "
echo "****************************************************************************************************************"
docker compose --project-name cicd-toolbox up -d --build --no-deps keycloak.services.provider.test
echo "****************************************************************************************************************"
echo " Wait until keycloak is running (~45 sec.)"
echo "****************************************************************************************************************"
let t=0
until $(curl --output /dev/null --silent --head --fail https://keycloak.services.provider.test:8443); do
spin
done
endspin
echo " "
echo "****************************************************************************************************************"
echo " Creating keycloak setup. This will take time..."
echo "****************************************************************************************************************"
docker exec -it keycloak.services.provider.test sh -c "/opt/keycloak/bin/create-realm.sh ${keycloak_pwd} ${keycloak_storepass} ${keycloak_pwd} ${local_admin_user}" | tee install_log/keycloak_create.log
echo " "
docker restart keycloak.services.provider.test
echo "****************************************************************************************************************"
echo " Wait until keycloak is running (~5 sec.)"
echo "****************************************************************************************************************"
let t=0
until $(curl --output /dev/null --silent --head --fail https://keycloak.services.provider.test:8443); do
spin
done
endspin
echo " "
echo "****************************************************************************************************************"
echo " Creating keycloak-vault integration"
echo "****************************************************************************************************************"
vault/vault_install_post_keycloak.sh
echo "****************************************************************************************************************"
echo " Creating keycloak-nexus json"
echo "****************************************************************************************************************"
docker cp keycloak.services.provider.test:/opt/keycloak/bin/keycloak-nexus.json nexus/keycloak-nexus.json
echo " "
echo "****************************************************************************************************************"
echo " Starting Jenkins"
echo "****************************************************************************************************************"
jenkins/jenkins-install.sh ${jenkins_storepass}
echo " "
echo "****************************************************************************************************************"
echo " Saving gitea certificates"
echo "****************************************************************************************************************"
cp vault/certs/gitea* gitea/
echo "****************************************************************************************************************"
echo " Creating gitea setup"
echo "****************************************************************************************************************"
gitea/gitea_install.sh ${netcicd_pwd} ${local_admin_user} | tee install_log/gitea_create.log
gitea/gitea_users.sh ${netcicd_pwd} ${local_admin_user} | tee install_log/gitea_users.log
echo " "
echo "****************************************************************************************************************"
echo " Booting Nexus"
echo "****************************************************************************************************************"
docker compose --project-name cicd-toolbox up -d --build --no-deps nexus.tooling.provider.test
echo "****************************************************************************************************************"
echo " Creating nexus setup (~ 115 sec.)"
echo "****************************************************************************************************************"
openssl pkcs12 -export -in ./vault/certs/nexus.tooling.provider.test.crt -inkey ./vault/certs/nexus.tooling.provider.test.pem -name nexus.tooling.provider.test -out ./nexus/nexus.p12 -password pass:${nexus_storepass}
chmod 644 ./nexus/nexus.p12
docker cp nexus/nexus.p12 nexus.tooling.provider.test:/nexus-data/etc/nexus.p12
docker exec --user root -it nexus.tooling.provider.test sh -c "/usr/bin/keytool -importkeystore -deststorepass ${nexus_storepass} -destkeystore /nexus-data/etc/ssl/keystore.jks -srckeystore /nexus-data/etc/nexus.p12 -srcstoretype PKCS12 -srcstorepass ${nexus_storepass} -deststoretype pkcs12"
echo "Reloading Nexus"
docker restart nexus.tooling.provider.test
let t=0
until $(curl --output /dev/null --insecure --silent --head --fail https://nexus.tooling.provider.test:8443); do
spin
done
endspin
echo " "
echo "****************************************************************************************************************"
echo " Finalizing install via ROBOT"
echo "****************************************************************************************************************"
robot --variable VALID_PASSWORD:${netcicd_pwd} -d install_log -o 20_finalize.xml -l 20_finalize_log.html -r 20_finalize_report.html finalize_install.robot
echo " "
echo "****************************************************************************************************************"
echo " Copying Jenkins Keystore to Jenkins buildnodes"
echo "****************************************************************************************************************"
cp ./jenkins/keystore/cacerts ./jenkins_buildnode/cacerts
echo " "
echo "****************************************************************************************************************"
echo " Retrieving Jenkins CSRF"
echo "****************************************************************************************************************"
jtoken=`cat jtoken.txt`
crumb=`curl -u "jenkins-jenkins:${jtoken}" --insecure 'https://jenkins.tooling.provider.test:8084/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)'`
csrf=$( echo $crumb | awk -F',' '{print $(1)}' | awk -F':' '{print $2}' )
echo $csrf
rm -f jtoken.txt
echo " "
echo "****************************************************************************************************************"
echo " Retrieving Jenkins Agent secrets"
echo "****************************************************************************************************************"
curl -L --insecure -u "jenkins-jenkins:${jtoken}" -H "Jenkins-Crumb:${csrf}" https://jenkins.tooling.provider.test:8084/computer/Dev/jenkins-agent.jnlp -s | sed "s/.*<jnlp><application-desc><argument>\([a-z0-9]*\).*/\1/" > ./jenkins_buildnode/Dev_secret.txt
curl -L --insecure -u "jenkins-jenkins:${jtoken}" -H "Jenkins-Crumb:${csrf}" https://jenkins.tooling.provider.test:8084/computer/Acc/jenkins-agent.jnlp -s | sed "s/.*<jnlp><application-desc><argument>\([a-z0-9]*\).*/\1/" > ./jenkins_buildnode/Acc_secret.txt
curl -L --insecure -u "jenkins-jenkins:${jtoken}" -H "Jenkins-Crumb:${csrf}" https://jenkins.tooling.provider.test:8084/computer/Test/jenkins-agent.jnlp -s | sed "s/.*<jnlp><application-desc><argument>\([a-z0-9]*\).*/\1/" > ./jenkins_buildnode/Test_secret.txt
curl -L --insecure -u "jenkins-jenkins:${jtoken}" -H "Jenkins-Crumb:${csrf}" https://jenkins.tooling.provider.test:8084/computer/Prod/jenkins-agent.jnlp -s | sed "s/.*<jnlp><application-desc><argument>\([a-z0-9]*\).*/\1/" > ./jenkins_buildnode/Prod_secret.txt
echo "****************************************************************************************************************"
echo " Building build nodes"
echo "****************************************************************************************************************"
jenkins_buildnode/create_runner.sh ${netcicd_pwd} | tee install_log/vault_create.log
echo "****************************************************************************************************************"
echo " Starting Restportal"
echo "****************************************************************************************************************"
docker compose --project-name cicd-toolbox up -d --build --no-deps restportal.services.provider.test
echo "****************************************************************************************************************"
echo " Starting Opennebula Frontend"
echo "****************************************************************************************************************"
docker compose --project-name cicd-toolbox up -d --build --no-deps opennebula.tooling.provider.test
echo "****************************************************************************************************************"
echo " Starting minio"
echo "****************************************************************************************************************"
docker compose --project-name cicd-toolbox up -d --build --no-deps minio.internal.provider.test
echo "****************************************************************************************************************"
echo " Copying Jenkins Keystore to Argos node"
echo "****************************************************************************************************************"
cp ./jenkins/keystore/cacerts ./argos/cacerts
cp ./jenkins/keystore/cacerts ./argos-service/cacerts
echo " "
echo "****************************************************************************************************************"
echo " Creating Argos setup"
echo "****************************************************************************************************************"
argos_client_id=$(grep ARGOS_token install_log/keycloak_create.log | cut -d' ' -f2 | tr -d '\r' )
sed -i -e "s/argos_secret/$argos_client_id/" argos/application.yml
echo "****************************************************************************************************************"
echo " Starting Argos"
echo "****************************************************************************************************************"
docker compose --project-name cicd-toolbox up -d --build --no-deps mongodb.internal.provider.test
docker compose --project-name cicd-toolbox up -d --build --no-deps argos-service.tooling.provider.test
docker compose --project-name cicd-toolbox up -d --build --no-deps argos.services.provider.test
# echo "****************************************************************************************************************"
# echo " Building Backstage"
# echo "****************************************************************************************************************"
# docker compose --project-name cicd-toolbox up -d --build --no-deps oauth2-proxy.tooling.provider.test
# backstage_client_id=$(grep Backstage_token install_log/keycloak_create.log | cut -d' ' -f2 | tr -d '\r' )
# docker exec -it oauth2-proxy.tooling.provider.test sh -c "OAUTH2_PROXY_CLIENT_SECRET=$backstage_client_id"
# docker restart oauth2-proxy.tooling.provider.test
# docker compose --project-name cicd-toolbox up -d --build --no-deps backstage.tooling.provider.test
echo "****************************************************************************************************************"
echo " Start NodeRed"
echo "****************************************************************************************************************"
docker compose --project-name cicd-toolbox up -d --build --no-deps nodered.tooling.provider.test
echo "****************************************************************************************************************"
echo " Start Portainer"
echo "****************************************************************************************************************"
docker compose --project-name cicd-toolbox up -d --build --no-deps portainer.monitoring.provider.test
echo "****************************************************************************************************************"
echo " Starting Netbox"
echo "****************************************************************************************************************"
docker compose --project-name cicd-toolbox up -d --build --no-deps redis.tooling.provider.test
docker compose --project-name cicd-toolbox up -d --build --no-deps netbox.tooling.provider.test
echo " "
echo "****************************************************************************************************************"
echo " Starting Loki, Promtail and Grafana..."
echo "****************************************************************************************************************"
docker compose --project-name cicd-toolbox up -d --build --no-deps loki.monitoring.provider.test
docker compose --project-name cicd-toolbox up -d --build --no-deps promtail.monitoring.provider.test
docker compose --project-name cicd-toolbox up -d --build --no-deps grafana.monitoring.provider.test
echo " "
echo "****************************************************************************************************************"
echo " Validating install"
echo "****************************************************************************************************************"
robot --variable VALID_PASSWORD:${netcicd_pwd} -d install_log -o 100_install_test.xml -l 100_install_test_log.html -r 100_install_test_report.html install_tests
echo " "
echo "****************************************************************************************************************"
echo " Running trivy vulnerability scanner (https://github.com/aquasecurity/trivy)"
echo "****************************************************************************************************************"
if command -v trivy &> /dev/null
then
echo "****************************************************************************************************************"
echo " Toolbox files"
echo "****************************************************************************************************************"
trivy fs --security-checks vuln,config . | tee install_log/trivy_create.log
echo "****************************************************************************************************************"
echo " Gitea"
echo "****************************************************************************************************************"
trivy image gitea/gitea:rootless | tee -a install_log/trivy_create.log
echo "****************************************************************************************************************"
echo " Jenkins"
echo "****************************************************************************************************************"
trivy image jenkins/jenkins:lts | tee -a install_log/trivy_create.log
echo "****************************************************************************************************************"
echo " Keycloak"
echo "****************************************************************************************************************"
trivy image jboss/keycloak:latest | tee -a install_log/trivy_create.log
echo "****************************************************************************************************************"
echo " PostgreSQL"
echo "****************************************************************************************************************"
trivy image postgres:latest | tee -a install_log/trivy_create.log
echo "****************************************************************************************************************"
echo " Nexus"
echo "****************************************************************************************************************"
trivy image sonatype/nexus3:latest | tee -a install_log/trivy_create.log
else
echo "trivy is not installed"
fi
echo "****************************************************************************************************************"
echo " Consolidating all robot test reports into one"
echo "****************************************************************************************************************"
rebot --norpa --output runonce.xml --log runonce_log.html --report runonce_report.html ./install_log/*.xml
echo "****************************************************************************************************************"
echo " The pipeline uses the default Cisco DevNet CML Sandbox credentials developer/C1sco12345 to log in to CML."
echo " You may change this to your own credentials in:"
echo " "
echo " http://jenkins.tooling.provider.test:8084/credentials/store/system/domain/_/credential/CML-SIM-CRED/update"
echo " "
echo " Due to limitations in Keycloak, do **not** use docker compose --project-name cicd-toolbox down. Keycloak will no longer function after this."
echo " "
echo " Stop the environment with ./down, start with ./up"
echo " "
echo "****************************************************************************************************************"
echo "CICD-toolbox install done "
echo " "
echo "You can read the install test report in install_tests/report.html"
echo " "
echo "You can reach the servers on:"
echo " "
echo " LLDAP: http://ldap.iam.provider.test:17170"
echo " Keycloak: https://keycloak.services.provider.test:8443"
echo " Gitea: https://gitea.tooling.provider.test:3000"
echo " Jenkins: https://jenkins.tooling.provider.test:8084"
echo " Nexus: https://nexus.tooling.provider.test:8443"
echo " Portainer: http://portainer.monitoring.provider.test:9000"
echo " Grafana: http://grafana.monitoring.provider.test:3000"
echo " Netbox: http://netbox.tooling.provider.test:8000"
#echo " Backstage: https://backstage.tooling.provider.test"
echo " restportal: http://restportal.services.provider.test:8200"
echo " Vault: https://vault.internal.provider.test:8200"
echo " OpenNebula: http://opennebula.tooling.provider.test"
echo " Minio: http://minio.tooling.provider.test:9001"
echo " NodeRed: http://nodered.tooling.provider.test:1880"
echo " Firefox: http://seleniumffhost.internal.provider.test:4444 (Dashboard)"
echo " http://seleniumffhost.internal.provider.test:7900 (NoVNC)"
echo " Chrome: http://seleniumgchost.internal.provider.test:4444 (Dashboard)"
echo " http://seleniumgchost.internal.provider.test:7900 (NoVNC)"
echo " "
echo " The installation test report generated by Robotframework can be found here: file:///home/$USER/CICD-toolbox/runonce_report.html"
echo "****************************************************************************************************************"
echo "Cleaning up"
echo "****************************************************************************************************************"