Skip to content

Docker

Docker #3015

name: Docker
on:
schedule:
- cron: "14 */2 * * *"
workflow_dispatch:
push:
branches: ["main"]
tags: ["v*.*.*"]
pull_request:
branches: ["main"]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get Git commit timestamps
id: commit-meta
run: |-
TIMESTAMP=$(git log -1 --pretty=%ct)
echo "timestamp=$TIMESTAMP" >> $GITHUB_OUTPUT
echo "date3339=$(date --utc --rfc-3339=seconds -d "@$TIMESTAMP" | sed 's/ /T/')" >> $GITHUB_OUTPUT
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f # v5.8.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
labels: |-
org.opencontainers.image.created=${{ steps.commit-meta.outputs.date3339 }}
annotations: |-
manifest:org.opencontainers.image.created=${{ steps.commit-meta.outputs.date3339 }}
# 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@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.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
# Disable attestation so scheduled builds can yield exactly the same image if the source tree and remote files
# do not change.
provenance: false
sbom: false
env:
SOURCE_DATE_EPOCH: ${{ steps.commit-meta.outputs.timestamp }}