-
Notifications
You must be signed in to change notification settings - Fork 1
/
Build.sh
executable file
·65 lines (53 loc) · 2.8 KB
/
Build.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
#! /bin/bash
if [[ ! -f "./Minikube-Infra/TF_key.pem" ]]; then
# creating empty key and inventory
touch ./Minikube-Infra/TF_key.pem
touch ./Ansible-Credentials/inventory
touch ./Get-Passwords/inventory
# building minikube cluster locally and using its local exec
# to set ec2 ip to inventory in ../Ansible-Credentials/inventory and kubernetes provider in ../Kubernetes-Resources/main.tf
cd ./Minikube-Infra
terraform init
terraform apply -auto-approve
#play ansible that get all certificates and config file to local ../Kubernetes-Resources
cd ../Ansible-Credentials
ansible-playbook playbook.yaml --private-key ../Minikube-Infra/TF_key.pem -u ubuntu --ssh-common-args='-o StrictHostKeyChecking=no' --verbose
# after getting config file change its certificates by data
cd ../Kubernetes-Resources
var1=$(cat ca.crt | base64 -w 0 ; echo )
sed -i -e "/certificate-authority:/ s/certificate-authority:[^/\n]*/certificate-authority-data: ${var1}/g" ./config
var2=$(cat client.crt | base64 -w 0 ; echo )
sed -i -e "/client-certificate:/ s/client-certificate:[^/\n]*/client-certificate-data: ${var2}/g" ./config
var3=$(cat client.key | base64 -w 0 ; echo )
sed -i -e "/client-key:/ s/client-key:[^/\n]*/client-key-data: ${var3}/g" ./config
sed -i "s|/root/.minikube/ca.crt||g" ./config
sed -i "s|/root/.minikube/profiles/minikube/client.crt||g" ./config
sed -i "s|/root/.minikube/profiles/minikube/client.key||g" ./config
# now kubernetes provider has its ec2 ip which apiserver endpoint listen to
# and has all its certificate
# and has config that gonna be use by jenkins secret file credentials to deploy on minikube from pipeline
# apply all kubernetes resources
terraform init
terraform apply -auto-approve
# getting jenkins & nexus passwords and apply new nexus cluster ip service to ../CI-CD/app.yaml
cd ../Get-Passwords
ansible-playbook -i inventory playbook.yaml --private-key ../Minikube-Infra/TF_key.pem -u ubuntu --ssh-common-args='-o StrictHostKeyChecking=no'
# applly agian kubernetes resources to change that new service ip cause the old one from our previous build
cd ../Kubernetes-Resources
terraform apply -auto-approve
# now pushing all new changins to git hub
cd ..
git add .
git commit -m "update nexus service ip to new one"
git push -u origin master
echo "Infrastructure has been built Successfully "
echo "-------------------"
echo "Jenkins-Password : "
awk ' {print $1}' ./Get-Passwords/file.txt
echo "-------------------"
echo "nexus-Password : "
awk ' {print $2}' ./Get-Passwords/file.txt
echo "--------------------"
echo "nexus-repo-cluster-ip : "
awk ' {print $3}' ./Get-Passwords/file.txt
fi