Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# See https://docs.github.com/en/actions/publishing-packages/publishing-docker-images

name: Build and push # to docker registries

on:
workflow_dispatch:
push:
branches:
- "main"
tags:
- "*"
release:
types: [published]

env:
IMAGE_NAME: paessler/multi-platform-probe

jobs:
docker_build:
name: Build and push
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
attestations: write
id-token: write
strategy:
fail-fast: false
matrix:
variant:
- name: dockerhub
registry: "docker.io"
- name: ghcr
registry: "ghcr.io"
steps:
- name: Set image for Docker
id: set-image
run: |
if [ "${{ matrix.variant.name }}" = "ghcr" ]; then
echo "IMAGE_TO_USE=${GITHUB_REPOSITORY}" >> $GITHUB_ENV
elif [ "${{ matrix.variant.name }}" == "dockerhub" ]; then
echo "IMAGE_TO_USE=${IMAGE_NAME}" >> $GITHUB_ENV
else
echo "Failing to resolve."
exit 1
fi

- name: Check out the repository
uses: actions/checkout@v5

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: |
- linux/amd64
- linux/arm64
- linux/arm/v7

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to Docker Hub
if: matrix.variant.name == 'dockerhub'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PUSH_TOKEN }}
registry: ${{ matrix.variant.registry }}

- name: Log in to Github Container Registry
if: matrix.variant.name == 'ghcr'
uses: docker/login-action@v3
with:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ${{ matrix.variant.registry }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ matrix.variant.registry }}/${{ env.IMAGE_TO_USE }}
tags: |
type=ref,event=branch
type=ref,event=tag
type=sha,format=short,prefix=

- name: Build and push Docker image
id: push
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64,linux/arm/v7

- name: Generate artifact attestation
if: matrix.variant.name == 'dockerhub'
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ matrix.variant.registry }}/${{ env.IMAGE_NAME }}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true

- name: Generate artifact attestation
if: matrix.variant.name == 'ghcr'
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ matrix.variant.registry }}/${{ github.repository }}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
4 changes: 2 additions & 2 deletions .github/workflows/dockerhub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
name: Push to Docker Hub

on:
release:
types: [published]
# release:
# types: [published]

env:
IMAGE_NAME: paessler/multi-platform-probe
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/github.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
name: Push to GitHub

on:
push:
branches: ["main"]
tags: ["*"]
# push:
# branches: ["main"]
# tags: ["*"]

env:
REGISTRY: ghcr.io
Expand Down