From cb0ecfed47d0e77b340ec89342582bbc71ccd9eb Mon Sep 17 00:00:00 2001 From: Gabriele De Rosa Date: Thu, 2 Nov 2023 15:51:44 +0100 Subject: [PATCH 1/3] Build images only once before pushing to two registry --- .github/workflows/docker-publish.yml | 159 +++++---------------------- 1 file changed, 30 insertions(+), 129 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 69cb155..0eaf65d 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -63,13 +63,13 @@ jobs: docker build . --file Dockerfile fi - # Push daemon image to GitHub Packages. - push-daemon-to-github-packages: + # Push daemon image to registry. + push-daemon: # Ensure test job passes before pushing image. needs: test-daemon - name: Build Daemon & Push to GitHub Registry + name: Build Daemon & Push runs-on: ubuntu-latest permissions: contents: read @@ -85,80 +85,32 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - # Login against a Docker registry except on PR - # https://github.com/docker/login-action - - name: Log into registry ${{ env.GITHUB_REGISTRY }} + # Login to Docker Hub except on PR + - name: Login to Docker Hub if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: - registry: ${{ env.GITHUB_REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - # Extract metadata (tags, labels) for Docker - # https://github.com/docker/metadata-action - - name: Extract Docker metadata - id: meta - uses: docker/metadata-action@v5 - with: - images: ${{ env.GITHUB_REGISTRY }}/${{ env.IMAGE_NAME_DAEMON }} - tags: | - type=ref,event=branch - type=semver,pattern={{version}} - type=semver,pattern={{major}} - type=semver,pattern={{major}}.{{minor}} - type=semver,pattern={{major}}.{{minor}}.{{patch}} - - # Build and push Docker image with Buildx (don't push on PR) - # https://github.com/docker/build-push-action - - name: Build and push Docker image - uses: docker/build-push-action@v5 - with: - context: ./daemon/ - platforms: linux/amd64,linux/arm64,linux/arm/v7 - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - - # Push client image to GitHub Packages. - push-client-to-github-packages: - - # Ensure test job passes before pushing image. - needs: test-client - - name: Build Client & Push to GitHub Registry - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - - 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 + registry: ${{ env.DOCKER_REGISTRY }} + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} - # Login against a Docker registry except on PR - # https://github.com/docker/login-action - - name: Log into registry ${{ env.GITHUB_REGISTRY }} + # Login to GitHub Container Registry except on PR + - name: Login to GitHub Container Registry if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: registry: ${{ env.GITHUB_REGISTRY }} - username: ${{ github.actor }} + username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} # Extract metadata (tags, labels) for Docker - # https://github.com/docker/metadata-action - name: Extract Docker metadata id: meta uses: docker/metadata-action@v5 with: - images: ${{ env.GITHUB_REGISTRY }}/${{ env.IMAGE_NAME_CLIENT }} + images: | + ${{ env.IMAGE_NAME_DAEMON }} + ${{ env.GITHUB_REGISTRY }}/${{ env.IMAGE_NAME_DAEMON }} tags: | type=ref,event=branch type=semver,pattern={{version}} @@ -167,25 +119,23 @@ jobs: type=semver,pattern={{major}}.{{minor}}.{{patch}} # Build and push Docker image with Buildx (don't push on PR) - # https://github.com/docker/build-push-action - name: Build and push Docker image uses: docker/build-push-action@v5 with: - context: . + context: ./daemon/ platforms: linux/amd64,linux/arm64,linux/arm/v7 push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - # Push daemon image to Docker Hub. - push-daemon-to-docker-hub: + # Push client image to registry. + push-client: # Ensure test job passes before pushing image. - needs: test-daemon + needs: test-client - name: Build Daemon & Push to Docker Hub + name: Build Client & Push runs-on: ubuntu-latest - if: github.event_name != 'pull_request' # no need to exec same build two times during PR (no final push) permissions: contents: read packages: write @@ -200,9 +150,8 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - # Login against a Docker registry except on PR - # https://github.com/docker/login-action - - name: Log into registry ${{ env.DOCKER_REGISTRY }} + # Login to Docker Hub except on PR + - name: Login to Docker Hub if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: @@ -210,71 +159,24 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - # Extract metadata (tags, labels) for Docker - # https://github.com/docker/metadata-action - - name: Extract Docker metadata - id: meta - uses: docker/metadata-action@v5 - with: - images: ${{ env.IMAGE_NAME_DAEMON }} - tags: | - type=ref,event=branch - type=semver,pattern={{version}} - type=semver,pattern={{major}} - type=semver,pattern={{major}}.{{minor}} - type=semver,pattern={{major}}.{{minor}}.{{patch}} - - # Build and push Docker image with Buildx (don't push on PR) - # https://github.com/docker/build-push-action - - name: Build and push Docker image - uses: docker/build-push-action@v5 - with: - context: ./daemon/ - platforms: linux/amd64,linux/arm64,linux/arm/v7 - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - - # Push client image to Docker Hub. - push-client-to-docker-hub: - - # Ensure test job passes before pushing image. - needs: test-client - - name: Build Client & Push to Docker Hub - runs-on: ubuntu-latest - if: github.event_name != 'pull_request' # no need to exec same build two times during PR (no final push) - permissions: - contents: read - packages: write - - 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 - - # Login against a Docker registry except on PR - # https://github.com/docker/login-action - - name: Log into registry ${{ env.DOCKER_REGISTRY }} + # Login to GitHub Container Registry except on PR + - name: Login to GitHub Container Registry if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: - registry: ${{ env.DOCKER_REGISTRY }} - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} + registry: ${{ env.GITHUB_REGISTRY }} + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} # Extract metadata (tags, labels) for Docker - # https://github.com/docker/metadata-action - name: Extract Docker metadata id: meta uses: docker/metadata-action@v5 with: - images: ${{ env.IMAGE_NAME_CLIENT }} + images: + images: | + ${{ env.IMAGE_NAME_CLIENT }} + ${{ env.GITHUB_REGISTRY }}/${{ env.IMAGE_NAME_CLIENT }} tags: | type=ref,event=branch type=semver,pattern={{version}} @@ -283,7 +185,6 @@ jobs: type=semver,pattern={{major}}.{{minor}}.{{patch}} # Build and push Docker image with Buildx (don't push on PR) - # https://github.com/docker/build-push-action - name: Build and push Docker image uses: docker/build-push-action@v5 with: From 4761147620b82418ba3bdad6aba17b20ce247dbf Mon Sep 17 00:00:00 2001 From: Gabriele De Rosa Date: Thu, 2 Nov 2023 15:53:37 +0100 Subject: [PATCH 2/3] Bugfix: remove empty images field in docker-publish.yml --- .github/workflows/docker-publish.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 0eaf65d..c06d60d 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -173,7 +173,6 @@ jobs: id: meta uses: docker/metadata-action@v5 with: - images: images: | ${{ env.IMAGE_NAME_CLIENT }} ${{ env.GITHUB_REGISTRY }}/${{ env.IMAGE_NAME_CLIENT }} From 73e84b130ffcd1f0097a96e9e29e83c1663b2c66 Mon Sep 17 00:00:00 2001 From: Gabriele De Rosa Date: Thu, 2 Nov 2023 15:58:41 +0100 Subject: [PATCH 3/3] Minor: rename push names in action --- .github/workflows/docker-publish.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index c06d60d..906345c 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -69,7 +69,7 @@ jobs: # Ensure test job passes before pushing image. needs: test-daemon - name: Build Daemon & Push + name: Build & Push Daemon runs-on: ubuntu-latest permissions: contents: read @@ -134,7 +134,7 @@ jobs: # Ensure test job passes before pushing image. needs: test-client - name: Build Client & Push + name: Build & Push Client runs-on: ubuntu-latest permissions: contents: read