-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudbuild.yaml
69 lines (57 loc) · 2.41 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
# This cloudbuild file is used by Google Cloud Build to deploy a container to Google Cloud Run.
# It can be used in many contexts, and should work as long as there is a build.Dockerfile in the root of the project.
# It will use this Dockerfile to build a container image, save the docker build steps to a cache, save the final image to
# Google cloud container registry, and push the build up to Google Cloud run
# Substitutions are used to make this dynamic. Their vars should be configured in the Cloud Build Trigger.
# Pass in the following substitution vars:
# - _PACKAGE_NAME
# The name of the package that this trigger is to deploy. This will be the name of the
# final Cloud Run instance. Eg: 'api-servic' or 'user-front-end' or 'admin-dashboard'
#######################################################################################
steps:
# pull build cache from the container repo if it exists
- name: gcr.io/cloud-builders/docker
id: Pulling build cache
entrypoint: "bash"
args:
- "-c"
- |
docker pull gcr.io/$PROJECT_ID/${_PACKAGE_NAME}:latest || exit 0
# Build the container image for the package using the Dockerfile in the root
- name: gcr.io/cloud-builders/docker
id: Build container image using dockerfile
entrypoint: "bash"
args:
[
"-c",
"docker build -f build.Dockerfile -t gcr.io/$PROJECT_ID/${_PACKAGE_NAME}:latest --cache-from gcr.io/$PROJECT_ID/${_PACKAGE_NAME}:latest --build-arg NPM_TOKEN=$$NPM_TOKEN .",
]
# secretEnv: ['NPM_TOKEN']
# Push the container image to Container Registry
- name: "gcr.io/cloud-builders/docker"
args: ["push", "gcr.io/$PROJECT_ID/${_PACKAGE_NAME}:latest"]
# Deploy container image to Cloud Run
- name: "gcr.io/cloud-builders/gcloud"
args:
[
"beta",
"run",
"deploy",
"${_PACKAGE_NAME}",
"--image",
"gcr.io/$PROJECT_ID/${_PACKAGE_NAME}",
"--region",
"europe-west1",
"--platform",
"managed",
"--quiet",
]
# The available secrets (from Google Secrets Manager) that are used in the build
# availableSecrets:
# secretManager:
# - versionName: projects/$PROJECT_ID/secrets/GH_HY_NPM_TOKEN/versions/latest
# env: NPM_TOKEN
# sets the timeout time for the build
timeout: 1200s
# Lists the images used in the build from the container registry
images: ["gcr.io/$PROJECT_ID/${_PACKAGE_NAME}:latest"]