2.5 KiB · text History 2e34788
# Builds the site image and pushes it to the forge's own OCI registry on
# every push to master: the old .gitlab-ci.yml kaniko job, ported. Same
# Dockerfile (Zola build → static-web-server), and keel polls the :master
# tag for the rollout (argo-01-bos/presentato-ma).
#
# No secrets. The per-job token is accepted by the registry's /v2/token
# endpoint and authorized to push this repository's own image path.
name: image
on:
  push:
    branches: [master]

jobs:
  image:
    runs-on: arc-runner-set
    steps:
      - uses: actions/checkout@v4

      - uses: docker/setup-buildx-action@v3

      # An unset CI_REGISTRY resolves to the empty string, and
      # login-action then silently defaults to docker.io while
      # metadata-action builds a nonsense "/owner/repo" reference. Say
      # what is missing instead.
      - name: Check the registry variable is set
        env:
          CI_REGISTRY: ${{ vars.CI_REGISTRY }}
        run: |
          set -euo pipefail
          if [ -z "${CI_REGISTRY:-}" ]; then
            echo "CI_REGISTRY is not set for this repository." >&2
            echo "Set it as an Actions variable on the repo or its owner" >&2
            echo "(the registry hostname, ggr.neiam.co)." >&2
            exit 1
          fi
          echo "pushing to $CI_REGISTRY"

      # The username is ignored by the token endpoint but login-action
      # requires it to be non-empty.
      - uses: docker/login-action@v3
        with:
          registry: ${{ vars.CI_REGISTRY }}
          username: ci
          password: ${{ github.token }}

      # Push to the job's OWN repo path (<registry>/<owner>/<repo>); the
      # per-job token only grants push there.
      - uses: docker/metadata-action@v5
        id: meta
        with:
          images: ${{ vars.CI_REGISTRY }}/${{ github.repository }}
          tags: |
            type=sha,format=long
            type=ref,event=branch
            # Unconditional: `{{is_default_branch}}` evaluates false on this
            # forge. The workflow only runs on master anyway.
            type=raw,value=latest

      - uses: docker/build-push-action@v6
        with:
          context: .
          file: ./Dockerfile
          push: true
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}
          cache-from: type=registry,ref=${{ vars.CI_REGISTRY }}/${{ github.repository }}:buildcache
          cache-to: type=registry,ref=${{ vars.CI_REGISTRY }}/${{ github.repository }}:buildcache,mode=max