Skip to content
This repository has been archived by the owner on Oct 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #457 from derogab/single-build-double-push
Browse files Browse the repository at this point in the history
Build images only once before pushing to two registry
  • Loading branch information
derogab authored Nov 2, 2023
2 parents 9a3127b + 73e84b1 commit 931058d
Showing 1 changed file with 29 additions and 129 deletions.
158 changes: 29 additions & 129 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 & Push Daemon
runs-on: ubuntu-latest
permissions:
contents: read
Expand All @@ -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}}
Expand All @@ -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 & Push Client
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
Expand All @@ -200,81 +150,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.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:
registry: ${{ env.DOCKER_REGISTRY }}
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: |
${{ env.IMAGE_NAME_CLIENT }}
${{ env.GITHUB_REGISTRY }}/${{ env.IMAGE_NAME_CLIENT }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
Expand All @@ -283,7 +184,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:
Expand Down

0 comments on commit 931058d

Please sign in to comment.