From c761805b56c320ba17af62546eedc89ae7894ffd Mon Sep 17 00:00:00 2001 From: Franz Kafka Date: Sat, 21 Mar 2026 19:24:04 +0000 Subject: [PATCH] ci: add Docker build + push workflow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Forgejo Actions workflow that builds and pushes Docker images on: - Push to main → tagged 'latest' + short SHA - Tags matching 'v*' → semver tags (1.0.0, 1.0, latest) - PRs → build only (no push) Pushes to both GHCR and Docker Hub with GitHub Actions cache. Required secrets: - DOCKERHUB_USERNAME: Docker Hub username - DOCKERHUB_PASSWORD: Docker Hub access token - GITHUB_TOKEN: automatically provided by Forgejo (or set manually for GHCR) Note: Requires a Forgejo Actions runner to be registered. See: https://forgejo.org/docs/latest/user/actions/#runner-setup --- .forgejo/workflows/docker.yml | 60 +++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 .forgejo/workflows/docker.yml diff --git a/.forgejo/workflows/docker.yml b/.forgejo/workflows/docker.yml new file mode 100644 index 0000000..52bd4d4 --- /dev/null +++ b/.forgejo/workflows/docker.yml @@ -0,0 +1,60 @@ +name: Build and Push Docker Image + +on: + push: + branches: [main] + tags: ['v*'] + pull_request: + branches: [main] + +env: + IMAGE_NAME: kafka + +jobs: + build-and-push: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }} + docker.io/${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=sha,prefix= + + - name: Login to GHCR + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Login to Docker Hub + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: docker.io + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max