.github/workflows/docker-publish.yaml #20
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: | |
push: | |
tags: | |
- 'v*.*.*' # Se déclenche uniquement pour les tags au format vx.x.x | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'Version tag (e.g., v1.0.0)' | |
required: true | |
default: 'v1.0.0' | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Set version for build | |
id: set_version | |
run: | | |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
VERSION="${{ github.event.inputs.version }}" | |
elif [[ "${{ github.ref_type }}" == "tag" ]]; then | |
VERSION="${{ github.ref_name }}" | |
else | |
echo "Error: Unsupported event type" | |
exit 1 | |
fi | |
echo "VERSION=${VERSION}" >> $GITHUB_ENV | |
- name: Validate version input | |
id: validate_version | |
run: | | |
if [[ ! "${{ github.event.inputs.version }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
echo "Error: Version must follow the format vX.X.X" | |
exit 1 | |
fi | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Setup Docker buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Log into registry ${{ env.REGISTRY }} | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract Docker metadata | |
id: meta | |
uses: docker/metadata-action@v3 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: ${{ github.event.inputs.version }} | |
- name: Build and push Docker image | |
id: build-and-push | |
uses: docker/build-push-action@v3 | |
with: | |
context: . | |
file: .docker/Dockerfile | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
target: 'prod' # Cible le stage (prod) | |
cache-from: type=gha | |
cache-to: type=gha,mode=max |