-
Notifications
You must be signed in to change notification settings - Fork 11
/
container-build.yaml
204 lines (187 loc) · 7.35 KB
/
container-build.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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# 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.
steps:
###########################################################
# Step 1: Retrieve the cached .m2 directory from GCS
###########################################################
- name: 'gcr.io/cloud-builders/gsutil'
id: fetch-mvn-cache
args:
- '-m'
- 'rsync'
- '-r'
- 'gs://${_BUCKET}/cache/.m2'
- '/cache/.m2'
volumes:
- path: '/cache/.m2'
name: 'm2_cache'
###########################################################
# Step 2: Download submodules
###########################################################
- name: gcr.io/cloud-builders/git
waitFor:
- '-'
id: update-submodules
args: ['submodule', 'update', '--init']
###########################################################
# Step 3: Retag cloned git repo hash
###########################################################
- name: gcr.io/cloud-builders/git
waitFor:
- '-'
id: recreate-tag
args: ['tag', '$_TAG']
###########################################################
# Step 4: Rebuild Dataflow Flex Template base image
###########################################################
- name: gcr.io/cloud-builders/docker
id: rebuild-dataflow-flex-base-image
waitFor:
- '-'
args:
- 'build'
- '-t'
- 'gcr.io/enpa-public-assets/distroless-flex-template-launcher:11'
- 'df-flex-template-base-image'
###########################################################
# Step 5: Publish Dataflow Flex Template base image
###########################################################
- name: gcr.io/cloud-builders/docker
id: push-dataflow-flex-base-image
waitFor:
- rebuild-dataflow-flex-base-image
args:
- 'push'
- 'gcr.io/enpa-public-assets/distroless-flex-template-launcher:11'
###########################################################
# Step 6: Package and Deploy to Github maven repo
###########################################################
- name: gcr.io/cloud-devrel-public-resources/java11
id: package-deploy-mvn-registry
waitFor:
- update-submodules
- recreate-tag
- fetch-mvn-cache
entrypoint: bash
args:
- '-c'
- 'source ci/common.sh && retry_with_backoff 3 10 ./mvnw -U -s mvn-settings.xml -DskipTests -Drevision=$(${_VERSION}) deploy'
env:
- 'PROJECT=enpa-integration-testing'
- 'KEY_RESOURCE_NAME=projects/enpa-integration-testing/locations/global/keyRings/appa-signature-key/cryptoKeys/appa-signature-key/cryptoKeyVersions/1'
secretEnv: ['GITHUB_TOKEN']
###########################################################
# Step 7: Build and Publish Public Ingestion Container Image
###########################################################
- name: gcr.io/cloud-devrel-public-resources/java11
id: public-ingestion-container-build
waitFor:
- update-submodules
- recreate-tag
- fetch-mvn-cache
- push-dataflow-flex-base-image
entrypoint: bash
args:
- '-c'
- 'source ci/common.sh && retry_with_backoff 3 10 ./mvnw -DskipTests -Pingestion-container-build -Dcontainer-version=$(${_VERSION}) -Dcontainer_registry_tag_prefix="gcr.io/enpa-public-assets" -Drevision=$(${_VERSION}) package'
###########################################################
# Step 8: Build and Publish Public Deletion Container Image
###########################################################
- name: gcr.io/cloud-devrel-public-resources/java11
id: public-deletion-container-build
waitFor:
- update-submodules
- recreate-tag
- fetch-mvn-cache
- push-dataflow-flex-base-image
entrypoint: bash
args:
- '-c'
- 'source ci/common.sh && retry_with_backoff 3 10 ./mvnw -DskipTests -Pdeletion-container-build -Dcontainer-version=$(${_VERSION}) -Dcontainer_registry_tag_prefix="gcr.io/enpa-public-assets" -Drevision=$(${_VERSION}) package'
###########################################################
# Step 9: Build and Publish Ingestion Container Image
###########################################################
- name: gcr.io/cloud-devrel-public-resources/java11
id: ingestion-container-build
waitFor:
- update-submodules
- recreate-tag
- fetch-mvn-cache
- push-dataflow-flex-base-image
entrypoint: bash
args:
- '-c'
- 'source ci/common.sh && retry_with_backoff 3 10 ./mvnw -s mvn-settings.xml -DskipTests -Pingestion-container-build,attestation -Dcontainer-version=$(${_VERSION}) -Dcontainer_registry_tag_prefix="gcr.io/enpa-infra" -Drevision=$(${_VERSION}) package'
secretEnv: ['GITHUB_TOKEN']
###########################################################
# Step 10: Build and Publish Deletion Container Image
###########################################################
- name: gcr.io/cloud-devrel-public-resources/java11
id: deletion-container-build
waitFor:
- update-submodules
- recreate-tag
- fetch-mvn-cache
- push-dataflow-flex-base-image
entrypoint: bash
args:
- '-c'
- 'source ci/common.sh && retry_with_backoff 3 10 ./mvnw -s mvn-settings.xml -DskipTests -Pdeletion-container-build,attestation -Dcontainer-version=$(${_VERSION}) -Dcontainer_registry_tag_prefix="gcr.io/enpa-infra" -Drevision=$(${_VERSION}) package'
secretEnv: ['GITHUB_TOKEN']
###########################################################
# Step 11: Generate Templates for Dataflow jobs and Firebase
###########################################################
- name: gcr.io/google.com/cloudsdktool/cloud-sdk:alpine
id: flex-template-generator-and-uploader
waitFor:
- recreate-tag
args:
- "./ci/generate-templates.sh"
env:
- PROJECT_ID=$PROJECT_ID
###########################################################
# Step 12: Update cached .m2 directory on GCS with any
# additional dependencies downloaded during the
# build.
###########################################################
- name: gcr.io/cloud-builders/gsutil
id: sync-mvn-cache
waitFor:
- ingestion-container-build
- deletion-container-build
args:
- '-m'
- 'rsync'
- '-r'
- '/cache/.m2'
- 'gs://${_BUCKET}/cache/.m2/'
volumes:
- path: '/cache/.m2'
name: 'm2_cache'
images:
- 'gcr.io/enpa-public-assets/distroless-flex-template-launcher:11'
substitutions:
# Default value
_BUCKET: 'enpa-infra'
_DEFAULT_TAG: '${SHORT_SHA}-SNAPSHOT'
_TAG: ${TAG_NAME:-$_DEFAULT_TAG} #default value will be SHORT_SHA-SNAPSHOT
_VERSION: 'git describe --tags --always --dirty=-dirty'
secrets:
- kmsKeyName: projects/enpa-infra/locations/global/keyRings/cloudbuild-keyring/cryptoKeys/cloudbuild
secretEnv:
GITHUB_TOKEN: 'CiQAzNSb40phOg8+Rtn21yuiJuqJA3CKm5YWgigMwpA5lsM42NgSUQA/9gK92tb89IansK/cTpYuAJpf9PUZ7Lvse94FqFmk/mVULLISsoNr6+39npTZAG2el7cRQ22LozB5lwE9dZGywalT7xHxs46+nywy/ix8Qg=='
options:
# Use higher CPU machines so the caching and build steps are faster.
machineType: 'N1_HIGHCPU_32'
serviceAccount: 'projects/enpa-infra/serviceAccounts/development-integration-tests@enpa-integration-testing.iam.gserviceaccount.com'