Skip to content

Commit 46c5fd1

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

File tree

1 file changed

+62
-5
lines changed

1 file changed

+62
-5
lines changed

.github/workflows/docker.yml

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

0 commit comments

Comments
 (0)