Skip to content

Docker

Docker #55

Workflow file for this run

name: Docker
on:
push:
tags: ['v*.*.*']
workflow_dispatch:
env:
# Use docker.io for Docker Hub if empty
REGISTRY_GHCR: ghcr.io
REGISTRY_DOCKERHUB: docker.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
actions: write
steps:
- name: Set version based on tag
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ env.RELEASE_VERSION }}
- name: Set Clean Version
id: set-clean-version
run: |
CLEAN_VERSION="${{ env.RELEASE_VERSION }}"
echo "VERSION=${CLEAN_VERSION}" >> $GITHUB_ENV
# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@3454372f43399081ed03b604cb2d021dabca52bb
with:
cosign-release: 'v2.2.4'
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
# Set up BuildKit Docker container builder to be able to build
# multi-platform images and export cache
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@e600775e527acba2317260cadb64b7e19efd5362
# Login to GitHub Container Registry (GHCR)
- name: Log into GitHub Container Registry (GHCR)
if: github.event_name != 'pull_request'
uses: docker/login-action@6d4b68b490aef8836e8fb5e50ee7b3bdfa5894f0
with:
registry: ${{ env.REGISTRY_GHCR }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Login to Docker Hub
- name: Log into Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@6d4b68b490aef8836e8fb5e50ee7b3bdfa5894f0
with:
registry: ${{ env.REGISTRY_DOCKERHUB }}
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@418e4b98bf2841bd337d0b24fe63cb36dc8afa55
with:
images: |
${{ env.REGISTRY_GHCR }}/${{ env.IMAGE_NAME }}
${{ env.REGISTRY_DOCKERHUB }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value={{date 'YYYYMMDD-HHmmss' tz='Asia/Seoul'}}
flavor: |
latest=true
- name: Build and push Docker image to both registries
id: build-and-push
uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1
with:
context: .
file: Dockerfile
build-args: |
VERSION=${{ env.VERSION }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64, linux/arm64
#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}