-
Notifications
You must be signed in to change notification settings - Fork 8
/
pipeline.yml
286 lines (265 loc) · 10.6 KB
/
pipeline.yml
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
parameters:
- name: package_name
displayName: package_name
type: string
default: ""
- name: tag
displayName: tag
type: string
default: ""
- name: revision
displayName: revision
type: string
default: ""
- name: specs
displayName: Package Specs
type: object
default: []
- name: build_id
displayName: build id
type: string
default: "__not_supplied"
- name: prod_storage_account_name
displayName: Prod Storage Account Name
type: string
default: mobyreleases
- name: index_container
displayName: Index Container
type: string
default: index
name: ${{ replace(parameters.build_id, '__not_supplied', '$(Date:yyyyMMdd).$(Rev:r)') }}-${{ parameters.package_name }}-${{ parameters.tag }}-${{ parameters.revision }}.run$(Rev:r)
variables:
amd.pool: staging-pool-amd64-mariner-2
package.name: "${{ parameters.package_name }}"
build.tag: "${{ parameters.tag }}"
build.revision: "${{ parameters.revision }}"
stages:
- stage: Validate
jobs:
- job: ValidateDataFormat
variables:
specs.input.dir: "$(Pipeline.Workspace)/input"
pool: $(amd.pool)
timeoutInMinutes: 5
steps:
- bash: |
set -exu
specs_basename="$(go run ./cmd/hash --project="$PACKAGE_NAME" --tag="$BUILD_TAG" --revision="$BUILD_REVISION")"
specs_file="${SPECS_INPUT_DIR}/${specs_basename}"
mkdir -p "$(dirname "$specs_file")"
cat > "$specs_file" <<EOF
${{ convertToJson(parameters.specs) }}
EOF
cat "$specs_file"
go run ./cmd/validate/ --project="$PACKAGE_NAME" --tag="$BUILD_TAG" --revision="$BUILD_REVISION" < "$specs_file"
displayName: Validate Input Data Format
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: "$(specs.input.dir)"
artifactName: input
- stage: Build
jobs:
- ${{ each spec in parameters.specs }}:
- job: "Build_\
${{ replace(spec.package, '-', '_') }}_\
${{ spec.distro }}_\
${{ replace(spec.arch, '/', '') }}_\
${{ replace(spec.tag, '.', '_') }}"
variables:
bundle.dir: "$(Pipeline.Workspace)/bundles"
spec.dir: "$(Pipeline.Workspace)/specs"
distro: "${{ spec.distro }}"
arch: "${{ spec.arch }}"
${{ if contains(spec.arch, 'arm') }}:
build.pool: staging-pool-arm64-mariner-2
${{ else }}:
build.pool: staging-pool-amd64-mariner-2
pool: $(build.pool)
timeoutInMinutes: 240
steps:
- bash: |
set -exu
mkdir -p "$SPEC_DIR"
filename="$(echo '${{ convertToJson(spec) }}' | go run ./cmd/path basename --spec-file=/dev/stdin)"
spec_file="${SPEC_DIR}/${filename}"
echo '${{ convertToJson(spec) }}' | tee "$spec_file"
go run . --build-spec="$spec_file" --output="$BUNDLE_DIR"
name: buildPackage
displayName: Build package
- task: AzureArtifacts.manifest-generator-task.manifest-generator-task.ManifestGeneratorTask@0
displayName: Generate SBOM
inputs:
BuildDropPath: "$(bundle.dir)/${{ parameters.distro }}"
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: "$(bundle.dir)"
artifactName: bundles
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: "$(spec.dir)"
artifactName: specs
- stage: Test
dependsOn: ["Build"]
jobs:
- ${{ each spec in parameters.specs }}:
- job: "Test_\
${{ replace(spec.package, '-', '_') }}_\
${{ spec.distro }}_\
${{ replace(spec.arch, '/', '') }}_\
${{ replace(spec.tag, '.', '_') }}"
condition: ne('${{ spec.distro }}', 'windows')
pool: $(build.pool)
variables:
bundle.dir: "$(Pipeline.Workspace)/bundles"
spec.dir: "$(Pipeline.Workspace)/specs"
distro: "${{ spec.distro }}"
arch: "${{ spec.arch }}"
results.dir: "$(Pipeline.Workspace)/testresults"
artifact.pattern: "**/${{ spec.distro }}/linux_${{ replace(spec.arch, '/', '_') }}/*@(-spec.json|.deb|.rpm)"
${{ if contains(spec.arch, 'arm') }}:
build.pool: staging-pool-arm64-mariner-2
${{ else }}:
build.pool: staging-pool-amd64-mariner-2
steps:
- download: current
artifact: bundles
patterns: "$(artifact.pattern)"
- download: current
artifact: specs
- script: |
set -exu
filename="$(echo '${{ convertToJson(spec) }}' | go run ./cmd/path basename --spec-file=/dev/stdin)"
spec_file="${SPEC_DIR}/${filename}"
[ -f "$spec_file" ]
# runs the tests
set +e
go run ./cmd/run_tests --spec-file="$spec_file" --bundle-dir="$BUNDLE_DIR"
rc="$?"
set -e
out_dir="$(go run ./cmd/path dir --spec-file="$spec_file" --bundle-dir="$RESULTS_DIR")"
mkdir -p "$out_dir"
find tests/.test -type f -exec cp {} "$out_dir" \;
exit "$rc"
displayName: Integration Test
- task: PublishBuildArtifacts@1
condition: always()
inputs:
pathToPublish: "$(results.dir)"
artifactName: testresults
- stage: SignAndPublish
dependsOn: ["Test"]
jobs:
- job: Sign_Packages
variables:
bundle.dir: "$(Pipeline.Workspace)/bundles"
signed.dir: "$(Pipeline.Workspace)/signed"
pool: production-pool-amd64-mariner-2
steps:
- download: current
artifact: bundles
- bash: |
set -exu
cp -r "$BUNDLE_DIR" "$SIGNED_DIR"
displayName: Copy files to sign
- task: UseDotNet@2
displayName: Install .NET Core SDK
inputs:
packageType: sdk
version: 2.2.207
- template: templates/sign.steps.yml
parameters:
rootDir: "$(signed.dir)"
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: "$(signed.dir)"
artifactName: signed
- job: Upload_Packages
dependsOn: ["Sign_Packages"]
variables:
specs.input.dir: "$(Pipeline.Workspace)/input"
signed.dir: "$(Pipeline.Workspace)/signed"
pool: production-pool-amd64-mariner-2
steps:
- download: current
artifact: signed
- download: current
artifact: input
- bash: |
set -exu
specs_basename="$(go run ./cmd/hash --project="$PACKAGE_NAME" --tag="$BUILD_TAG" --revision="$BUILD_REVISION")"
specs_file="${SPECS_INPUT_DIR}/${specs_basename}"
# uploads signed files to prod bucket, removes unsigned / failed uploads, writes output to stdout
go run ./cmd/upload \
--signed-dir="$SIGNED_DIR" \
--specs-file="$specs_file"
displayName: Upload Signed Packages to Prod Storage
name: uploadPackages
- job: Update_Latest
dependsOn: ["Sign_Packages", "Upload_Packages"]
pool: production-pool-amd64-mariner-2
steps:
- checkout: self
- bash: az login --identity
displayName: Login to Azure
- bash: scripts/generate-versions.sh
displayName: Generate versions
env:
AZURE_STORAGE_ACCOUNT: ${{ parameters.prod_storage_account_name }}
STORAGE_CONTAINER: moby
OUTPUT: $(Build.ArtifactStagingDirectory)
- task: PublishBuildArtifacts@1
displayName: Store pipeline artifacts
inputs:
artifactName: versions
- bash: |
set -ex
az storage container create -n "${STORAGE_CONTAINER}" --auth-mode=login --public-access=blob
az storage blob upload-batch \
--max-connections=10 --auth-mode=login \
--overwrite \
--source "${BUILD_ARTIFACTSTAGINGDIRECTORY}/" \
--destination "${STORAGE_CONTAINER}" \
--destination-path "/" \
--pattern "*.json" \
--content-type "application/json"
az storage blob upload-batch \
--max-connections=10 --auth-mode=login \
--overwrite \
--source "${BUILD_ARTIFACTSTAGINGDIRECTORY}/" \
--destination "${STORAGE_CONTAINER}" \
--destination-path "/" \
--pattern "*.rss" \
--content-type "application/rss+xml"
az storage blob upload-batch \
--max-connections=10 --auth-mode=login \
--overwrite \
--source "${BUILD_ARTIFACTSTAGINGDIRECTORY}/" \
--destination "${STORAGE_CONTAINER}" \
--destination-path "/" \
--pattern "**/latest/*" \
--content-type "text/plain"
displayName: Upload versions to blob storage
env:
AZURE_STORAGE_ACCOUNT: ${{ parameters.prod_storage_account_name }}
STORAGE_CONTAINER: ${{ parameters.index_container }}
- job: Publish_PMC
dependsOn: ["Update_Latest"]
pool: production-pool-amd64-mariner-2
steps:
- task: TriggerBuild@4
displayName: Trigger PMC Sync
inputs:
definitionIsInCurrentTeamProject: true
buildDefinition: 'pmc-sync'
queueBuildForUserThatTriggeredBuild: true
useSameSourceVersion: false
useSameBranch: false
branchToUse: 'master'
waitForQueuedBuildsToFinish: true
waitForQueuedBuildsToFinishRefreshTime: '60'
failTaskIfBuildsNotSuccessful: true
templateParameters: 'package: ${{ parameters.package_name }}, version_branch: ${{ parameters.tag }}'
authenticationMethod: 'OAuth Token'
enableBuildInQueueCondition: false
includeCurrentBuildDefinition: false
blockingBuildsList: 'pmc-sync'