Skip to content

Commit a8efddd

Browse files
committed
Implement semantic docker image tagging
1 parent dbaf6fb commit a8efddd

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ name: CI
22

33
on:
44
push:
5-
branches: ["*"]
5+
branches: ["main"]
6+
tags:
7+
- "v*"
68
pull_request:
7-
branches: ["*"]
9+
branches: ["main"]
810

911
jobs:
1012
build-and-test:
@@ -57,25 +59,32 @@ jobs:
5759
5860
# Log in to Github Container Registry
5961
- name: Log in to GHCR
60-
if: github.ref == 'refs/heads/main'
62+
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
6163
uses: docker/login-action@v3
6264
with:
6365
registry: ghcr.io
6466
username: ${{ github.actor }}
6567
password: ${{ secrets.GITHUB_TOKEN }}
6668

67-
# Build and push Docker image (for main only)
68-
- name: Build and push Docker image
69-
if: github.ref == 'refs/heads/main'
70-
run: |
71-
IMAGE_NAME=ghcr.io/${{ github.repository_owner }}/eventrelay
72-
IMAGE_TAG=${{ github.sha }}
73-
74-
docker build \
75-
-f backend/Dockerfile \
76-
-t $IMAGE_NAME:latest \
77-
-t $IMAGE_NAME:$IMAGE_TAG \
78-
backend
69+
# Semantic Docker image tagging (relesae-grade)
70+
- name: Dcoker metadata
71+
id: meta
72+
uses: docker/metadata-action@v5
73+
with:
74+
images: ghcr.io/${{ github.repository_owner }}/eventrelay
75+
tags: |
76+
type=semver,pattern={{version}}
77+
type=semver,pattern={{major}}.{{minor}}
78+
type=semver,pattern={{major}}
79+
type=sha
7980
80-
docker push $IMAGE_NAME:latest
81-
docker push $IMAGE_NAME:$IMAGE_TAG
81+
# Build and push docker image (for main only)
82+
- name: Build and push Docker image
83+
uses: docker/build-push-action@v5
84+
if: github.ref == 'refs/heads/main' || startWith(github.ref, 'refs/tags/v')
85+
with:
86+
context: backend
87+
file: backend/Dockerfile
88+
push: true
89+
tags: ${{ steps.meta.outputs.tags }}
90+
labels: ${{ steps.meta.outputs.labels }}

0 commit comments

Comments
 (0)