-
Notifications
You must be signed in to change notification settings - Fork 4
/
cloudbuild.yaml
68 lines (68 loc) ยท 1.9 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
steps:
# git checkout
- name: "gcr.io/cloud-builders/git"
secretEnv: ["SSH_KEY"]
entrypoint: "bash"
args:
- -c
- |
git config --global \
url."ssh://[email protected]".insteadOf "https://github.com"
echo "$$SSH_KEY" >> /root/.ssh/id_rsa
chmod 400 /root/.ssh/id_rsa
echo ${_KNOWN_HOST_GITHUB} >> /root/.ssh/known_hosts
volumes:
- name: "ssh"
path: /root/.ssh
id: Git Checkout
# update submodules
- name: gcr.io/cloud-builders/git
args: ["submodule", "update", "--init", "--recursive"]
volumes:
- name: "ssh"
path: /root/.ssh
id: Update Submodules
# build application
- name: gradle
args: ["./gradlew", "clean", "build"]
id: Build Application
# build image
- name: gcr.io/cloud-builders/docker
args:
- build
- "--build-arg"
- "STAGE=$_STAGE"
- "--no-cache"
- "-t"
- "$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA"
- .
- "-f"
- Dockerfile
id: Build
# push images
- name: gcr.io/cloud-builders/docker
args:
- push
- "$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA"
id: Push
# deploy service
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk:slim"
args:
- run
- services
- update
- $_SERVICE_NAME
- "--platform=managed"
- "--image=$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA"
- >-
--labels=managed-by=gcp-cloud-build-deploy-cloud-run,commit-sha=$COMMIT_SHA,gcb-build-id=$BUILD_ID,gcb-trigger-id=$_TRIGGER_ID,$_LABELS
- "--region=$_DEPLOY_REGION"
- "--quiet"
id: Deploy
entrypoint: gcloud
images:
- '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA'
availableSecrets:
secretManager:
- versionName: projects/$PROJECT_ID/secrets/github_ssh/versions/latest
env: "SSH_KEY"