From 03c4955ef70435500eb0e2b82b9feb0b88c55573 Mon Sep 17 00:00:00 2001 From: Manuel Stahl Date: Thu, 18 Apr 2024 16:37:56 +0200 Subject: [PATCH] Push docker images also to ghcr.io Fixes #350. Change-Id: Ifdb7e4e7fda46efd0ed9e760587033f52ff4a130 --- .github/workflows/docker-release.yml | 48 ++++++++++++++--------- .github/workflows/test-docker-image.yml | 51 ------------------------- 2 files changed, 29 insertions(+), 70 deletions(-) delete mode 100644 .github/workflows/test-docker-image.yml diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml index 682b201..e390137 100644 --- a/.github/workflows/docker-release.yml +++ b/.github/workflows/docker-release.yml @@ -1,51 +1,61 @@ -name: Create docker image(s) and push to docker hub +name: Create docker image(s) and push to docker hub and ghcr.io +# see https://docs.github.com/en/actions/publishing-packages/publishing-docker-images#publishing-images-to-docker-hub-and-github-packages on: push: # Sequence of patterns matched against refs/heads # prettier-ignore - branches: + branches: # Push events on master branch - master # Sequence of patterns matched against refs/tags - tags: + tags: - '[0-9]+\.[0-9]+\.[0-9]+' # Push events to 0.X.X tag jobs: docker: + name: Push Docker image to multiple registries runs-on: ubuntu-latest + permissions: + packages: write + contents: read steps: - name: Checkout 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: Login to DockerHub uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Calculate docker image tag - id: set-tag - run: | - case "${GITHUB_REF}" in - refs/heads/master|refs/heads/main) - tag=latest - ;; - refs/tags/*) - tag=${GITHUB_REF#refs/tags/} - ;; - *) - tag=${GITHUB_SHA} - ;; - esac - echo "::set-output name=tag::$tag" + + - name: Login to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: | + awesometechnologies/synapse-admin + ghcr.io/${{ github.repository }} + - name: Build and Push Tag uses: docker/build-push-action@v5 with: context: . push: true - tags: "awesometechnologies/synapse-admin:${{ steps.set-tag.outputs.tag }}" + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} platforms: linux/amd64,linux/arm64 diff --git a/.github/workflows/test-docker-image.yml b/.github/workflows/test-docker-image.yml deleted file mode 100644 index 778385d..0000000 --- a/.github/workflows/test-docker-image.yml +++ /dev/null @@ -1,51 +0,0 @@ -name: Test docker image creation - -on: - push: - # Sequence of patterns matched against refs/heads - # prettier-ignore - branches: - # Push events on branch fix_docker_cd - - fix_docker_cd - # Sequence of patterns matched against refs/tags - tags: - - '[0-9]+\.[0-9]+\.[0-9]+' # Push events to 0.X.X tag - -jobs: - docker: - runs-on: ubuntu-latest - - steps: - - name: Checkout - 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: Login to DockerHub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Calculate docker image tag - id: set-tag - run: | - case "${GITHUB_REF}" in - refs/heads/master|refs/heads/main) - tag=latest - ;; - refs/tags/*) - tag=${GITHUB_REF#refs/tags/} - ;; - *) - tag=${GITHUB_SHA} - ;; - esac - echo "::set-output name=tag::$tag" - - name: Build and Push Tag - uses: docker/build-push-action@v5 - with: - context: . - push: false - tags: "awesometechnologies/synapse-admin:${{ steps.set-tag.outputs.tag }}" - platforms: linux/amd64,linux/arm64