forked from GoogleCloudPlatform/microservices-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudbuild.yaml
More file actions
105 lines (99 loc) · 3.94 KB
/
cloudbuild.yaml
File metadata and controls
105 lines (99 loc) · 3.94 KB
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
96
97
98
99
100
101
102
103
104
105
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This configuration file is used to build and deploy the app into a
# GKE cluster using Google Cloud Build and Google Cloud Deploy.
#
# PREREQUISITES:
# - Cloud Build service account must have roles: "Cloud Deploy Releaser", "Service Account User"
# - Compute service account must have roles: "Kubernetes Engine Developer", "Cloud Deploy Runner"
# USAGE:
# The release ID must be incremented/unique for each run:
# Example invocation:
# `gcloud builds submit --config=cloudbuild_cd.yaml --substitutions=_REL_ID=UNIQUE.`
# where UNIQUE is different for each release
# https://cloud.google.com/deploy/docs/integrating-ci?hl=ko#an_example_configuration_using_skaffold
# [START cloudbuild_microservice_demo_cloudbuild]
steps:
# - name: gcr.io/cloud-builders/gsutil
# id: download-skaffold-cache
# entrypoint: 'bash'
# args:
# - '-c'
# - 'gsutil cp -c ${_CACHE_URI} /workspace/cache || true'
- name: gcr.io/k8s-skaffold/skaffold
id: build-and-push-images
args:
- skaffold
- build
- '--cache-artifacts=false'
- '--interactive=false'
- '--default-repo=${_DEFAUILT_REPOSITORY}'
# - '--cache-file=/workspace/$_CACHE' # set _CACHE to anything other than "cache" e.g. "no-cache" to reset skaffold cache
- '--file-output=/workspace/artifacts.json'
- name: gcr.io/google.com/cloudsdktool/cloud-sdk
id: show-artifacts-json
entrypoint: 'bash'
args:
- '-c'
- 'cat /workspace/artifacts.json'
# - name: gcr.io/google.com/cloudsdktool/cloud-sdk
# id: upload-skaffold-cache
# args:
# - 'gsutil'
# - 'cp'
# - '/workspace/$_CACHE'
# - '${_CACHE_URI}'
##################
#- name: gcr.io/k8s-skaffold/skaffold:v2.8.0 # python set up should be baked into a custom builder image to speed up build times
# id: run-tests
# script: |
# #!/bin/bash
# apt-get update
# apt-get -y install python3-venv
# python3 -m venv $HOME/venv-python-tests
# . $HOME/venv-python-tests/bin/activate
# pip install --upgrade pip
# pip install pylint
# skaffold test --build-artifacts=/workspace/artifacts.json --module=$SERVICE --assume-yes
# env:
# - 'TEAM=$_TEAM'
# - 'SERVICE=$_SERVICE'
- name: gcr.io/google.com/cloudsdktool/cloud-sdk
id: trigger-release
args:
- 'gcloud'
- 'deploy'
- 'releases'
- 'create'
- 'rel-${SHORT_SHA}'
- '--delivery-pipeline=${_DELIVERY_PIPELINE_NAME}'
- '--build-artifacts=/workspace/artifacts.json'
- '--region=${_REGION}'
- '--annotations=commitId=${REVISION_ID}'
# - '--gcs-source-staging-dir=$_SOURCE_STAGING_BUCKET/$SHORT_SHA'
# Add more power, and more time, for heavy Skaffold build
timeout: '3600s'
# https://cloud.google.com/build/docs/securing-builds/configure-user-specified-service-accounts?hl=ko#execute_a_build_using_a_config_file
serviceAccount: 'projects/${PROJECT_ID}/serviceAccounts/ob-build-sa@kiwonlee-demo-ob.iam.gserviceaccount.com'
options:
machineType: 'E2_HIGHCPU_8'
logging: CLOUD_LOGGING_ONLY #https://cloud.google.com/build/docs/securing-builds/configure-user-specified-service-accounts?hl=ko#execute_a_build_using_a_config_file
# workerPool: 'projects/${PROJECT_ID}/locations/${_REGION}/workerPools/microservices-pp'
substitutions:
_DELIVERY_PIPELINE_NAME: ob-pipeline
_DEFAUILT_REPOSITORY: us-central1-docker.pkg.dev/${PROJECT_ID}/docker-repo
_REGION: us-central1
_CACHE_URI: gs://skaffold-cache/cache
_CACHE: cache
# [END cloudbuild_microservice_demo_cloudbuild]