Files
zensical/.github/workflows/docker.yml
T
2026-04-16 18:06:31 +02:00

134 lines
4.4 KiB
YAML

# Copyright (c) 2025-2026 Zensical and contributors
# SPDX-License-Identifier: MIT
# All contributions are certified under the DCO
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
name: Docker
on:
pull_request:
types:
- closed
branches:
- master
jobs:
docker:
name: Build and push
if: |
github.event.pull_request.merged == true &&
startsWith(github.event.pull_request.head.ref, 'release/')
runs-on: ubuntu-latest
env:
IMAGE: ${{ github.event.repository.full_name }}
DOCKER_BUILDKIT: 1
DOCKER_BUILD_SUMMARY: false
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
ref: ${{ inputs.ref || github.sha }}
- name: Determine version
id: version
run: |
BRANCH="${{ github.event.pull_request.head.ref }}"
VERSION=${BRANCH#release/}
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Set up Buildx
uses: docker/setup-buildx-action@v4
- name: Login to DockerHub
uses: docker/login-action@v4
with:
username: zensical
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Generate tags and labels
id: meta
uses: docker/metadata-action@v6
env:
VERSION: ${{ steps.version.outputs.version }}
with:
images: ${{ env.IMAGE }}
tags: |
type=semver,value=${{ env.VERSION }},pattern={{version}}
type=semver,value=${{ env.VERSION }},pattern={{major}}.{{minor}}
type=semver,value=${{ env.VERSION }},pattern={{major}}
type=ref,event=pr
labels: |
org.opencontainers.image.title=Zensical
org.opencontainers.image.description=A modern static site generator
org.opencontainers.image.documentation=https://zensical.org/docs/
org.opencontainers.image.url=https://zensical.org
org.opencontainers.image.vendor=Zensical
org.opencontainers.image.version=${{ env.VERSION }}
org.opencontainers.image.licenses=MIT
- name: Prepare build
run: python scripts/prepare.py
- name: Build image
uses: docker/build-push-action@v7
with:
context: .
load: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ steps.meta.outputs.version }}
- name: Check image
working-directory: /tmp
env:
VERSION: ${{ steps.meta.outputs.version }}
run: |
docker run --rm -i -v $PWD:/docs $IMAGE:$VERSION new .
docker run --rm -i -v $PWD:/docs $IMAGE:$VERSION build
- name: Build and push image
uses: docker/build-push-action@v7
with:
context: .
platforms: |
linux/amd64
linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Inspect manifest
env:
VERSION: ${{ steps.meta.outputs.version }}
run: |
docker buildx imagetools inspect $IMAGE:$VERSION
- name: Inspect image
env:
VERSION: ${{ steps.meta.outputs.version }}
run: |
docker pull $IMAGE:$VERSION
docker image inspect $IMAGE:$VERSION