Skip to content

Build and Push Docker Image (v2.0.1) #32

Build and Push Docker Image (v2.0.1)

Build and Push Docker Image (v2.0.1) #32

Workflow file for this run

name: Build and Push Docker Image
run-name: Build and Push Docker Image (${{ github.ref_name }})
on:
push:
tags:
- "v*.*.*"
workflow_dispatch:
concurrency:
group: docker-publish
cancel-in-progress: false
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
persist-credentials: false
- name: Determine version
id: version
env:
REF_NAME: ${{ github.ref_name }}
EVENT_NAME: ${{ github.event_name }}
run: |
if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
TAG=$(git tag --sort=-version:refname --list 'v*.*' | head -1)
if [ -z "$TAG" ]; then
echo "::error::No version tag found"
exit 1
fi
git checkout "$TAG"
else
TAG="$REF_NAME"
fi
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
# Check if this version is the latest within the same major/major.minor
VERSION="${TAG#v}"
MAJOR=$(echo "$VERSION" | cut -d. -f1)
MINOR=$(echo "$VERSION" | cut -d. -f1-2)
LATEST_IN_MAJOR=$(git tag --list "v${MAJOR}.*.*" --sort=-version:refname | head -1)
if [ "$TAG" != "$LATEST_IN_MAJOR" ]; then
echo "skip_major=true" >> "$GITHUB_OUTPUT"
fi
LATEST_IN_MINOR=$(git tag --list "v${MINOR}.*" --sort=-version:refname | head -1)
if [ "$TAG" != "$LATEST_IN_MINOR" ]; then
echo "skip_minor=true" >> "$GITHUB_OUTPUT"
fi
- name: Set up QEMU
uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4.0.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
- name: Extract metadata
id: meta
uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6.0.0
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}},value=${{ steps.version.outputs.tag }}
${{ steps.version.outputs.skip_minor != 'true' && format('type=semver,pattern={{{{major}}}}.{{{{minor}}}},value={0}', steps.version.outputs.tag) || '' }}
${{ steps.version.outputs.skip_major != 'true' && format('type=semver,pattern={{{{major}}}},value={0}', steps.version.outputs.tag) || '' }}
type=raw,value=sha-${{ steps.version.outputs.sha }},priority=100
- name: Login to GHCR
uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4.0.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7.0.0
env:
DOCKER_BUILD_CHECKS_ANNOTATIONS: true
DOCKER_BUILD_SUMMARY: true
DOCKER_BUILD_RECORD_UPLOAD: false
with:
context: docker
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}