Skip to content

ci: add image build

ci: add image build #1

Workflow file for this run

name: Build Docker image
on:
push:
tags:
- "v*"
# Run on pull requests to verify that the image still builds correctly
# The image is not pushed on pull requests
pull_request:
permissions:
packages: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- name: Set up QEMU
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0
- name: Login to GHCR
# Login is only needed when the image is pushed
if: ${{ startsWith(github.ref, 'refs/tags') }}
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3.2.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
with:
flavor: |
latest=false
# This pushes to the GitHub registry only
# It can be extended to https://hub.docker.com/r/gohugoio/hugo once a maintainer
# adds a Dockerhub token with push access to the GitHub action secrets. Then add
# "gohugoio/hugo" here
images: |
ghcr.io/gohugoio/hugo
# Tag the image with the v-prefixed semver version on tags, tag with the ref on PRs
tags: |
type=semver,pattern={{raw}}
type=ref,event=pr
- name: Build and push
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
with:
platforms: linux/amd64,linux/arm64
# Push for git tags only
push: ${{ startsWith(github.ref, 'refs/tags') }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}