-
Notifications
You must be signed in to change notification settings - Fork 0
/
apps-deployment-script.sh
98 lines (82 loc) · 3.23 KB
/
apps-deployment-script.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
#!/bin/bash
PROJECT_ID="$(gcloud config get-value project)"
REGION="$1"
GKE_CLUSTER="car-demo-gke"
# install gke-gcloud-auth-plugin to install kubectl and authenticate gke.
gcloud --quiet components install gke-gcloud-auth-plugin
build_and_deploy_service(){
SERVICE_NAME=$1
CLUSTER_NAME=$2
DEPLOYMENT_NAME=$3
echo "---------build and deploy $SERVICE_NAME-----------"
cd "$SERVICE_NAME" || exit
if [ $SERVICE_NAME != "car-ui" ]; then
# mvn verify sonar:sonar
# mvn verify sonar:sonar -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=nashtech
mvn clean install -s $GITHUB_WORKSPACE/settings.xml -X
#mvn clean install -X
#mvn clean install -s $HOME/.m2/settings.xml
fi
echo "---------packaging done, start docker build-----------"
docker build -f Dockerfile --tag gcr.io/"$PROJECT_ID"/"$SERVICE_NAME":"$GITHUB_SHA" .
echo "--------docker build done, docker push---------------"
docker push gcr.io/"$PROJECT_ID"/"$SERVICE_NAME":"$GITHUB_SHA"
echo "--------pushed docker image, deploy to gke cluster--------------------------"
gcloud container clusters get-credentials "$CLUSTER_NAME" --region "$REGION"
# setup kustomize
curl -sfLo kustomize https://github.com/kubernetes-sigs/kustomize/releases/download/v3.1.0/kustomize_3.1.0_linux_amd64
chmod u+x ./kustomize
# set docker image for kustomize
./kustomize edit set image gcr.io/PROJECT_ID/IMAGE:TAG=gcr.io/"$PROJECT_ID"/"$SERVICE_NAME":"$GITHUB_SHA"
# deploy through kubectl
./kustomize build . | kubectl apply -f -
kubectl rollout status deployment/"$DEPLOYMENT_NAME"
kubectl get services -o wide
echo "-------------$SERVICE_NAME deployed on $CLUSTER_NAME----------"
}
for project in $(cat projects-changes-deploy.txt)
do
:
case $project in
# case 1 build and deploy package common
"common")
echo "=========================Deploying common package=================="
cd common || exit
mvn -B package --file pom.xml
mvn deploy -X -s $GITHUB_WORKSPACE/settings.xml
#mvn deploy -X -s $HOME/.m2/settings.xml
cd ..;;
# case 2 build and deploy order-service
"order-service")
build_and_deploy_service order-service $GKE_CLUSTER orderservice
cd ..;;
# case 3 build and deploy inventory-service
"inventory-service")
build_and_deploy_service inventory-service $GKE_CLUSTER inventoryservice
cd ..;;
# case 4 build and deploy payment-service
"payment-service")
build_and_deploy_service payment-service $GKE_CLUSTER paymentservice
cd ..;;
# case 5 build and deploy shipment-service
"shipment-service")
build_and_deploy_service shipment-service $GKE_CLUSTER shipmentservice
cd ..;;
# case 6 build and deploy admin-service
"admin-service")
build_and_deploy_service admin-service $GKE_CLUSTER adminservice
cd ..;;
# case 7 build and deploy cart-service
"cart-service")
build_and_deploy_service cart-service $GKE_CLUSTER cartservice
cd ..;;
# case 8 build and deploy car-ui app
"car-ui")
build_and_deploy_service car-ui $GKE_CLUSTER carui
cd ..;;
# case 8 build and deploy car-ui app
"elastic-search")
build_and_deploy_service elastic-search $GKE_CLUSTER elasticsearch
cd ..;;
esac
done