Skip to content

Commit 7442c4c

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

File tree

1 file changed

+61
-5
lines changed

1 file changed

+61
-5
lines changed

.github/workflows/docker.yml

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

0 commit comments

Comments
 (0)