Skip to content

Publishing Docker images

benoit74 edited this page Nov 30, 2026 · 2 revisions

openZIM Docker images are built and published to ghcr.io by a reusable workflow hosted in this repository: .github/workflows/docker-publish.yaml.

It replaces openzim/docker-publish-action (DPA), which is deprecated. See Migrating from docker-publish-action below.

Why a reusable workflow

DPA was a composite action: all its steps ran inside a single job, on a single runner. That makes it impossible to build each architecture on a runner of that architecture — multi-arch builds had to go through QEMU emulation, which is extremely slow for heavy images (hours for linux/arm64 on some scrapers), and it also made concurrent pushes to the same tag racy.

A reusable workflow can declare several jobs, so we follow Docker's documented pattern:

  1. compute-tag — decides which Docker tag (if any) must be published, from the event and the inputs
  2. platforms — maps each requested platform to a native GitHub-hosted runner (linux/amd64 → ubuntu-24.04, linux/arm64 → ubuntu-24.04-arm, anything else → QEMU on ubuntu-24.04)
  3. build — one job per platform, building and pushing by digest (no tag yet)
  4. merge — combines all digests into a single multi-arch manifest with docker buildx imagetools create and pushes the final tag(s)

Each arch is therefore built natively and in parallel, and the tag only ever appears once, when the complete manifest is pushed.

Usage

Publish on release

name: Publish released version

on:
  release:
    types: [published]

jobs:
  docker-publish:
    name: "Docker publish"
    if: github.repository == 'openzim/myproject'
    uses: openzim/overview/.github/workflows/docker-publish.yaml@v1
    with:
      image-name: openzim/myproject
      tag-pattern: /^v([0-9.]+)$/
      latest-on-tag: true
      platforms: linux/amd64 linux/arm64
    secrets:
      ghcr_username: ${{ secrets.GHCR_USERNAME }}
      ghcr_token: ${{ secrets.GHCR_TOKEN }}

Publish a dev image on every commit on the default branch

name: Publish Docker dev image

on:
  push:
    branches:
      - main
  workflow_dispatch:

jobs:
  docker-publish:
    name: "Publish Docker image"
    if: github.repository == 'openzim/myproject'
    uses: openzim/overview/.github/workflows/docker-publish.yaml@v1
    with:
      image-name: openzim/myproject
      on-main: dev
      platforms: linux/amd64 linux/arm64
    secrets:
      ghcr_username: ${{ secrets.GHCR_USERNAME }}
      ghcr_token: ${{ secrets.GHCR_TOKEN }}

Inputs

Input Required Default Usage
image-name yes Image path on ghcr.io, without the registry and without the tag. Ex. openzim/zimit publishes ghcr.io/openzim/zimit. Convention is to use dashes, not underscores.
context no . Folder to use as build context, relative to the repository root.
dockerfile no Dockerfile Dockerfile path, relative to context. Use ../ if it lives outside the context.
build-args no name=value pairs passed as --build-arg, one per line. The special value {tag} is replaced with the tag being published.
platforms no linux/amd64 Platforms to build for, space- or newline-separated. Ex. linux/amd64 linux/arm64.
on-main no Tag to publish for every commit on the default branch. Omit it if you don't want to publish non-tagged commits.
tag-pattern no Regular expression matched against git tags. Only matching tags trigger a publish. With a capture group, the group is used as Docker tag; without one, the whole git tag is used. Perl-style /…/ delimiters are accepted.
latest-on-tag no false Also publish :latest when tag-pattern matched (or when manual-tag is set).
manual-tag no Publish this exact tag, overriding on-main and tag-pattern.

Nothing is published when none of manual-tag, tag-pattern or on-main resolves to a tag — the workflow succeeds with a "nothing will be published" message, and the build/merge jobs are skipped.

If the computed tag already is latest, latest-on-tag is ignored (the tag is never pushed twice).

Secrets

Secret Usage
ghcr_username ghcr.io username — organization secret GHCR_USERNAME
ghcr_token ghcr.io token — organization secret GHCR_TOKEN, a PAT with write:packages

Both are required. They are passed explicitly (as in the examples above) rather than with secrets: inherit, so that what the workflow receives stays obvious in the caller.

Versioning

Pin a tag, not a branch:

    uses: openzim/overview/.github/workflows/docker-publish.yaml@v1

Tags are published in this repository. v1 is a moving major tag: backwards-compatible changes and fixes are pushed onto it, so callers receive them without having to change anything. Any change breaking caller compatibility — a renamed or removed input, a changed default, a different secret — gets a new major tag (v2), and the migration is documented on this page.

Referencing @main also works but is discouraged: every run would pick up whatever has just been merged, in every repository at once, with no known-good version to roll a single caller back to.

Guarding against forks

The workflow has no restrict-to input: guard the calling job with a plain if: instead, which is cheaper (the job is never scheduled on a fork) and more flexible:

    if: github.repository == 'openzim/myproject'

Migrating from docker-publish-action

Replace the whole steps: block of your job with a uses: + with: + secrets: call. A job calling a reusable workflow cannot have steps, so if your job did something else (checkout, build front-end assets…), that part has to move to its own job — the reusable workflow checks out the repository itself.

Input mapping

DPA input Becomes
image-name image-name, unchanged
registries dropped — always ghcr.io
credentials secrets: ghcr_username / ghcr_token (see above)
context context, unchanged
dockerfile dockerfile, unchanged
build-args build-args, unchanged (one name=value per line)
platforms platforms, unchanged
on-master renamed to on-main (same semantics: the repository's default branch, whatever its name)
tag-pattern tag-pattern, unchanged
latest-on-tag latest-on-tag, unchanged
manual-tag manual-tag, unchanged
restrict-to an if: github.repository == '…' on the calling job
webhook dropped — add your own step in a job with needs: docker-publish
repo_description dropped — docker.io only
repo_overview dropped — docker.io only

docker.io support and the two repo_* inputs are gone because no openZIM, Kiwix or Offspot repository publishes to Docker Hub any more — all of them list ghcr.io as their only registry.

Checklist

  • move the with: inputs per the table above, drop the removed ones
  • turn restrict-to into an if: on the job
  • rename on-master to on-main
  • replace credentials with the two secrets
  • remove the now-useless runs-on:, steps: and actions/checkout from the publishing job
  • if the job did more than publishing, split the rest into a separate job
  • consider adding a smoke-test job with needs: docker-publish that runs the published image on each platform (see zimit)

When it does not fit

The reusable workflow checks the repository out itself, on its own runners. An image whose build needs files produced earlier in the calling job — a npm run build output that the Dockerfile copies from ./dist, for instance — therefore cannot use it as is: the build jobs would only see a fresh checkout. Such a repository either keeps building and pushing in a single job with docker/login-action and docker/build-push-action directly, or publishes those artifacts and has the Dockerfile fetch them.

Everything the Dockerfile builds itself from the source tree is fine, including multi-stage builds that compile a frontend: that is the common case in our scrapers.

Reference pull requests

Notes

  • the first time an image is published, the resulting package is private: make it public from the organization's Packages settings if it is meant to be pulled anonymously

Clone this wiki locally