-
Notifications
You must be signed in to change notification settings - Fork 21
287 lines (274 loc) · 11.1 KB
/
build.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
287
name: Build
permissions:
contents: read
packages: write
on:
workflow_call:
inputs:
ref:
type: string
required: true
build-server-image:
description: Whether to build a `usdr-gost-api` Docker image using the `production-api.Dockerfile`.
type: boolean
default: true
build-website:
description: Whether to build website distribution artifacts for the client package.
type: boolean
default: true
server-image-args-ref:
description: Ref name for the build commit, like refs/heads/my-feature-branch-1.
type: string
required: true
server-image-artifacts-retention-days:
description: Number of days to store Docker attestation artifacts.
type: number
default: 90
server-image-upload-attestations:
description: Whether to upload attestation files for the Docker build as artifacts.
type: boolean
default: false
server-image-push:
description: Whether to push Docker images to the registry after building.
type: boolean
default: true
server-image-name:
description: Name of the docker image. Use caution when setting a non-default value.
type: string
default: ${{ github.repository }}-api
server-image-registry:
description: The Docker image registry. Use caution when setting a non-default value.
type: string
default: ghcr.io
server-image-tag-latest:
description: Tags image builds with `latest`.
type: boolean
default: false
server-image-tag-production:
description: Tags image builds with `production`.
type: boolean
required: false
server-image-tag-pr:
description: A PR number to add as a Docker image tag (as `pr-<value>`) when building for a pull request.
type: string
required: false
server-image-tag-release:
description: A tag value that, if provided, signifies the release version associated with the Docker image.
type: string
required: false
server-image-version:
description: Value to set for the `org.opencontainers.image.version label`.
type: string
default: ""
website-artifact-retention-days:
description: Number of days to retain website build artifacts.
type: number
default: 90
outputs:
build-server-image-result:
value: ${{ jobs.server-docker-image.result }}
build-website-result:
value: ${{ jobs.website-bundle.result }}
server-image-digest:
value: ${{ jobs.server-docker-image.outputs.digest }}
server-attestation-artifacts-key:
value: ${{ jobs.server-docker-image.outputs.attestation-artifacts-key }}
server-attestation-artifacts-path:
value: ${{ jobs.server-docker-image.outputs.attestation-artifacts-path }}
website-artifacts-key:
value: ${{ jobs.website-bundle.outputs.artifacts-key }}
website-artifacts-path:
value: ${{ jobs.website-bundle.outputs.artifacts-path }}
website-checksums-sha256:
value: ${{ jobs.website-bundle.outputs.checksums-sha256 }}
jobs:
server-docker-image:
name: Build server Docker image
if: inputs.build-server-image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
ATTESTATION_ARTIFACTS_KEY: "server-image-attestations-${{ inputs.ref }}"
outputs:
commit-tag: ${{ inputs.ref }}
digest: ${{ steps.build-push.outputs.digest }}
attestation-artifacts-key: ${{ env.ATTESTATION_ARTIFACTS_KEY }}
attestation-artifacts-path: ${{ steps.store-attestations.outputs.path }}
steps:
- uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
disable-sudo: true
egress-policy: audit
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
id: checkout
with:
ref: ${{ inputs.ref }}
show-progress: 'false'
persist-credentials: 'false'
- name: Set build info for the checked-out commit
id: commit-sha
run: echo "long=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0
with:
platforms: linux/amd64,linux/arm64
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1
with:
platforms: linux/amd64,linux/arm64
- name: Authenticate docker
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1
with:
images: ${{ inputs.server-image-registry }}/${{ inputs.server-image-name }}
tags: |
type=raw,enable=true,priority=100,prefix=sha-,value=${{ steps.commit-sha.outputs.long }}
type=raw,enable=${{ inputs.server-image-tag-release != '' }},priority=200,value=${{ inputs.server-image-tag-release }}
type=raw,enable=${{ inputs.server-image-tag-latest }},priority=300,value=latest
type=raw,enable=${{ inputs.server-image-tag-pr != '' }},priority=600,prefix=pr-,value=${{ inputs.server-image-tag-pr }}
labels: |
org.opencontainers.image.title=${{ inputs.server-image-name }}
org.opencontainers.image.version=${{ inputs.server-image-version }}
org.opencontainers.image.revision=${{ steps.commit-sha.outputs.long }}
com.datadoghq.tags.service=gost
com.datadoghq.tags.version=${{ steps.commit-sha.outputs.long }}
- name: Set bake file definition as step output
id: bakefile
run: |
BAKEFILE_CONTENTS="$(cat $BAKEFILE_PATH)"
echo "result<<ENDOFBAKEFILE" >> $GITHUB_OUTPUT
echo "$BAKEFILE_CONTENTS" >> $GITHUB_OUTPUT
echo "ENDOFBAKEFILE" >> $GITHUB_OUTPUT
env:
BAKEFILE_PATH: ${{ steps.meta.outputs.bake-file }}
- name: Build and push Docker image
id: build-push
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6.9.0
with:
context: .
github-token: ${{ secrets.GITHUB_TOKEN }}
push: ${{ inputs.server-image-push }}
file: docker/production-api.Dockerfile
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: true
sbom: true
build-args: |
GIT_COMMIT=${{ inputs.ref }}
GIT_REF=${{ inputs.server-image-args-ref }}
TIMESTAMP=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
- name: Publish build results
run: |
REPORT_FILE=$(mktemp -t summary.md.XXXXX)
cat >> $REPORT_FILE << 'ENDOFREPORT'
## Docker Build Summary
**Image ID:** `${{ steps.build-push.outputs.imageid }}`
**Image Digest:** `${{ steps.build-push.outputs.digest }}`
<details>
<summary>Bake File</summary>
```json
${{ steps.bakefile.outputs.result }}
```
</details>
<details>
<summary>Build Metadata</summary>
```json
${{ steps.build-push.outputs.metadata }}
```
</details>
ENDOFREPORT
cat "$REPORT_FILE" >> $GITHUB_STEP_SUMMARY
- name: Store attestations
id: store-attestations
if: inputs.server-image-upload-attestations
run: |
ATTESTATIONS_DIR=$(mktemp -d)
echo "path=$ATTESTATIONS_DIR" >> $GITHUB_OUTPUT
docker buildx imagetools inspect "$INSPECT_NAME" --format "{{ json .SBOM }}" > $ATTESTATIONS_DIR/sbom.sdpx.json
docker buildx imagetools inspect "$INSPECT_NAME" --format "{{ json .Provenance }}" > $ATTESTATIONS_DIR/provenance.json
env:
INSPECT_NAME: ${{ inputs.server-image-registry }}/${{ inputs.server-image-name }}@${{ steps.build-push.outputs.digest }}
- name: Upload attestations
if: steps.store-attestations.outcome == 'success'
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: ${{ env.ATTESTATION_ARTIFACTS_KEY }}
path: ${{ steps.store-attestations.outputs.path }}
if-no-files-found: error
include-hidden-files: true
retention-days: ${{ inputs.server-image-artifacts-retention-days }}
overwrite: true
website-bundle:
name: Build website deployment artifact
if: inputs.build-website
runs-on: ubuntu-latest
permissions:
contents: read
packages: none
env:
ARTIFACTS_KEY: website-${{ inputs.ref }}
ARTIFACTS_PATH: ${{ github.workspace }}/packages/client/dist
outputs:
artifacts-key: ${{ env.ARTIFACTS_KEY }}
artifacts-path: ${{ env.ARTIFACTS_PATH }}
checksums-sha256: ${{ steps.checksums.outputs.sha256 }}
steps:
- uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
disable-sudo: true
egress-policy: audit
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ inputs.ref }}
show-progress: 'false'
persist-credentials: 'false'
- name: Setup Node
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version-file: .nvmrc
cache: yarn
cache-dependency-path: yarn.lock
- name: Install dependencies
run: yarn workspace client install --frozen-lockfile
- name: Build the website
run: yarn workspace client build
- name: Compute build artifact checksums
id: checksums
run: |
DIST_CHECKSUMS=$(find "$ARTIFACTS_PATH" -type f -exec sha256sum {} \;)
echo "sha256<<EOF" >> $GITHUB_OUTPUT
echo "$DIST_CHECKSUMS" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Publish build results
run: |
REPORT_FILE=$(mktemp -t summary.md.XXXXX)
cat >> $REPORT_FILE << 'ENDOFREPORT'
## Build Website Summary
<details>
<summary>Checksums</summary>
```
${{ steps.checksums.outputs.sha256 }}
```
</details>
ENDOFREPORT
cat "$REPORT_FILE" >> $GITHUB_STEP_SUMMARY
- name: Upload build artifact
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: ${{ env.ARTIFACTS_KEY }}
path: ${{ env.ARTIFACTS_PATH }}
if-no-files-found: error
include-hidden-files: true
retention-days: ${{ inputs.website-artifact-retention-days }}
overwrite: true