Skip to content

Commit 581d352

Browse files
committed
chore: update Docker build workflow to conditionally handle pull requests
- Added conditions to skip login, push, and manifest creation steps when the event is a pull request. - Enhanced manifest creation to process each tag individually for better clarity and management. - Updated image inspection to handle multiple tags, improving the workflow's robustness.
1 parent c54b0e0 commit 581d352

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

.github/workflows/docker-build.yml

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ jobs:
3232
id: buildx
3333

3434
- name: Log in to the Container registry
35+
# Only login if we're pushing (not a PR)
36+
if: github.event_name != 'pull_request'
3537
uses: docker/login-action@v3
3638
with:
3739
registry: ${{ env.REGISTRY }}
@@ -61,14 +63,17 @@ jobs:
6163
uses: docker/build-push-action@v5
6264
with:
6365
context: .
64-
push: true
66+
# Only push if not a PR
67+
push: ${{ github.event_name != 'pull_request' }}
6568
platforms: ${{ matrix.platform }}
6669
tags: ${{ steps.meta.outputs.tags }}-${{ steps.platform.outputs.arch }}
6770
labels: ${{ steps.meta.outputs.labels }}
6871
cache-from: type=gha
6972
cache-to: type=gha,mode=max
7073

7174
create-manifest:
75+
# Skip this job for pull requests
76+
if: github.event_name != 'pull_request'
7277
runs-on: ubuntu-latest
7378
needs: build
7479
permissions:
@@ -97,18 +102,24 @@ jobs:
97102
type=semver,pattern={{major}}.{{minor}}
98103
type=sha,format=long
99104
100-
- name: Create manifest list and push
105+
- name: Create manifest lists and push
101106
run: |
102-
# Get the first tag from meta outputs (without newlines)
103-
FIRST_TAG=$(echo "${{ steps.meta.outputs.tags }}" | head -n 1)
104-
105-
# Create manifest with both architecture images
106-
docker buildx imagetools create \
107-
--tag ${FIRST_TAG} \
108-
${FIRST_TAG}-amd64 \
109-
${FIRST_TAG}-arm64
107+
# Process each tag and create a manifest for it
108+
echo "${{ steps.meta.outputs.tags }}" | while read -r TAG; do
109+
if [ -n "$TAG" ]; then
110+
echo "Creating manifest for $TAG"
111+
docker buildx imagetools create \
112+
--tag $TAG \
113+
$TAG-amd64 \
114+
$TAG-arm64
115+
fi
116+
done
110117
111-
- name: Inspect image
118+
- name: Inspect images
112119
run: |
113-
FIRST_TAG=$(echo "${{ steps.meta.outputs.tags }}" | head -n 1)
114-
docker buildx imagetools inspect ${FIRST_TAG}
120+
echo "${{ steps.meta.outputs.tags }}" | while read -r TAG; do
121+
if [ -n "$TAG" ]; then
122+
echo "Inspecting manifest for $TAG"
123+
docker buildx imagetools inspect $TAG
124+
fi
125+
done

0 commit comments

Comments
 (0)