Skip to content

Docker

Docker #65

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@e40248c492a99ad409432e2ea978d7a2811f2e1f
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@e468171a9de216ec08956ac3ada2f0791b6bd435
# Login to GitHub Container Registry (GHCR)
- name: Log into GitHub Container Registry (GHCR)
if: github.event_name != 'pull_request'
uses: docker/login-action@3d100841f68d4548bf57e52eb27bd33ec5069f55
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@3d100841f68d4548bf57e52eb27bd33ec5069f55
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@be19121bfd18b9c1ac415d9571d4f67b9b357886
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@263435318d21b8e681c14492fe198d362a7d2c83
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}