forked from dehypnosis/moleculer-iam
-
Notifications
You must be signed in to change notification settings - Fork 3
/
cloudbuild.yaml
110 lines (99 loc) · 3.92 KB
/
cloudbuild.yaml
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
#
# Mandatory variables to be injected:
# SHORT_SHA, BRANCH_NAME
#
# Manual trigger example:
# gcloud builds submit . --substitutions="BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD),SHORT_SHA=$(git rev-parse --short HEAD)"
#
timeout: '1200s'
substitutions:
# Docker image to build
_IMAGE: 'gcr.io/qmit-pro/iam'
# K8S resource and container name to be updated
_IMAGE_TARGET: 'deployment/iam server'
# K8S namespace of the resource
_NAMESPACE: 'util'
# GKE cluster name and zone/region for development stage
_CLUSTER_DEV: 'dev'
_ZONE_DEV: 'asia-northeast1-a'
# GKE cluster name and zone/region for production stage
_CLUSTER_PROD: 'prod'
_ZONE_PROD: 'asia-northeast1-a'
steps:
- id: '[*] build temporary image'
name: 'gcr.io/cloud-builders/docker'
entrypoint: 'bash'
args:
- '-c'
- |
(docker pull ${_IMAGE}:latest || true) \
&& docker build . -f ./Dockerfile -t ${_IMAGE}:ci-${SHORT_SHA} --cache-from ${_IMAGE}:latest \
&& docker push ${_IMAGE}:ci-${SHORT_SHA} \
&& echo "DONE: ${_IMAGE}:ci-${SHORT_SHA} pushed"
- id: '[*] do unit/integration test in dev cluster'
name: 'gcr.io/cloud-builders/kubectl'
entrypoint: 'bash'
env:
- 'CLOUDSDK_COMPUTE_ZONE=$_ZONE_DEV'
- 'CLOUDSDK_CONTAINER_CLUSTER=$_CLUSTER_DEV'
args:
- '-c'
- |
gcloud container clusters get-credentials --zone $$CLOUDSDK_COMPUTE_ZONE $$CLOUDSDK_CONTAINER_CLUSTER \
&& /builder/kubectl.bash -n ${_NAMESPACE} run \
test-${BUILD_ID} \
--labels=test=true \
--generator=run-pod/v1 \
--image ${_IMAGE}:ci-${SHORT_SHA} \
--rm -i --restart=Never --attach --pod-running-timeout=10m \
-- yarn test-with-examples
- id: '[develop] push the temporary image with :latest tag'
name: 'gcr.io/cloud-builders/docker'
entrypoint: 'bash'
args:
- '-c'
- |
([ "$BRANCH_NAME" != "develop" ] && echo "SKIP: not a commit of develop branch") || ( \
docker tag ${_IMAGE}:ci-${SHORT_SHA} ${_IMAGE}:latest \
&& docker push ${_IMAGE}:latest \
&& echo "DONE: ${_IMAGE}:lastest pushed" \
)
- id: '[develop] deploy latest image to dev cluster'
name: 'gcr.io/cloud-builders/kubectl'
entrypoint: 'bash'
env:
- 'CLOUDSDK_COMPUTE_ZONE=$_ZONE_DEV'
- 'CLOUDSDK_CONTAINER_CLUSTER=$_CLUSTER_DEV'
args:
- '-c'
- |
([ "$BRANCH_NAME" != "develop" ] && echo "SKIP: not a commit of develop branch") || ( \
gcloud container clusters get-credentials --zone $$CLOUDSDK_COMPUTE_ZONE $$CLOUDSDK_CONTAINER_CLUSTER \
&& /builder/kubectl.bash -n ${_NAMESPACE} set image ${_IMAGE_TARGET}=${_IMAGE}:ci-${SHORT_SHA} \
&& echo "DONE: ${_IMAGE}:ci-${SHORT_SHA} (latest) deployed in dev cluster"
)
- id: '[master] push release image'
name: 'gcr.io/cloud-builders/docker'
entrypoint: 'bash'
args:
- '-c'
- |
([ "$BRANCH_NAME" != "master" ] && echo "SKIP: not a commit of master branch") || ( \
docker tag ${_IMAGE}:ci-${SHORT_SHA} ${_IMAGE}:release-${SHORT_SHA} \
&& docker push ${_IMAGE}:release-${SHORT_SHA} \
&& echo "DONE: ${_IMAGE}:release-${SHORT_SHA} pushed" \
)
- id: '[master] deploy latest release image in prod cluster'
name: 'gcr.io/cloud-builders/kubectl'
entrypoint: 'bash'
env:
- 'CLOUDSDK_COMPUTE_ZONE=$_ZONE_PROD'
- 'CLOUDSDK_CONTAINER_CLUSTER=$_CLUSTER_PROD'
args:
- '-c'
- |
([ "$BRANCH_NAME" != "master" ] && echo "SKIP: not a commit of master branch") || ( \
gcloud container clusters get-credentials --zone $$CLOUDSDK_COMPUTE_ZONE $$CLOUDSDK_CONTAINER_CLUSTER \
&& /builder/kubectl.bash -n ${_NAMESPACE} set image ${_IMAGE_TARGET}=${_IMAGE}:release-${SHORT_SHA} \
&& echo "DONE: ${_IMAGE}:release-${SHORT_SHA} deployed in prod cluster" \
)