Skip to content

Commit 390b00e

Browse files
committed
Add parallel building
1 parent c303113 commit 390b00e

File tree

1 file changed

+62
-7
lines changed

1 file changed

+62
-7
lines changed

.github/workflows/docker-publish.yml

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,22 @@ env:
1616
# github.repository as <account>/<repo>
1717
IMAGE_NAME: ${{ github.repository }}
1818

19+
concurrency:
20+
group: ${{ github.workflow }}-${{ github.ref }}
21+
cancel-in-progress: true
22+
1923
jobs:
2024
build:
2125
runs-on: ubuntu-latest
2226
permissions:
2327
contents: read
2428
packages: write
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
platform:
33+
- linux/amd64
34+
- linux/arm64/v8
2535

2636
steps:
2737
- name: Checkout repository
@@ -55,22 +65,67 @@ jobs:
5565
env:
5666
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
5767
if: ${{ env.SENTRY_AUTH_TOKEN != '' }}
58-
run: "echo SENTRY_AUTH_TOKEN=\"$SENTRY_AUTH_TOKEN\" > frontend/.env.sentry-build-plugin"
68+
run: 'echo SENTRY_AUTH_TOKEN="$SENTRY_AUTH_TOKEN" > frontend/.env.sentry-build-plugin'
5969

6070
# Build and push Docker image with Buildx (don't push on PR)
6171
# https://github.com/docker/build-push-action
6272
- name: Build and push Docker image
63-
id: build-and-push
73+
id: build
6474
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5.1.0
6575
with:
6676
context: .
67-
push: ${{ github.event_name != 'pull_request' }}
68-
tags: ${{ steps.meta.outputs.tags }}
6977
labels: ${{ steps.meta.outputs.labels }}
7078
cache-from: type=gha
7179
cache-to: type=gha,mode=max
72-
platforms: linux/amd64,linux/arm64/v8
80+
platforms: ${{ matrix.platform }}
7381
provenance: true
7482
sbom: true
75-
build-args: |
76-
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
83+
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=${{ !github.event.pull_request || github.event.pull_request.base.repo == github.event.pull_request.head.repo }}
84+
- name: Export digest
85+
if: ${{ !github.event.pull_request || github.event.pull_request.base.repo == github.event.pull_request.head.repo }}
86+
run: |
87+
mkdir -p /tmp/digests
88+
digest="${{ steps.build.outputs.digest }}"
89+
touch "/tmp/digests/${digest#sha256:}"
90+
- name: Upload digest
91+
if: ${{ !github.event.pull_request || github.event.pull_request.base.repo == github.event.pull_request.head.repo }}
92+
uses: actions/upload-artifact@v3
93+
with:
94+
name: digests
95+
path: /tmp/digests/*
96+
if-no-files-found: error
97+
retention-days: 1
98+
merge:
99+
runs-on: ubuntu-latest
100+
if: ${{ !github.event.pull_request || github.event.pull_request.base.repo == github.event.pull_request.head.repo }}
101+
needs:
102+
- build
103+
permissions:
104+
packages: write
105+
steps:
106+
- name: Download digests
107+
uses: actions/download-artifact@v3
108+
with:
109+
name: digests
110+
path: /tmp/digests
111+
- name: Set up Docker Buildx
112+
uses: docker/setup-buildx-action@v3
113+
- name: Docker meta
114+
id: meta
115+
uses: docker/metadata-action@v5
116+
with:
117+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
118+
- name: Log into registry ${{ env.REGISTRY }}
119+
uses: docker/login-action@v3.0.0
120+
with:
121+
registry: ${{ env.REGISTRY }}
122+
username: ${{ github.actor }}
123+
password: ${{ secrets.GITHUB_TOKEN }}
124+
- name: Create manifest list and push
125+
working-directory: /tmp/digests
126+
run: |
127+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
128+
$(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)
129+
- name: Inspect image
130+
run: |
131+
docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}

0 commit comments

Comments
 (0)