-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·127 lines (101 loc) · 5.06 KB
/
install.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
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
#!/usr/bin/env bash
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
PARENT_DIR=$(pwd)
# Switch to Terraform directory
cd ${PARENT_DIR}/01_-_infrastructure
# Initialise Terraform configuration
terraform init -reconfigure -upgrade
# Apply Terraform configuration
terraform apply -auto-approve
# Get the kubernetes credentials
$(terraform output -json | jq -r .cluster_one_credentials.value)
$(terraform output -json | jq -r .cluster_two_credentials.value)
# Source environment variables
cd ${PARENT_DIR}
source env.sh
# Rename context
kubectl config delete-context mgw-cluster-one || true
kubectl config delete-context mgw-cluster-two || true
kubectl config rename-context gke_${PROJECT_ID}_${LOCATION_ONE}_${CLUSTER_ONE_NAME} mgw-cluster-one
kubectl config rename-context gke_${PROJECT_ID}_${LOCATION_TWO}_${CLUSTER_TWO_NAME} mgw-cluster-two
kubectl config use-context mgw-cluster-one
cd ${PARENT_DIR}/02_-_app
make build/docker
# Create Kustomize configuration
cd ${PARENT_DIR}/03_-_kubernetes/app
# Update configuration files so they contain the updated fields
cp overlays/accounting/kustomization.yaml.orig overlays/accounting/kustomization.yaml
cp overlays/consumer/kustomization.yaml.orig overlays/consumer/kustomization.yaml
sed -i '' "s|IMAGE_NAME|${IMAGE_NAME}|g" ./overlays/accounting/kustomization.yaml
sed -i '' "s|IMAGE_TAG|${IMAGE_TAG}|g" ./overlays/accounting/kustomization.yaml
sed -i '' "s|SERVICE_ACCOUNT|${ACCOUNTING_APP_IDENTITY}|g" ./overlays/accounting/kustomization.yaml
sed -i '' "s|IMAGE_NAME|${IMAGE_NAME}|g" ./overlays/consumer/kustomization.yaml
sed -i '' "s|IMAGE_TAG|${IMAGE_TAG}|g" ./overlays/consumer/kustomization.yaml
sed -i '' "s|SERVICE_ACCOUNT|${ACCOUNTING_APP_IDENTITY}|g" ./overlays/consumer/kustomization.yaml
# Deploy resources to both clusters
kubectl apply -k ./ --context mgw-cluster-one
kubectl apply -k ./ --context mgw-cluster-two
# Deploy Gateway
cd ${PARENT_DIR}/03_-_kubernetes/gateway
cp public-app-route-accounting.yaml.orig public-app-route-accounting.yaml
cp public-app-route-consumer.yaml.orig public-app-route-consumer.yaml
sed -i '' "s|DOMAIN|accounting.${DOMAIN}|g" ./public-app-route-accounting.yaml
sed -i '' "s|DOMAIN|consumer.${DOMAIN}|g" ./public-app-route-consumer.yaml
kubectl apply -f ./ --context mgw-cluster-one
echo "Retrieving Gateway address ..."
GATEWAY_ADDRESS=$(kubectl get gateways.gateway.networking.k8s.io external-https -o=jsonpath="{.status.addresses[0].value}" -n gateway-infra --context mgw-cluster-one)
while [ -z "$GATEWAY_ADDRESS" ]; do
GATEWAY_ADDRESS=$(kubectl get gateways.gateway.networking.k8s.io external-https -o=jsonpath="{.status.addresses[0].value}" -n gateway-infra --context mgw-cluster-one)
done
echo "Gateway address provisioned: ${GATEWAY_ADDRESS}"
# Patching the environment variables on cluster one
kubectl -n accounting set env deployment/acc-demo-app \
AUDIENCE=accounting \
NAMESPACE=accounting \
CLUSTER=${CLUSTER_ONE_NAME} \
REGION=${LOCATION_ONE} \
--context mgw-cluster-one
kubectl -n consumer set env deployment/cons-demo-app \
AUDIENCE=consumer \
NAMESPACE=consumer \
CLUSTER=${CLUSTER_ONE_NAME} \
REGION=${LOCATION_ONE} \
--context mgw-cluster-one
# Patching the environment variables on cluster two
kubectl -n accounting set env deployment/acc-demo-app \
AUDIENCE=accounting \
NAMESPACE=accounting \
CLUSTER=${CLUSTER_TWO_NAME} \
REGION=${LOCATION_TWO} \
--context mgw-cluster-two
kubectl -n consumer set env deployment/cons-demo-app \
AUDIENCE=consumer \
NAMESPACE=consumer \
CLUSTER=${CLUSTER_TWO_NAME} \
REGION=${LOCATION_TWO} \
--context mgw-cluster-two
# Manual config
echo "##############################################################################################"
echo "Please update your DNS records with the following details:"
echo "- Add a CNAME record for *.${DOMAIN}, data: ${CNAME_RECORD}"
echo "- Add an A-record for accounting.${DOMAIN}, data: ${GATEWAY_ADDRESS}"
echo "- Add an A-record for consumer.${DOMAIN}, data: ${GATEWAY_ADDRESS}"
echo "##############################################################################################"
echo "Once the DNS records have been created and the certificate shows up as 'provisioned', you can open both endpoints in a browser"
echo "- https://accounting.${DOMAIN}/v1/appinfo"
echo "- https://consumer.${DOMAIN}/v1/appinfo"
echo "##############################################################################################"
echo "You can check the status of the certificate by running the following command in the 01_-_infrastructure-folder:"
echo "\$(terraform output -json | jq -r .certificate_status.value)"