-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloudbuild-deploy.yml
executable file
·110 lines (96 loc) · 3.66 KB
/
cloudbuild-deploy.yml
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
substitutions:
_FRONTEND_IMAGE_NAME: front-end
_FRONTEND_IMAGE_TAG: '1'
_ORDER_SERVICE_IMAGE_NAME: order-service
_ORDER_SERVICE_IMAGE_TAG: '1'
_CATALOG_SERVICE_IMAGE_NAME: catalog-service
_CATALOG_SERVICE_IMAGE_TAG: '1'
_CUSTOMER_SERVICE_IMAGE_NAME: customer-service
_CUSTOMER_SERVICE_IMAGE_TAG: '1'
# CHANGE THESE FOR PRODUCTION
# _ENV: production
# _MONGODB_FILE_PREFIX: mongodb-prod
_ENV: staging
_MONGODB_FILE_PREFIX: mongodb-stag
# TODO: Pass these in as configuration arguments. Region and Cluster name are
# subject to change and should not be hardcoded!
# See <https://github.com/GoogleCloudPlatform/cloud-builders/tree/master/kubectl>
# for more information
_CLUSTER_LOCATION: us-central1
_CLUSTER_NAME: cicd-test-dt-kube-demo-cluster
steps:
- id: 'Deploy Mongodb'
name: gcr.io/cloud-builders/kubectl
args:
- 'apply'
- -f
- $_MONGODB_FILE_PREFIX-configmaps.yml
- -f
- $_MONGODB_FILE_PREFIX-secrets.yml
- -f
- $_MONGODB_FILE_PREFIX-deploy.yml
env:
- 'CLOUDSDK_COMPUTE_REGION=$_CLUSTER_LOCATION'
- 'CLOUDSDK_CONTAINER_CLUSTER=$_CLUSTER_NAME'
- id: 'Template Kube Config'
name: gcr.io/cloud-builders/kubectl
entrypoint: 'sh'
args:
- '-c'
- |
sed -i 's/REPLACE_NAMESPACE/${_ENV}/g' front-end.yml
sed -i 's/REPLACE_NAMESPACE/${_ENV}/g' order-service.yml
sed -i 's/REPLACE_NAMESPACE/${_ENV}/g' customer-service.yml
sed -i 's/REPLACE_NAMESPACE/${_ENV}/g' catalog-service.yml
sed -i 's#REPLACE-IMAGE-NAME#gcr.io/$PROJECT_ID/${_FRONTEND_IMAGE_NAME}:${_FRONTEND_IMAGE_TAG}#g' front-end.yml
sed -i 's#REPLACE-IMAGE-NAME#gcr.io/$PROJECT_ID/${_ORDER_SERVICE_IMAGE_NAME}:${_ORDER_SERVICE_IMAGE_TAG}#g' order-service.yml
sed -i 's#REPLACE-IMAGE-NAME#gcr.io/$PROJECT_ID/${_CUSTOMER_SERVICE_IMAGE_NAME}:${_CUSTOMER_SERVICE_IMAGE_TAG}#g' customer-service.yml
sed -i 's#REPLACE-IMAGE-NAME#gcr.io/$PROJECT_ID/${_CATALOG_SERVICE_IMAGE_NAME}:${_CATALOG_SERVICE_IMAGE_TAG}#g' catalog-service.yml
cat front-end.yml
cat order-service.yml
cat customer-service.yml
cat catalog-service.yml
- id: 'Deploy Frontend'
name: gcr.io/cloud-builders/gke-deploy
args:
- run
- --cluster=$_CLUSTER_NAME
- --location=$_CLUSTER_LOCATION
- --filename=front-end.yml
- --image=gcr.io/$PROJECT_ID/$_FRONTEND_IMAGE_NAME:$_FRONTEND_IMAGE_TAG
- --namespace=$_ENV
# Without this option, deployment will fail because the output directory already exists...
- -o frontend-output
- id: 'Deploy Order Service'
name: gcr.io/cloud-builders/gke-deploy
args:
- run
- --cluster=$_CLUSTER_NAME
- --location=$_CLUSTER_LOCATION
- --filename=order-service.yml
- --image=gcr.io/$PROJECT_ID/$_ORDER_SERVICE_IMAGE_NAME:$_ORDER_SERVICE_IMAGE_TAG
- --namespace=$_ENV
# Without this option, deployment will fail because the output directory already exists...
- -o order-output
- id: 'Deploy Customer Service'
name: gcr.io/cloud-builders/gke-deploy
args:
- run
- --cluster=$_CLUSTER_NAME
- --location=$_CLUSTER_LOCATION
- --filename=customer-service.yml
- --image=gcr.io/$PROJECT_ID/$_CUSTOMER_SERVICE_IMAGE_NAME:$_CUSTOMER_SERVICE_IMAGE_TAG
- --namespace=$_ENV
# Without this option, deployment will fail because the output directory already exists...
- -o customer-output
- id: 'Deploy Catalog Service'
name: gcr.io/cloud-builders/gke-deploy
args:
- run
- --cluster=$_CLUSTER_NAME
- --location=$_CLUSTER_LOCATION
- --filename=catalog-service.yml
- --image=gcr.io/$PROJECT_ID/$_CATALOG_SERVICE_IMAGE_NAME:$_CATALOG_SERVICE_IMAGE_TAG
- --namespace=$_ENV
# Without this option, deployment will fail because the output directory already exists...
- -o catalog-output