Skip to content

Commit 53bdb29

Browse files
committed
tweaks to tags
1 parent cc7f5ec commit 53bdb29

File tree

1 file changed

+61
-40
lines changed

1 file changed

+61
-40
lines changed

.github/workflows/docker-publish.yml

+61-40
Original file line numberDiff line numberDiff line change
@@ -64,29 +64,18 @@ jobs:
6464
- name: Checkout repository
6565
uses: actions/checkout@v4
6666

67-
# Install the cosign tool except on PR
68-
- name: Install cosign
69-
if: github.event_name != 'pull_request'
70-
uses: sigstore/cosign-installer@v3
71-
72-
# Add support for more platforms with QEMU (optional)
73-
# https://github.com/docker/setup-qemu-action
74-
- name:
75-
uses: docker/setup-qemu-action@v3
67+
- name: Prepare variables
68+
id: vars
69+
run: |
70+
SURFIX=$(echo ${{ matrix.platform }} | cut -d'/' -f2)
71+
echo "SURFIX=$SURFIX" >> $GITHUB_OUTPUT
72+
# Generate a unique local tag for the image
73+
echo "LOCAL_TAG=local-${{ github.sha }}-$SURFIX" >> $GITHUB_OUTPUT
7674
7775
# Set up BuildKit Docker container builder
7876
- name: Set up Docker Buildx
7977
uses: docker/setup-buildx-action@v3
8078

81-
# Login against a Docker registry except on PR
82-
- name: Log into registry ${{ env.REGISTRY }}
83-
if: github.event_name != 'pull_request'
84-
uses: docker/login-action@v3
85-
with:
86-
registry: ${{ env.REGISTRY }}
87-
username: ${{ github.actor }}
88-
password: ${{ secrets.GITHUB_TOKEN }}
89-
9079
# Extract metadata (tags, labels) for Docker
9180
- name: Extract Docker metadata
9281
id: meta
@@ -101,30 +90,32 @@ jobs:
10190
type=raw,enable=${{ github.ref_type == 'tag' }}, value=latest
10291
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
10392

104-
# Build and push Docker image with platform-specific tag
105-
- name: Build and push Docker image
106-
id: build-and-push
93+
# Build and export Docker image for each platform (without pushing)
94+
- name: Build Docker image
95+
id: build
10796
uses: docker/build-push-action@v6
10897
with:
10998
context: .
11099
pull: true
111-
push: ${{ github.event_name != 'pull_request' }}
112-
tags: ${{ steps.meta.outputs.tags }}-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }}
100+
push: false
101+
load: true # Export to local Docker instead of pushing
102+
tags: ${{ steps.vars.outputs.LOCAL_TAG }}
113103
labels: ${{ steps.meta.outputs.labels }}
114104
platforms: ${{ matrix.platform }}
115105
cache-from: type=gha,scope=${{ matrix.platform }}
116106
cache-to: type=gha,mode=max,scope=${{ matrix.platform }}
117107
build-args: GITHUB_BUILD=true,VERSION=${{ github.ref_type == 'tag' && github.ref_name || github.sha }}
108+
outputs: type=docker,dest=/tmp/image-${{ steps.vars.outputs.SURFIX }}.tar
118109

119-
# Sign the platform specific image
120-
- name: Sign the published Docker image
121-
if: ${{ github.event_name != 'pull_request' }}
122-
env:
123-
TAGS: ${{ steps.meta.outputs.tags }}
124-
DIGEST: ${{ steps.build-and-push.outputs.digest }}
125-
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
110+
# Upload the tarball as an artifact
111+
- name: Upload image artifact
112+
uses: actions/upload-artifact@v4
113+
with:
114+
name: docker-image-${{ steps.vars.outputs.SURFIX }}
115+
path: /tmp/image-${{ steps.vars.outputs.SURFIX }}.tar
116+
retention-days: 1
126117

127-
merge:
118+
merge-and-push:
128119
needs: build
129120
runs-on: ubuntu-latest
130121
if: github.event_name != 'pull_request'
@@ -137,13 +128,23 @@ jobs:
137128
- name: Checkout repository
138129
uses: actions/checkout@v4
139130

131+
# Install the cosign tool
132+
- name: Install cosign
133+
uses: sigstore/cosign-installer@v3
134+
135+
# Set up Docker Buildx
136+
- name: Set up Docker Buildx
137+
uses: docker/setup-buildx-action@v3
138+
139+
# Log into registry
140140
- name: Log into registry ${{ env.REGISTRY }}
141141
uses: docker/login-action@v3
142142
with:
143143
registry: ${{ env.REGISTRY }}
144144
username: ${{ github.actor }}
145145
password: ${{ secrets.GITHUB_TOKEN }}
146146

147+
# Extract Docker metadata for tagging
147148
- name: Extract Docker metadata
148149
id: meta
149150
uses: docker/metadata-action@v5
@@ -157,26 +158,46 @@ jobs:
157158
type=raw,enable=${{ github.ref_type == 'tag' }}, value=latest
158159
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
159160

160-
- name: Install cosign
161-
uses: sigstore/cosign-installer@v3
161+
# Download all image artifacts
162+
- name: Download AMD64 image
163+
uses: actions/download-artifact@v4
164+
with:
165+
name: docker-image-amd64
166+
path: /tmp
162167

163-
- name: Set up Docker Buildx
164-
uses: docker/setup-buildx-action@v3
168+
- name: Download ARM64 image
169+
uses: actions/download-artifact@v4
170+
with:
171+
name: docker-image-arm64
172+
path: /tmp
173+
174+
# Load images into Docker
175+
- name: Load images
176+
run: |
177+
docker load --input /tmp/image-amd64.tar
178+
docker load --input /tmp/image-arm64.tar
165179
166-
- name: Create and push manifest
180+
# Create manifest lists and push
181+
- name: Create and push manifest lists
167182
run: |
168183
TAGS="${{ steps.meta.outputs.tags }}"
169184
for TAG in $TAGS; do
185+
# Tag the local images with their registry counterparts
186+
docker tag local-${{ github.sha }}-amd64 $TAG-amd64
187+
docker tag local-${{ github.sha }}-arm64 $TAG-arm64
188+
189+
# Push individual platform images
190+
# docker push $TAG-amd64
191+
# docker push $TAG-arm64
192+
170193
# Create manifest list and push it
171194
docker buildx imagetools create -t $TAG \
172195
$TAG-amd64 \
173196
$TAG-arm64
174197
done
175198
176-
- name: Install cosign
177-
uses: sigstore/cosign-installer@v3
178-
179-
- name: Sign the manifest
199+
# Sign the manifest
200+
- name: Sign the manifests
180201
env:
181202
TAGS: ${{ steps.meta.outputs.tags }}
182203
run: |

0 commit comments

Comments
 (0)