Skip to content

Commit 6f1d414

Browse files
committed
major-update
1 parent dd3dc4f commit 6f1d414

File tree

1 file changed

+44
-5
lines changed

1 file changed

+44
-5
lines changed

.github/workflows/main.yml

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ name: Build and Push Docker Image
33
on:
44
push:
55
branches:
6-
- traefik-int
6+
- main
7+
- master
8+
- dev
79
paths:
810
- 'Dockerfile'
911
- 'go.mod'
@@ -17,6 +19,9 @@ on:
1719
- 'models/**'
1820
- 'services/**'
1921
- 'ui/**'
22+
23+
tags:
24+
- 'v*'
2025
workflow_dispatch:
2126

2227
env:
@@ -48,23 +53,57 @@ jobs:
4853
username: ${{ secrets.DOCKERHUB_USERNAME }}
4954
password: ${{ secrets.DOCKERHUB_TOKEN }}
5055

56+
# Get current date for image tags
57+
- name: Get current date
58+
id: date
59+
run: echo "date=$(date +'%Y%m%d')" >> $GITHUB_OUTPUT
60+
5161
# Prepare tags based on branch and version
5262
- name: Prepare Docker tags
5363
id: docker_tags
5464
run: |
5565
TAGS=""
56-
if [[ "${{ github.ref_type }}" == "branch" && "${{ github.ref_name }}" == "traefik-int" ]]; then
57-
TAGS="${{ env.DOCKERHUB_IMAGE_NAME }}:traefik-int"
66+
67+
# Add branch-specific tags
68+
if [[ "${{ github.ref_name }}" == "main" || "${{ github.ref_name }}" == "master" ]]; then
69+
# For main/master branch, add latest tag
70+
TAGS="$TAGS ${{ env.DOCKERHUB_IMAGE_NAME }}:latest"
71+
elif [[ "${{ github.ref_name }}" == "dev" ]]; then
72+
# For dev branch
73+
TAGS="$TAGS ${{ env.DOCKERHUB_IMAGE_NAME }}:dev"
74+
elif [[ "${{ github.ref_type }}" == "branch" ]]; then
75+
# For other branches
76+
TAGS="$TAGS ${{ env.DOCKERHUB_IMAGE_NAME }}:${{ github.ref_name }}"
77+
fi
78+
79+
# Add sha tag for all branches
80+
if [[ "${{ github.ref_type }}" == "branch" ]]; then
81+
TAGS="$TAGS,${{ env.DOCKERHUB_IMAGE_NAME }}:sha-${GITHUB_SHA::7}"
82+
fi
83+
84+
# Add version tag for tagged releases
85+
if [[ "${{ github.ref_type }}" == "tag" && "${{ github.ref }}" == refs/tags/v* ]]; then
86+
VERSION="${{ github.ref_name }}"
87+
88+
# Add full version tag
89+
TAGS="$TAGS,${{ env.DOCKERHUB_IMAGE_NAME }}:$VERSION"
5890
fi
91+
92+
# Add date tag for all builds
93+
TAGS="$TAGS,${{ env.DOCKERHUB_IMAGE_NAME }}:${{ steps.date.outputs.date }}"
94+
95+
# Remove leading space or comma if present
96+
TAGS=$(echo "$TAGS" | sed 's/^[ ,]*//')
97+
5998
echo "tags=$TAGS" >> $GITHUB_OUTPUT
6099
echo "Docker tags: $TAGS"
61100
62101
- name: Build and push
63102
uses: docker/build-push-action@v5
64103
with:
65104
context: .
66-
push: ${{ steps.docker_tags.outputs.tags != '' }} # IMPORTANT: Only push if tags were generated
105+
push: true
67106
platforms: linux/amd64,linux/arm64
68107
tags: ${{ steps.docker_tags.outputs.tags }}
69108
cache-from: type=gha
70-
cache-to: type=gha,mode=max
109+
cache-to: type=gha,mode=max

0 commit comments

Comments
 (0)