Skip to content

Commit 585ef56

Browse files
JohanDevlclaude
andcommitted
fix: eliminate double Docker build by optimizing workflow triggers
- Remove push on main branch from docker-build.yml triggers - Add tag-based trigger (v*) to docker-build.yml for semantic versioning - Simplify versioning logic by removing manual Git tag retrieval - Remove manual workflow dispatch from auto-tag.yml (now uses automatic tag trigger) - Update documentation to reflect single-build process Process optimization: 1. PR merged to main → no immediate Docker build 2. auto-tag.yml creates new Git tag (v2.0.14) 3. Git tag push automatically triggers docker-build.yml 4. Single Docker build with correct semantic version tags This eliminates the previous double-build issue while maintaining proper semantic versioning. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 45c0834 commit 585ef56

File tree

3 files changed

+22
-81
lines changed

3 files changed

+22
-81
lines changed

.github/workflows/auto-tag.yml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,3 @@ jobs:
9393
env:
9494
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9595

96-
- name: Trigger Docker build for new version
97-
uses: actions/github-script@v7
98-
with:
99-
github-token: ${{ secrets.GITHUB_TOKEN }}
100-
script: |
101-
const { data: result } = await github.rest.actions.createWorkflowDispatch({
102-
owner: context.repo.owner,
103-
repo: context.repo.repo,
104-
workflow_id: 'docker-build.yml',
105-
ref: 'main',
106-
inputs: {
107-
reason: `New version tagged: ${{ steps.tag.outputs.new_tag }}`
108-
}
109-
});
110-
111-
console.log(`🐳 Triggered Docker build for version ${{ steps.tag.outputs.new_tag }}`);
112-
console.log(`Workflow dispatch result:`, result);

.github/workflows/docker-build.yml

Lines changed: 14 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
name: Docker Build and Publish
22

33
on:
4-
release:
5-
types: [published]
64
push:
75
branches:
8-
- main
96
- develop
7+
tags:
8+
- 'v*'
109
paths-ignore:
1110
- "**.md"
1211
- "docs/**"
@@ -19,6 +18,8 @@ on:
1918
- "**.md"
2019
- "docs/**"
2120
- ".github/ISSUE_TEMPLATE/**"
21+
release:
22+
types: [published]
2223
workflow_dispatch:
2324
inputs:
2425
reason:
@@ -50,25 +51,6 @@ jobs:
5051
- name: Set up Docker Buildx
5152
uses: docker/setup-buildx-action@v3
5253

53-
- name: Get latest version tag
54-
id: version
55-
run: |
56-
# Fetch all tags
57-
git fetch --tags
58-
59-
# Get the latest version tag
60-
LATEST_TAG=$(git tag -l "v*" | grep -v "-" | sort -V | tail -n 1)
61-
62-
# If no tag exists, default to v1.0.0
63-
if [ -z "$LATEST_TAG" ]; then
64-
LATEST_TAG="v1.0.0"
65-
fi
66-
67-
echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT
68-
echo "version=${LATEST_TAG#v}" >> $GITHUB_OUTPUT
69-
70-
echo "📋 Latest version tag: $LATEST_TAG"
71-
7254
- name: Extract metadata for Docker
7355
id: meta
7456
uses: docker/metadata-action@v5
@@ -77,15 +59,14 @@ jobs:
7759
${{ env.REGISTRY_IMAGE }}
7860
${{ env.GITHUB_IMAGE }}
7961
tags: |
80-
# Main branch tags - use latest available tag
62+
# Main branch tags (only via workflow_dispatch from auto-tag)
8163
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
8264
type=raw,value=main,enable=${{ github.ref == 'refs/heads/main' }}
83-
type=raw,value=${{ steps.version.outputs.latest_tag }},enable=${{ github.ref == 'refs/heads/main' }}
8465
# Develop branch tag
8566
type=raw,value=develop,enable=${{ github.ref == 'refs/heads/develop' }}
8667
# PR tags
8768
type=ref,event=pr,prefix=PR-
88-
# Release tags (for releases triggered by auto-tag)
69+
# Release/tag-based builds (semantic versioning)
8970
type=semver,pattern={{version}}
9071
type=semver,pattern={{major}}.{{minor}}
9172
@@ -118,15 +99,15 @@ jobs:
11899
cache-from: type=gha,scope=${{ github.workflow }}-${{ github.ref_name }}
119100
cache-to: type=gha,mode=max,scope=${{ github.workflow }}-${{ github.ref_name }}
120101
build-args: |
121-
VERSION=${{ github.ref == 'refs/heads/main' && steps.version.outputs.latest_tag || steps.meta.outputs.version }}
102+
VERSION=${{ steps.meta.outputs.version }}
122103
COMMIT_SHA=${{ github.sha }}
123104
BUILD_DATE=${{ steps.build_date.outputs.BUILD_DATE }}
124105
125106
- name: Scan image for vulnerabilities
126107
if: github.event_name != 'pull_request'
127108
uses: aquasecurity/trivy-action@master
128109
with:
129-
image-ref: ${{ env.REGISTRY_IMAGE }}:${{ github.ref == 'refs/heads/main' && steps.version.outputs.latest_tag || steps.meta.outputs.version }}
110+
image-ref: ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
130111
format: "sarif"
131112
output: "trivy-results.sarif"
132113

@@ -155,41 +136,18 @@ jobs:
155136
username: ${{ secrets.DOCKERHUB_USERNAME }}
156137
password: ${{ secrets.DOCKERHUB_TOKEN }}
157138

158-
- name: Get latest version tag
159-
id: version
160-
run: |
161-
# Fetch all tags
162-
git fetch --tags
163-
164-
# Get the latest version tag
165-
LATEST_TAG=$(git tag -l "v*" | grep -v "-" | sort -V | tail -n 1)
166-
167-
# If no tag exists, default to v1.0.0
168-
if [ -z "$LATEST_TAG" ]; then
169-
LATEST_TAG="v1.0.0"
170-
fi
171-
172-
echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT
173-
174-
- name: Extract Docker metadata
139+
- name: Extract Docker metadata for testing
175140
id: meta
176141
uses: docker/metadata-action@v5
177142
with:
178143
images: ${{ env.REGISTRY_IMAGE }}
179144
tags: |
180-
type=sha,format=short
181-
182-
- name: Determine test image tag
183-
id: test_tag
184-
run: |
185-
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
186-
echo "tag=${{ steps.version.outputs.latest_tag }}" >> $GITHUB_OUTPUT
187-
else
188-
echo "tag=${{ steps.meta.outputs.version }}" >> $GITHUB_OUTPUT
189-
fi
145+
type=semver,pattern={{version}}
146+
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
147+
type=raw,value=develop,enable=${{ github.ref == 'refs/heads/develop' }}
190148
191149
- name: Pull image for testing
192-
run: docker pull ${{ env.REGISTRY_IMAGE }}:${{ steps.test_tag.outputs.tag }}
150+
run: docker pull ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
193151

194152
- name: Test Docker image
195153
run: |
@@ -201,7 +159,7 @@ jobs:
201159
-v $(pwd)/test_config:/app/config \
202160
-v $(pwd)/test_logs:/app/logs \
203161
-v $(pwd)/test_exports:/app/exports \
204-
${{ env.REGISTRY_IMAGE }}:${{ steps.test_tag.outputs.tag }} --help
162+
${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} --help
205163
206164
echo "Docker image tests passed successfully"
207165

DOCKER_STRATEGY.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ Le système de gestion des images Docker a été optimisé pour maintenir unique
2121

2222
### 📋 Séquence lors d'un merge vers main :
2323

24-
1. **PR mergée vers `main`** → Déclenche `docker-build.yml`
25-
2. **docker-build.yml** récupère le dernier tag Git (ex: `v2.0.13`)
26-
3. **Image Docker créée** avec tags : `latest`, `main`, `v2.0.13`
27-
4. **auto-tag.yml** crée automatiquement le prochain tag (ex: `v2.0.14`)
28-
5. **Nouveau build Docker déclenché** avec le nouveau tag `v2.0.14`
24+
1. **PR mergée vers `main`** → Push sur la branche main (pas de build Docker)
25+
2. **auto-tag.yml** se déclenche et crée automatiquement le nouveau tag (ex: `v2.0.14`)
26+
3. **Push du tag Git** déclenche automatiquement `docker-build.yml`
27+
4. **Image Docker créée** avec tags : `latest`, `main`, `v2.0.14`
2928

3029
### 🔄 Résultat :
31-
- L'image Docker utilise **toujours la dernière version disponible** au moment du build
32-
- Les versions sémantiques sont **synchronisées** avec les tags Git
33-
- **Double build** garantit la disponibilité immédiate des nouvelles versions
30+
- **Un seul build Docker** par merge (plus de double build)
31+
- L'image Docker utilise **exactement la version sémantique** du tag Git
32+
- **Synchronisation parfaite** entre versions Git et Docker
33+
- **Process optimisé** sans builds redondants
3434

3535
## Registres Supportés
3636

0 commit comments

Comments
 (0)