forked from Narcissus/docker-multi-platform-probe
114 lines
3.2 KiB
YAML
114 lines
3.2 KiB
YAML
# 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
|