Skip to content

Commit e4a0a9e

Browse files
Simplify Docker workflow to manual dispatch with custom tag
1 parent 66d6b56 commit e4a0a9e

File tree

1 file changed

+7
-45
lines changed

1 file changed

+7
-45
lines changed
Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
name: Build and Push Docker Image
22

33
on:
4-
push:
5-
branches:
6-
- main
7-
- add-docker-workflow
8-
tags: ['v*']
4+
workflow_dispatch:
5+
inputs:
6+
tag:
7+
description: 'Docker image tag'
8+
required: true
9+
type: string
910
pull_request:
1011
branches: [main]
1112

@@ -35,51 +36,12 @@ jobs:
3536
username: ${{ github.actor }}
3637
password: ${{ secrets.GITHUB_TOKEN }}
3738

38-
- name: Extract metadata (tags, labels)
39-
id: meta
40-
uses: docker/metadata-action@v5.7.0
41-
with:
42-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
43-
tags: |
44-
type=raw,value=latest,enable={{is_default_branch}}
45-
type=sha,prefix={{branch}}-,format=short
46-
type=semver,pattern={{version}}
47-
48-
- name: Check if image exists
49-
id: check
50-
if: github.event_name != 'pull_request'
51-
continue-on-error: true
52-
run: |
53-
TAGS="${{ steps.meta.outputs.tags }}"
54-
IMAGE_EXISTS=false
55-
56-
for TAG in $TAGS; do
57-
echo "Checking if image exists: $TAG"
58-
if docker manifest inspect $TAG > /dev/null 2>&1; then
59-
echo "Image already exists: $TAG"
60-
IMAGE_EXISTS=true
61-
else
62-
echo "Image does not exist: $TAG"
63-
IMAGE_EXISTS=false
64-
break
65-
fi
66-
done
67-
68-
echo "should_push=$([[ "$IMAGE_EXISTS" == "false" ]] && echo "true" || echo "false")" >> $GITHUB_OUTPUT
69-
7039
- name: Build and push Docker image
71-
if: github.event_name == 'pull_request' || steps.check.outputs.should_push == 'true'
7240
uses: docker/build-push-action@v6
7341
with:
7442
context: .
7543
push: ${{ github.event_name != 'pull_request' }}
76-
tags: ${{ steps.meta.outputs.tags }}
77-
labels: ${{ steps.meta.outputs.labels }}
44+
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ inputs.tag }}
7845
cache-from: type=gha
7946
cache-to: type=gha,mode=max
8047
platforms: linux/amd64,linux/arm64
81-
82-
- name: Image push skipped
83-
if: github.event_name != 'pull_request' && steps.check.outputs.should_push != 'true'
84-
run: |
85-
echo "All image tags already exist in registry. Skipping build and push."

0 commit comments

Comments
 (0)