CI : tags de version sur les images Docker
Build and Publish Docker Image / build-and-push-image (push) Successful in 48s

En plus de :latest, chaque image (frontend + backend) est taguée :
- <version> (semver de package.json, ex. 1.0.0)
- <version>-<build> (numéro de run Gitea, unique/incrémental)
- <sha court> (commit exact)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Zed
2026-07-22 18:30:14 +02:00
parent 9352bb08d9
commit 0debfa0c36
+37 -9
View File
@@ -17,28 +17,56 @@ jobs:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
# Simple login directly with docker login - name: Compute version and image names
run: |
LOWERCASE_IMAGE=$(echo "${{ env.IMAGE_NAME }}" | tr '[:upper:]' '[:lower:]')
# Version sémantique lue dans package.json (sans dépendre de node)
VERSION=$(sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' package.json | head -1)
[ -z "$VERSION" ] && VERSION="0.0.0"
BUILD="${{ gitea.run_number }}"
SHORT_SHA=$(echo "${{ gitea.sha }}" | cut -c1-7)
{
echo "FRONT=${{ env.REGISTRY }}/$LOWERCASE_IMAGE"
echo "BACK=${{ env.REGISTRY }}/$LOWERCASE_IMAGE-backend"
echo "VERSION=$VERSION"
echo "TAG=$VERSION-$BUILD"
echo "SHORT_SHA=$SHORT_SHA"
} >> "$GITHUB_ENV"
echo "Publication version $VERSION (build $BUILD, commit $SHORT_SHA)"
- name: Log in to the Container registry - name: Log in to the Container registry
run: echo "${{ secrets.DOCKER_TOKEN }}" | docker login ${{ env.REGISTRY }} -u "${{ gitea.actor }}" --password-stdin run: echo "${{ secrets.DOCKER_TOKEN }}" | docker login ${{ env.REGISTRY }} -u "${{ gitea.actor }}" --password-stdin
# Frontend image (nginx + SPA) # Frontend image (nginx + SPA)
- name: Build frontend Docker image - name: Build frontend Docker image
run: | run: |
LOWERCASE_IMAGE=$(echo "${{ env.IMAGE_NAME }}" | tr '[:upper:]' '[:lower:]') docker build \
docker build -t ${{ env.REGISTRY }}/$LOWERCASE_IMAGE:latest . -t "$FRONT:latest" \
-t "$FRONT:$VERSION" \
-t "$FRONT:$TAG" \
-t "$FRONT:$SHORT_SHA" \
.
- name: Push frontend Docker image - name: Push frontend Docker image
run: | run: |
LOWERCASE_IMAGE=$(echo "${{ env.IMAGE_NAME }}" | tr '[:upper:]' '[:lower:]') docker push "$FRONT:latest"
docker push ${{ env.REGISTRY }}/$LOWERCASE_IMAGE:latest docker push "$FRONT:$VERSION"
docker push "$FRONT:$TAG"
docker push "$FRONT:$SHORT_SHA"
# Backend image (Express API) # Backend image (Express API)
- name: Build backend Docker image - name: Build backend Docker image
run: | run: |
LOWERCASE_IMAGE=$(echo "${{ env.IMAGE_NAME }}" | tr '[:upper:]' '[:lower:]') docker build \
docker build -t ${{ env.REGISTRY }}/$LOWERCASE_IMAGE-backend:latest ./server -t "$BACK:latest" \
-t "$BACK:$VERSION" \
-t "$BACK:$TAG" \
-t "$BACK:$SHORT_SHA" \
./server
- name: Push backend Docker image - name: Push backend Docker image
run: | run: |
LOWERCASE_IMAGE=$(echo "${{ env.IMAGE_NAME }}" | tr '[:upper:]' '[:lower:]') docker push "$BACK:latest"
docker push ${{ env.REGISTRY }}/$LOWERCASE_IMAGE-backend:latest docker push "$BACK:$VERSION"
docker push "$BACK:$TAG"
docker push "$BACK:$SHORT_SHA"