indexer/.forgejo/workflows/container.yaml
Ricardo (XenGi) Band 48e241d79a
Some checks failed
CI pipeline for ffd-indexer / checks (go test + golangci) (push) Successful in 2m22s
CI pipeline for ffd-indexer / build binaries + containers (push) Successful in 6m16s
CI pipeline for ffd-indexer / format (gofmt + nixfmt) (push) Failing after 1m27s
CI pipeline for ffd-indexer / integration (live scrape + Typesense) (push) Failing after 7m36s
enable experimental flakes
2026-10-01 00:40:56 +02:00

73 lines
3.1 KiB
YAML

name: Build and publish containers on tags
on:
push:
tags: ["**"]
workflow_dispatch:
jobs:
container:
name: build + publish ffd-indexer / ffd-metrics
runs-on: debian-stable
env:
# Forgejo does not auto-expose secrets as env vars; map it explicitly
# so the whole step (including the inner heredoc) can read it.
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
# nixos/nix:latest does not enable flakes/experimental features by default;
# the heredoc steps run `nix build`/`nix develop` and need them.
NIX_CONFIG: experimental-features = nix-command flakes
container:
image: nixos/nix:latest
steps:
- name: Checkout
run: |
set -euo pipefail
git config --global --add safe.directory "$PWD"
ref="${FORGEJO_HEAD_REF:-$FORGEJO_REF_NAME}"
git clone --depth 1 --branch "$ref" "${FORGEJO_SERVER_URL}/${FORGEJO_REPOSITORY}.git" .
# Build the two OCI images from the flake:
# .#container -> ffd-indexer (the scraper)
# .#container-metrics -> ffd-metrics (the metrics daemon)
# No container daemon/buildkit is needed: `nix develop` provides
# `skopeo`, which copies the resulting image tarballs straight to the
# Forgejo container registry.
#
# Both containers are pushed with the SAME tag; their names differ:
# git.xengi.de/ffd/indexer:<tag> ffd-indexer
# git.xengi.de/ffd/indexer-metrics:<tag> ffd-metrics
# Each also gets a `:latest` on its own name.
- name: Build and publish containers
run: |
set -euo pipefail
# Image tag: the git tag that triggered this run, without a leading
# "v" (e.g. v1.2.3 -> 1.2.3).
ref="${FORGEJO_REF_NAME:?}"
tag="${ref##*/}" # drop any refs/tags/ prefix
tag="${tag#v}" # drop a leading v
[ -n "$tag" ] || { echo "empty tag" >&2; exit 1; }
registry="${FORGEJO_SERVER_URL#https://}" # git.xengi.de
owner="${FORGEJO_REPOSITORY_OWNER:?}" # ffd
repo="${FORGEJO_REPOSITORY##*/}" # indexer
token="${REGISTRY_TOKEN:?}"
echo "publishing tag=$tag to $registry/$owner"
export registry owner repo tag token
nix develop --command bash <<'INNER'
set -euo pipefail
idx="$(nix build .#container --accept-flake-config --no-link --print-out-paths)"
met="$(nix build .#container-metrics --accept-flake-config --no-link --print-out-paths)"
# Same tag for both images, distinct names:
skopeo copy --dest-creds "$owner:$token" \
"docker-archive:$idx" "docker://$registry/$owner/$repo:$tag"
skopeo copy --dest-creds "$owner:$token" \
"docker-archive:$idx" "docker://$registry/$owner/$repo:latest"
skopeo copy --dest-creds "$owner:$token" \
"docker-archive:$met" "docker://$registry/$owner/${repo}-metrics:$tag"
skopeo copy --dest-creds "$owner:$token" \
"docker-archive:$met" "docker://$registry/$owner/${repo}-metrics:latest"
INNER