-
Notifications
You must be signed in to change notification settings - Fork 154
/
cloudbuild.yaml
78 lines (70 loc) · 2.62 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
steps:
- name: 'gcr.io/cloud-builders/docker'
id: 'pull image cache'
entrypoint: 'bash'
args:
- -c
- |
docker pull gcr.io/$PROJECT_ID/alpaca-py:deps || true
- name: 'gcr.io/cloud-builders/docker'
id: 'deps build'
args: [
'build',
'--target', 'deps',
'-t', 'gcr.io/$PROJECT_ID/alpaca-py:deps',
'--cache-from', 'gcr.io/$PROJECT_ID/alpaca-py:deps',
'.'
]
- name: 'gcr.io/cloud-builders/docker'
id: 'build image'
args: [
'build',
'-t', 'gcr.io/$PROJECT_ID/alpaca-py:latest',
'--cache-from', 'gcr.io/$PROJECT_ID/alpaca-py:deps',
'.'
]
- name: 'gcr.io/cloud-builders/docker'
id: 'push images'
entrypoint: 'sh'
args:
- -c
- |
set -eu
if [ "$TAG_NAME" = "" ] && [ "$BRANCH_NAME" = "master" ]; then
docker tag gcr.io/$PROJECT_ID/alpaca-py:latest gcr.io/$PROJECT_ID/alpaca-py:${BRANCH_NAME}-latest
docker push gcr.io/$PROJECT_ID/alpaca-py:${BRANCH_NAME}-latest
fi
if [ "$TAG_NAME" != "" ]; then
docker tag gcr.io/$PROJECT_ID/alpaca-py:latest gcr.io/$PROJECT_ID/alpaca-py:$TAG_NAME
docker push gcr.io/$PROJECT_ID/alpaca-py:$TAG_NAME
else
docker push gcr.io/$PROJECT_ID/alpaca-py:deps
docker push gcr.io/$PROJECT_ID/alpaca-py:latest
fi
- name: 'gcr.io/cloud-builders/kubectl'
id: 'deploy to staging or master as appropriate'
entrypoint: 'sh'
secretEnv: ['SA_TOKEN_STAGING','SA_TOKEN_MASTER']
args:
- -c
- |
set -eu
if [ "$TAG_NAME" = "" ] && [ "$BRANCH_NAME" = "master" ] ; then
SA_TOKEN="$$SA_TOKEN_STAGING"
elif [ "$TAG_NAME" != "" ]; then
SA_TOKEN="$$SA_TOKEN_MASTER"
fi
if [ "$_KUBE_API_SERVER" != "" -a "$_KUBE_CA_CRT" != "" -a "$_KUBE_NAMESPACE" != "" -a "$_KUBE_DEPLOYMENT" != "" -a "$$SA_TOKEN" != "" ]; then
echo "$_KUBE_CA_CRT" > /tmp/ca.crt
if [ "$TAG_NAME" != "" ]; then
kubectl --certificate-authority /tmp/ca.crt --server "$_KUBE_API_SERVER" --namespace "$_KUBE_NAMESPACE" --token "$$SA_TOKEN" set image deploy "$_KUBE_DEPLOYMENT" nginx=gcr.io/$PROJECT_ID/alpaca-py:$TAG_NAME
fi
kubectl --certificate-authority /tmp/ca.crt --server "$_KUBE_API_SERVER" --namespace "$_KUBE_NAMESPACE" --token "$$SA_TOKEN" rollout restart deploy "$_KUBE_DEPLOYMENT"
fi
availableSecrets:
secretManager:
- versionName: projects/$PROJECT_ID/secrets/alpaca-py-staging-cloudbuild-kubernetes-sa-token/versions/latest
env: 'SA_TOKEN_STAGING'
- versionName: projects/$PROJECT_ID/secrets/alpaca-py-prod-cloudbuild-kubernetes-sa-token/versions/latest
env: 'SA_TOKEN_MASTER'
timeout: 1200s