switch to docker hub publishing

This commit is contained in:
Michi 2025-01-29 21:14:30 +01:00 committed by GitHub
parent 40a5d21c42
commit 0185f482c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,98 +1,34 @@
name: Docker name: Build & Publish Image to Docker Hub (MultiArch)
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
on: on:
schedule:
- cron: '37 19 * * *'
push: push:
branches: [ "main" ] branches:
# Publish semver tags as releases. - "*"
tags: [ 'v*.*.*' ]
pull_request:
branches: [ "main" ]
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
jobs: jobs:
build: build:
name: push docker image to docker hub
runs-on: ubuntu-latest
steps:
- name: checkout
uses: "actions/checkout@v4"
runs-on: ubuntu-latest - name: Set up QEMU
permissions: uses: "docker/setup-qemu-action@v3"
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
steps: - name: Set up Docker Buildx
- name: Checkout repository uses: "docker/setup-buildx-action@v3"
uses: actions/checkout@v3
# Install the cosign tool except on PR - name: Login to Docker Hub
# https://github.com/sigstore/cosign-installer uses: "docker/login-action@v3"
- name: Install cosign with:
if: github.event_name != 'pull_request' username: "${{secrets.DOCKER_USERNAME}}"
uses: sigstore/cosign-installer@6e04d228eb30da1757ee4e1dd75a0ec73a653e06 #v3.1.1 password: "${{secrets.DOCKER_TOKEN}}"
with:
cosign-release: 'v2.1.1'
# Set up BuildKit Docker container builder to be able to build - name: Build and push image tags
# multi-platform images and export cache uses: "docker/build-push-action@v5"
# https://github.com/docker/setup-buildx-action with:
- name: Set up Docker Buildx context: "."
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 platforms: "linux/amd64,linux/arm64"
push: true
# Login against a Docker registry except on PR tags: |
# https://github.com/docker/login-action "michivonah/adguard-ddns-client:latest"
- name: Log into registry ${{ env.REGISTRY }} "michivonah/adguard-ddns-client:${{ github.ref_name }}"
if: github.event_name != 'pull_request'
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ${{ env.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@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# 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
id: build-and-push
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Sign the resulting Docker image digest except on PRs.
# This will only write to the public Rekor transparency log when the Docker
# repository is public to avoid leaking data. If you would like to publish
# transparency data even for private images, pass --force to cosign below.
# https://github.com/sigstore/cosign
- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
env:
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
TAGS: ${{ steps.meta.outputs.tags }}
DIGEST: ${{ steps.build-and-push.outputs.digest }}
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}