Skip to content

Commit 6737fd8

Browse files
committed
fix: update Docker workflow to handle version tags and extract metadata
1 parent e0d5f7b commit 6737fd8

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

.github/workflows/docker.yml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on:
55
push:
66
branches:
77
- main
8+
tags:
9+
- 'v*.*.*'
810

911
env:
1012
REGISTRY: docker.io
@@ -32,7 +34,7 @@ jobs:
3234
cache-to: type=gha,mode=max
3335

3436
publish:
35-
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
37+
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
3638
needs: build
3739
runs-on: ubuntu-latest
3840
steps:
@@ -58,15 +60,27 @@ jobs:
5860
username: ${{ secrets.DOCKERHUB_USERNAME }}
5961
password: ${{ secrets.DOCKERHUB_TOKEN }}
6062

63+
- name: Extract Docker metadata
64+
id: meta
65+
uses: docker/metadata-action@v5
66+
with:
67+
images: ${{ env.REGISTRY }}/${{ env.DOCKERHUB_NAMESPACE }}/${{ env.IMAGE_NAME }}
68+
tags: |
69+
type=ref,event=branch
70+
type=semver,pattern={{version}}
71+
type=semver,pattern={{major}}.{{minor}}
72+
type=semver,pattern={{major}}
73+
type=sha
74+
type=raw,value=latest,enable=${{ github.ref_type == 'tag' && startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, '-') }}
75+
6176
- name: Build and push image
6277
uses: docker/build-push-action@v5
6378
with:
6479
context: .
6580
file: Dockerfile
6681
push: true
67-
tags: |
68-
${{ env.REGISTRY }}/${{ env.DOCKERHUB_NAMESPACE }}/${{ env.IMAGE_NAME }}:latest
69-
${{ env.REGISTRY }}/${{ env.DOCKERHUB_NAMESPACE }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
82+
tags: ${{ steps.meta.outputs.tags }}
83+
labels: ${{ steps.meta.outputs.labels }}
7084
cache-from: type=gha
7185
cache-to: type=gha,mode=max
7286

0 commit comments

Comments
 (0)