-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcloudbuild.yaml
68 lines (60 loc) · 2.35 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
#
# The development cloud build - that deploys the image to Cloud Run for testing
#
# _IMAGE_NAME: This is a GCP resource and no underscores are allowed
# [a-z]([-a-z0-9]*[a-z0-9])? is the regex for the resource name
#
# [START cloudbuild_gen_yaml]
steps:
# [START cloudbuild_python_dependencies_yaml]
# install dependecies
# - name: python
# entrypoint: pip
# args: ["install", "-r", "requirements.txt", "--user"]
# [END cloudbuild_python_dependencies_yaml]
# - name: python
# entrypoint: python3
# args: ["-m", "unittest"]
- name: 'gcr.io/cloud-builders/docker'
entrypoint: 'bash'
args: ['-c', 'docker pull gcr.io/${PROJECT_ID}/${_ARTIFACT_REPO}/${_IMAGE_NAME}:latest || exit 0']
# [START cloudbuild_python_image_yaml]
# Docker Build
- name: 'gcr.io/cloud-builders/docker'
args: ['build',
'-t', 'gcr.io/${PROJECT_ID}/${_ARTIFACT_REPO}/${_IMAGE_NAME}:${COMMIT_SHA}',
'-t', 'gcr.io/${PROJECT_ID}/${_ARTIFACT_REPO}/${_IMAGE_NAME}:latest',
'--cache-from', 'gcr.io/${PROJECT_ID}/${_ARTIFACT_REPO}/${_IMAGE_NAME}:latest',
'-f', '${_ROOTDIR}/Dockerfile',
'${_ROOTDIR}']
# [END cloudbuild_python_image_yaml]
# [START cloudbuild_python_push_yaml]
# Docker push to Google Artifact Registry
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'gcr.io/${PROJECT_ID}/${_ARTIFACT_REPO}/${_IMAGE_NAME}:${COMMIT_SHA}']
# [END cloudbuild_python_push_yaml]
# [START cloudbuild_python_deploy_yaml]
# Deploy to Cloud Run
- name: 'google/cloud-sdk'
id: Deploy
entrypoint: gcloud
args: ['run', 'services', 'update', '${_IMAGE_NAME}',
'--image=gcr.io/${PROJECT_ID}/${_ARTIFACT_REPO}/${_IMAGE_NAME}:${COMMIT_SHA}',
'--region', '$_DEPLOY_REGION', '--platform', 'managed']
# [END cloudbuild_python_deploy_yaml]
# [START cloudbuild_python_logs_yaml]
# Save test logs to Google Cloud Storage
# artifacts:
# objects:
# location: gs://${_BUCKET_NAME}/
# paths:
# - ${SHORT_SHA}_test_log.xml
# [END cloudbuild_python_logs_yaml]
# Without this, build does not proceed
options:
logging: CLOUD_LOGGING_ONLY
# Store images in Google Artifact Registry
images:
- gcr.io/${PROJECT_ID}/${_ARTIFACT_REPO}/${_IMAGE_NAME}:${COMMIT_SHA}
- gcr.io/${PROJECT_ID}/${_ARTIFACT_REPO}/${_IMAGE_NAME}:latest
# [END cloudbuild_gen_yaml]