From 74843d13aaed3e6a0e3dccd0b69e91c6cac33378 Mon Sep 17 00:00:00 2001 From: gkits <56302678+gKits@users.noreply.github.com> Date: Sun, 24 Mar 2024 00:37:29 +0100 Subject: [PATCH] ci: update pipeline to publish image publicly --- .github/workflows/deploy-to-ghcr.yml | 60 ++++++++++++++++++---------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/.github/workflows/deploy-to-ghcr.yml b/.github/workflows/deploy-to-ghcr.yml index 39577fb..8a4607f 100644 --- a/.github/workflows/deploy-to-ghcr.yml +++ b/.github/workflows/deploy-to-ghcr.yml @@ -1,29 +1,45 @@ -name: Build and publish a Docker image to ghcr.io -on: +name: Publish Docker image - # publish on releases, e.g. v2.1.13 (image tagged as "2.1.13" - "v" prefix is removed) +on: release: - types: [ published ] - - # publish on pushes to the main branch (image tagged as "latest") - push: - branches: - - master + types: [published] jobs: - docker_publish: - runs-on: "ubuntu-20.04" - + push_to_registries: + name: Push Docker image to multiple registries + runs-on: ubuntu-latest + permissions: + packages: write + contents: read steps: - - uses: actions/checkout@v2 + - name: Check out the repo + uses: actions/checkout@v4 + + - name: Log in to Docker Hub + uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: | + my-docker-hub-namespace/my-docker-hub-repository + ghcr.io/${{ github.repository }} - # https://github.com/marketplace/actions/push-to-ghcr - - name: Build and publish a Docker image for ${{ github.repository }} - uses: macbre/push-to-ghcr@master + - name: Build and push Docker images + uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 with: - image_name: ${{ github.repository }} # it will be lowercased internally - github_token: ${{ secrets.GITHUB_TOKEN }} - # optionally push to the Docker Hub (docker.io) - # docker_io_token: ${{ secrets.DOCKER_IO_ACCESS_TOKEN }} # see https://hub.docker.com/settings/security - # customize the username to be used when pushing to the Docker Hub - # docker_io_user: foobar # see https://github.com/macbre/push-to-ghcr/issues/14 + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }}