This repository has been archived by the owner on Oct 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 86
/
cloudbuild.yaml
96 lines (85 loc) · 2.68 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
---
substitutions:
_NAMESPACE: experimental
_IMAGE_NAME: dshop-backend
steps:
- id: 'Configure network name'
name: 'gcr.io/cloud-builders/docker'
entrypoint: 'sh'
args:
- '-c'
- |
# Write network to file for future usage
case "$BRANCH_NAME" in
stable)
echo "mainnet" > .network
;;
*)
echo "rinkeby" > .network
;;
esac
- id: 'Create unique build tag'
name: 'gcr.io/cloud-builders/docker'
entrypoint: '/bin/bash'
args:
- '-c'
- 'date +%Y%m%d%H%M%s > .tag'
- id: 'Build docker image'
name: 'gcr.io/cloud-builders/docker'
entrypoint: '/bin/bash'
args:
- '-c'
- |
docker build \
-f ./devops/Dockerfile \
-t "gcr.io/$PROJECT_ID/${_NAMESPACE}/${_IMAGE_NAME}:$(cat .tag)" \
--build-arg SENTRY_DSN=${_SENTRY_DSN} \
--build-arg ENVIRONMENT=${_ENVIRONMENT} \
$(pwd)
- id: 'Push the image to GCR'
name: 'gcr.io/cloud-builders/docker'
entrypoint: '/bin/bash'
args:
- '-c'
- |
docker push \
gcr.io/$PROJECT_ID/${_NAMESPACE}/${_IMAGE_NAME}:$(cat .tag)
- id: 'Tag the image'
name: 'gcr.io/cloud-builders/gcloud'
entrypoint: '/bin/bash'
args:
- '-c'
- |
gcloud container images add-tag \
"gcr.io/$PROJECT_ID/${_NAMESPACE}/${_IMAGE_NAME}:$(cat .tag)" \
"gcr.io/$PROJECT_ID/${_NAMESPACE}/${_IMAGE_NAME}:latest" \
--quiet
if [[ "$BRANCH_NAME" == "stable" ]]; then
gcloud container images add-tag \
"gcr.io/$PROJECT_ID/${_NAMESPACE}/${_IMAGE_NAME}:$(cat .tag)" \
"gcr.io/$PROJECT_ID/${_NAMESPACE}/${_IMAGE_NAME}:mainnet" \
--quiet
fi
- id: 'Update the StatefulSet'
name: 'gcr.io/cloud-builders/kubectl'
env:
- 'CLOUDSDK_COMPUTE_ZONE=us-west1-a'
- 'CLOUDSDK_CONTAINER_CLUSTER=origin'
entrypoint: '/bin/bash'
args:
- '-c'
- |
gcloud container clusters get-credentials "$$CLOUDSDK_CONTAINER_CLUSTER" \
--project "$(gcloud config get-value core/project)" \
--zone "$(gcloud config get-value compute/zone)"
export STS_NAME="${_NAMESPACE}-${_IMAGE_NAME}-$(cat .network)"
export PATCH_JSON="[{ \
\"op\": \"replace\", \
\"path\": \"/spec/template/spec/containers/0/image\", \
\"value\": \"gcr.io/$PROJECT_ID/${_NAMESPACE}/${_IMAGE_NAME}:$(cat .tag)\" \
}]"
kubectl -n ${_NAMESPACE} patch statefulset $$STS_NAME --type='json' \
-p="$$PATCH_JSON"
timeout: '3600s'
options:
machineType: 'N1_HIGHCPU_32'