Skip to content

🔨 Build and Publish Docker Image #4

🔨 Build and Publish Docker Image

🔨 Build and Publish Docker Image #4

Workflow file for this run

name: 🔨 Build and Publish Docker Image
on:
workflow_dispatch:
push:
branches:
- "master"
tags:
- "v*"
schedule:
- cron: "54 3 * * *"
permissions:
packages: write
jobs:
build:
name: Build and Publish Docker Image to GitHub Packages
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set image tag
id: set_tag
run: |
# Définir le tag selon le contexte
if [[ $GITHUB_REF == refs/tags/* ]]; then
# Si c'est un tag Git, on utilise le tag comme version
IMAGE_TAG=${GITHUB_REF#refs/tags/}
else
# Sinon, on utilise "latest" pour les commits sur master
IMAGE_TAG="latest"
fi
IMAGE_NAME=ghcr.io/${{ github.repository }}:$IMAGE_TAG
IMAGE_NAME_LOWER=$(echo $IMAGE_NAME | tr '[:upper:]' '[:lower:]')
echo "IMAGE_NAME=$IMAGE_NAME_LOWER" >> $GITHUB_ENV
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ env.IMAGE_NAME }}