From 633c6e8f21fa118f09e73c37b33f67cac2a60554 Mon Sep 17 00:00:00 2001 From: Nick Marti Date: Mon, 1 Jul 2024 11:05:23 +0200 Subject: [PATCH 1/2] build and push image to ghcr.io --- .github/workflows/push.yml | 68 +++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 9eda78f..a23b27e 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -2,41 +2,47 @@ name: Build & Push Container Image on: push: branches: + - main - master tags: - - v* + - "v*" + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} jobs: - build: + # Push image to GitHub Packages. + container: runs-on: ubuntu-latest - env: - IMAGE: docker.io/vshn/modsecurity - QUAY_IMAGE: quay.io/vshn/modsecurity + permissions: + contents: read + packages: write + steps: - - uses: actions/checkout@v4 - with: - fetch-depth: "0" - - name: Set version latest - if: github.ref == 'refs/heads/master' - run: echo "VERSION=latest" >> ${GITHUB_ENV} - - name: Set version from tag - if: startsWith(github.ref, 'refs/tags/v') - run: echo "VERSION=$(echo ${GITHUB_REF#refs/tags/})" >> ${GITHUB_ENV} - - name: Build Image - run: docker build -t "${IMAGE}:${VERSION}" v3.3 - - name: Push Image to DockerHub - env: - DOCKER_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} - run: | - docker login docker.io --username "${DOCKER_USERNAME}" --password "${DOCKER_PASSWORD}" - docker push "${IMAGE}:${VERSION}" - - name: Push Image to Quay - env: - DOCKER_USERNAME: ${{ secrets.QUAY_USERNAME }} - DOCKER_PASSWORD: ${{ secrets.QUAY_PASSWORD }} - run: | - docker login quay.io --username "${DOCKER_USERNAME}" --password "${DOCKER_PASSWORD}" - docker tag "${IMAGE}:${VERSION}" ${QUAY_IMAGE}:${VERSION} - docker push "${QUAY_IMAGE}:${VERSION}" + - uses: actions/checkout@v4 + with: + fetch-depth: "0" + - name: Log in to the Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Determine Tags & Labels based on Git ref + id: meta + uses: docker/metadata-action@v5 + with: + images: "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" + + - name: Build & Push container image + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + addLatest: true From 2f7d601c40a0fb6afca62c82d8ae05466ac60861 Mon Sep 17 00:00:00 2001 From: Nick Marti Date: Mon, 1 Jul 2024 11:05:43 +0200 Subject: [PATCH 2/2] build and push image to ghcr.io --- .github/workflows/push.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index a23b27e..fb91550 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -2,7 +2,6 @@ name: Build & Push Container Image on: push: branches: - - main - master tags: - "v*"