From e580b8e615875c5821103e64800d34711a64368c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9C=B0=E9=9C=87?= Date: Thu, 9 Oct 2025 07:24:36 +0000 Subject: [PATCH] Add GitHub Actions CI to build and publish Docker images --- .github/workflows/docker-publish.yml | 75 ++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 .github/workflows/docker-publish.yml diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..92faf71 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,75 @@ +# SPDX-FileCopyrightText: 2025 Olivier 'reivilibre' +# +# SPDX-License-Identifier: GPL-3.0-or-later + +name: Docker Publish + +on: + push: + branches: + - main + tags: + - 'v*' + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-publish: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Extract version from tag + id: version + if: startsWith(github.ref, 'refs/tags/') + run: | + VERSION=${GITHUB_REF#refs/tags/v} + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "Tag version: $VERSION" + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + ${{ secrets.DOCKERHUB_USERNAME }}/pgcrab + tags: | + type=raw,value=latest,enable={{is_default_branch}} + type=semver,pattern={{version}} + flavor: | + latest=auto + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + cache-from: type=gha + cache-to: type=gha,mode=max + labels: ${{ steps.meta.outputs.labels }} + tags: ${{ steps.meta.outputs.tags }} \ No newline at end of file -- 2.50.1