Skip to content

Commit 1f55272

Browse files
committed
Merge platforms before publishing.
1 parent 9ca84dc commit 1f55272

File tree

1 file changed

+62
-11
lines changed

1 file changed

+62
-11
lines changed

.github/workflows/docker.yml

Lines changed: 62 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- '*'
77

88
jobs:
9-
build-and-push-image:
9+
build:
1010
strategy:
1111
matrix:
1212
include:
@@ -28,12 +28,6 @@ jobs:
2828
- name: Checkout repository
2929
uses: actions/checkout@v4
3030

31-
- name: Log in to Docker Hub
32-
uses: docker/login-action@v3
33-
with:
34-
username: ${{ secrets.DOCKER_USERNAME }}
35-
password: ${{ secrets.DOCKER_PASSWORD }}
36-
3731
- name: Log in to the Container registry
3832
uses: docker/login-action@v3
3933
with:
@@ -49,11 +43,68 @@ jobs:
4943
openhv/server
5044
ghcr.io/${{ github.repository }}
5145
52-
- name: Build and push Docker image
46+
- name: Build and push by digest
47+
id: build
5348
uses: docker/build-push-action@v6
5449
with:
55-
context: .
5650
platforms: ${{ matrix.platform }}
57-
push: true
58-
tags: ${{ steps.meta.outputs.tags }}
5951
labels: ${{ steps.meta.outputs.labels }}
52+
tags: ${{ steps.meta.outputs.tags }}
53+
outputs: type=image,push-by-digest=true,name-canonical=true,push=true
54+
55+
- name: Export digest
56+
run: |
57+
mkdir -p ${{ runner.temp }}/digests
58+
digest="${{ steps.build.outputs.digest }}"
59+
touch "${{ runner.temp }}/digests/${digest#sha256:}"
60+
61+
- name: Upload digest
62+
uses: actions/upload-artifact@v4
63+
with:
64+
name: digests-${{ env.PLATFORM_PAIR }}
65+
path: ${{ runner.temp }}/digests/*
66+
if-no-files-found: error
67+
retention-days: 1
68+
69+
70+
merge:
71+
runs-on: ubuntu-latest
72+
needs:
73+
- build
74+
steps:
75+
- name: Download digests
76+
uses: actions/download-artifact@v4
77+
with:
78+
path: ${{ runner.temp }}/digests
79+
pattern: digests-*
80+
merge-multiple: true
81+
82+
- name: Log in to Docker Hub
83+
uses: docker/login-action@v3
84+
with:
85+
username: ${{ secrets.DOCKER_USERNAME }}
86+
password: ${{ secrets.DOCKER_PASSWORD }}
87+
88+
- name: Set up Docker Buildx
89+
uses: docker/setup-buildx-action@v3
90+
91+
- name: Docker meta
92+
id: meta
93+
uses: docker/metadata-action@v5
94+
with:
95+
images: ${{ env.REGISTRY_IMAGE }}
96+
tags: |
97+
type=ref,event=branch
98+
type=ref,event=pr
99+
type=semver,pattern={{version}}
100+
type=semver,pattern={{major}}.{{minor}}
101+
102+
- name: Create manifest list and push
103+
working-directory: ${{ runner.temp }}/digests
104+
run: |
105+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
106+
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
107+
108+
- name: Inspect image
109+
run: |
110+
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}

0 commit comments

Comments
 (0)