-
Notifications
You must be signed in to change notification settings - Fork 3
242 lines (231 loc) · 8.92 KB
/
build-push.yaml
File metadata and controls
242 lines (231 loc) · 8.92 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
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
name: Build and Push
on:
pull_request:
branches: [main]
paths:
- "VERSION"
- "Dockerfile"
- "docker/**"
- "requirements.txt"
- ".devcontainer/**"
- ".github/workflows/build-push.yaml"
push:
branches: [main]
paths:
- "VERSION"
- "Dockerfile"
- "docker/**"
- "requirements.txt"
- ".devcontainer/**"
- ".github/workflows/build-push.yaml"
workflow_dispatch:
inputs:
build_amd64:
description: "Release: push linux/amd64 (uncheck to skip). PRs always test both arches in parallel."
type: boolean
default: true
build_arm64:
description: "Release: push linux/arm64 (uncheck to skip). PRs always test both arches in parallel."
type: boolean
default: true
permissions:
contents: "read"
id-token: "write"
security-events: "write"
actions: "read"
packages: "write"
env:
IMAGE: codecollection-devtools
DEFAULT_BRANCH: "origin/${{ github.event.repository.default_branch }}"
SHARED_ARTIFACT_REPOSITORY_PATH: "us-docker.pkg.dev/runwhen-nonprod-shared/public-images"
GHCR_ORG: "runwhen-contrib"
jobs:
# ------------------------------------------------------------------------------
# PR: parallel build tests (native amd64; arm64 via QEMU)
# ------------------------------------------------------------------------------
build-test-amd64:
if: ${{ github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- name: Build test (linux/amd64)
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
platforms: linux/amd64
push: false
load: true
tags: codecollection-devtools:pr-test-amd64
build-test-arm64:
if: ${{ github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- name: Build test (linux/arm64)
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
platforms: linux/arm64
push: false
tags: codecollection-devtools:pr-test-arm64
# ------------------------------------------------------------------------------
# Release: shared VERSION for per-arch pushes + manifest merge
# ------------------------------------------------------------------------------
prepare-release:
if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v4
- id: version
run: |
if [[ -s VERSION ]]; then
VERSION=$(cat VERSION | tr -d '[:space:]')
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
echo "VERSION extracted: $VERSION"
else
echo "VERSION file is missing or empty" >&2
exit 1
fi
build-push-amd64:
needs: [prepare-release]
if: |
(github.event_name == 'push' || github.event_name == 'workflow_dispatch') &&
(github.event_name == 'push' || github.event.inputs.build_amd64 == 'true')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- id: auth-runwhen
name: Authenticate to Google Cloud
uses: google-github-actions/auth@v0.4.0
with:
workload_identity_provider: ${{ secrets.RUNWHEN_NONPROD_SHARED_WI_PROVIDER }}
service_account: ${{ secrets.RUNWHEN_NONPROD_SHARED_WI_SA }}
- name: Configure docker for GCP
run: gcloud --quiet auth configure-docker us-docker.pkg.dev
- name: Login to GHCR
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | \
docker login --username ${{ github.actor }} --password-stdin ghcr.io
- name: Build & push (linux/amd64)
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
platforms: linux/amd64
push: true
tags: |
${{ env.SHARED_ARTIFACT_REPOSITORY_PATH }}/${{ env.IMAGE }}:${{ needs.prepare-release.outputs.version }}-amd64
ghcr.io/${{ env.GHCR_ORG }}/${{ env.IMAGE }}:${{ needs.prepare-release.outputs.version }}-amd64
build-args: |
GITHUB_SHA=${{ github.sha }}
GITHUB_REF=${{ github.ref }}
build-push-arm64:
needs: [prepare-release]
if: |
(github.event_name == 'push' || github.event_name == 'workflow_dispatch') &&
(github.event_name == 'push' || github.event.inputs.build_arm64 == 'true')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- id: auth-runwhen
name: Authenticate to Google Cloud
uses: google-github-actions/auth@v0.4.0
with:
workload_identity_provider: ${{ secrets.RUNWHEN_NONPROD_SHARED_WI_PROVIDER }}
service_account: ${{ secrets.RUNWHEN_NONPROD_SHARED_WI_SA }}
- name: Configure docker for GCP
run: gcloud --quiet auth configure-docker us-docker.pkg.dev
- name: Login to GHCR
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | \
docker login --username ${{ github.actor }} --password-stdin ghcr.io
- name: Build & push (linux/arm64)
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
platforms: linux/arm64
push: true
tags: |
${{ env.SHARED_ARTIFACT_REPOSITORY_PATH }}/${{ env.IMAGE }}:${{ needs.prepare-release.outputs.version }}-arm64
ghcr.io/${{ env.GHCR_ORG }}/${{ env.IMAGE }}:${{ needs.prepare-release.outputs.version }}-arm64
build-args: |
GITHUB_SHA=${{ github.sha }}
GITHUB_REF=${{ github.ref }}
merge-manifests:
needs: [prepare-release, build-push-amd64, build-push-arm64]
if: |
always() && !cancelled() &&
needs.prepare-release.result == 'success' &&
(
(github.event_name == 'push' &&
needs.build-push-amd64.result == 'success' &&
needs.build-push-arm64.result == 'success') ||
(github.event_name == 'workflow_dispatch' &&
(needs.build-push-amd64.result == 'success' || needs.build-push-arm64.result == 'success'))
)
runs-on: ubuntu-latest
steps:
- id: auth-runwhen
name: Authenticate to Google Cloud
uses: google-github-actions/auth@v0.4.0
with:
workload_identity_provider: ${{ secrets.RUNWHEN_NONPROD_SHARED_WI_PROVIDER }}
service_account: ${{ secrets.RUNWHEN_NONPROD_SHARED_WI_SA }}
- name: Configure docker for GCP
run: gcloud --quiet auth configure-docker us-docker.pkg.dev
- name: Login to GHCR
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | \
docker login --username ${{ github.actor }} --password-stdin ghcr.io
- uses: docker/setup-buildx-action@v3
- name: Merge multi-arch manifests (GCP + GHCR)
env:
V: ${{ needs.prepare-release.outputs.version }}
GCP_BASE: ${{ env.SHARED_ARTIFACT_REPOSITORY_PATH }}/${{ env.IMAGE }}
GHCR_BASE: ghcr.io/${{ env.GHCR_ORG }}/${{ env.IMAGE }}
AMD64_OK: ${{ needs.build-push-amd64.result }}
ARM64_OK: ${{ needs.build-push-arm64.result }}
run: |
set -euo pipefail
GCP_REF=()
GHCR_REF=()
if [[ "$AMD64_OK" == "success" ]]; then
GCP_REF+=("${GCP_BASE}:${V}-amd64")
GHCR_REF+=("${GHCR_BASE}:${V}-amd64")
fi
if [[ "$ARM64_OK" == "success" ]]; then
GCP_REF+=("${GCP_BASE}:${V}-arm64")
GHCR_REF+=("${GHCR_BASE}:${V}-arm64")
fi
docker buildx imagetools create \
-t "${GCP_BASE}:${V}" -t "${GCP_BASE}:latest" \
"${GCP_REF[@]}"
docker buildx imagetools create \
-t "${GHCR_BASE}:${V}" -t "${GHCR_BASE}:latest" \
"${GHCR_REF[@]}"
- name: Notify Slack of Container Build
uses: slackapi/slack-github-action@v1.19.0
with:
channel-id: "#notifications"
slack-message: "Just Pushed to ${{ env.SHARED_ARTIFACT_REPOSITORY_PATH }}/${{ env.IMAGE }}:${{ needs.prepare-release.outputs.version }}"
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
- name: Notify Slack of GHCR Push
uses: slackapi/slack-github-action@v1.19.0
with:
channel-id: "#codecollections"
slack-message: "Just deployed latest version of codecollection-devtools to https://github.com/orgs/runwhen-contrib/packages/container/package/codecollection-devtools"
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}