osint-dashboard/.forgejo/workflows/build.yml
tui-design 88b95f6a95 ci: log in with a write:package PAT called REGISTRY_TOKEN
Run 1364 got as far as building and naming the image, then every blob upload
401'd with 'unauthorized: reqPackageAccess'. Forgejo's container routes run
reqPackageAccess(Write), which checks the login token's own scope list for
write:package and rejects a scoped token without it — the token only has to
be scoped, since an unscoped token skips the check. The repo's FORGEJO_TOKEN
secret is such a scoped token.

FORGEJO_/GITHUB_ are reserved secret prefixes, so that name cannot be created
or updated through the API; the workflow now reads REGISTRY_TOKEN instead.
2026-11-17 15:10:13 -05:00

229 lines
8.9 KiB
YAML

# Build changed OSINT images and publish them to the Forgejo container
# registry. Deployment is NOT done here: the cluster (homek8s, namespace
# `osint`) runs amd64 images pinned by tag in apps/base/osint/*.yaml, so the
# final step prints the tag to pin and a human opens that manifest PR.
#
# Unchanged images are skipped. Dockerfile.pg / osint-dashboard-pg is NOT
# rebuilt on a normal merge — Postgres stays up. Rebuild it only when
# Dockerfile.pg changes, or via workflow_dispatch rebuild_pg.
#
# Registry endpoints
# CI push host: forgejo.forgejo.svc.cluster.local:3000 — plain HTTP
# ClusterIP, whitelisted by --insecure-registry on the amd64
# runner's dind daemon. 127.0.0.1:3000 stopped working when
# Forgejo moved into k8s: inside an in-cluster job pod, loopback
# is the pod itself, so login died with "connection refused".
# Public pull: forgejo.siriusdevops.com (HTTPS via Cloudflare; kubelet pulls
# from here). Do NOT push here — Cloudflare 413s layers ≳100MB.
#
# Images (public names):
# forgejo.siriusdevops.com/sirius/osint-dashboard:amd64-<sha12>
# forgejo.siriusdevops.com/sirius/osint-dashboard-pg:amd64-<sha12>
# forgejo.siriusdevops.com/sirius/osint-news-scraper:amd64-<sha12>
# forgejo.siriusdevops.com/sirius/osint-news-summarizer:amd64-<sha12>
#
# Optional repo variable FORGEJO_REGISTRY overrides the *public* pull host.
name: build-and-deploy
on:
push:
branches: [main, master]
workflow_dispatch:
inputs:
rebuild_pg:
description: Rebuild Timescale+PostGIS (Dockerfile.pg)
type: boolean
default: false
rebuild_all:
description: Rebuild every app image (ignore path filter)
type: boolean
default: false
env:
PUBLIC_REGISTRY: ${{ vars.FORGEJO_REGISTRY || 'forgejo.siriusdevops.com' }}
PUSH_REGISTRY: forgejo.forgejo.svc.cluster.local:3000
OWNER: sirius
jobs:
build-push:
# `amd64` only exists on siriussec-amd64, which is also the node the
# workloads run on — so the images are built on the architecture they are
# pulled to. `runs-on: docker` matched the Pi's arm64 runner, which
# produced images the amd64 cluster could never run.
# No job-level `permissions:` block: Forgejo ignores it (it emits a
# pre-execution warning) and the push authenticates with the FORGEJO_TOKEN
# user PAT instead, because the package registry rejects the Actions token.
runs-on: amd64
steps:
- name: Checkout
uses: https://code.forgejo.org/actions/checkout@v4
with:
fetch-depth: 50
- name: Plan image builds
id: plan
run: |
set -euo pipefail
APP=0
SCRAPER=0
SUM=0
PG=0
mark() {
case "$1" in
Dockerfile.pg)
PG=1 ;;
Dockerfile|app/*|alembic/*|alembic.ini)
APP=1 ;;
news/scraper/*)
SCRAPER=1 ;;
news/summerizer/*)
SUM=1 ;;
esac
}
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
APP=1; SCRAPER=1; SUM=1
if [ "${{ github.event.inputs.rebuild_all }}" = "true" ]; then
APP=1; SCRAPER=1; SUM=1; PG=1
fi
if [ "${{ github.event.inputs.rebuild_pg }}" = "true" ]; then
PG=1
fi
else
BEFORE="${{ github.event.before }}"
SHA="${GITHUB_SHA}"
ZEROS="0000000000000000000000000000000000000000"
if [ -z "$BEFORE" ] || [ "$BEFORE" = "$ZEROS" ]; then
echo "No previous SHA — build app images, skip pg"
APP=1; SCRAPER=1; SUM=1
elif ! git cat-file -e "${BEFORE}^{commit}" 2>/dev/null; then
echo "Previous SHA $BEFORE not in history — build app images, skip pg"
APP=1; SCRAPER=1; SUM=1
else
while IFS= read -r f; do
[ -z "$f" ] && continue
mark "$f"
done < <(git diff --name-only "$BEFORE" "$SHA")
fi
fi
{
echo "app=$APP"
echo "scraper=$SCRAPER"
echo "summarizer=$SUM"
echo "pg=$PG"
} >> "$GITHUB_OUTPUT"
echo "plan app=$APP scraper=$SCRAPER summarizer=$SUM pg=$PG"
- name: Image refs
id: img
run: |
set -euo pipefail
PUSH="${PUSH_REGISTRY}"
PUB="${PUBLIC_REGISTRY}"
OWN="${OWNER}"
SHA="${GITHUB_SHA::12}"
TAG="amd64-${SHA}"
{
echo "reg=$PUSH"
echo "pub=$PUB"
echo "tag=$TAG"
echo "app=$PUSH/$OWN/osint-dashboard"
echo "pg=$PUSH/$OWN/osint-dashboard-pg"
echo "scraper=$PUSH/$OWN/osint-news-scraper"
echo "summarizer=$PUSH/$OWN/osint-news-summarizer"
} >> "$GITHUB_OUTPUT"
echo "Push registry: $PUSH"
echo "Public pull: $PUB"
echo "Image tag: $TAG"
- name: Login to Forgejo registry
if: steps.plan.outputs.app == '1' || steps.plan.outputs.scraper == '1' || steps.plan.outputs.summarizer == '1' || steps.plan.outputs.pg == '1'
run: |
set -euo pipefail
# GITHUB_TOKEN login "succeeds" but blob uploads 401 (Forgejo packages
# reject the Actions token). Use a user PAT.
# The PAT must carry the `write:package` scope: Forgejo mints a push
# token even without it and then rejects every blob upload with
# `unauthorized: reqPackageAccess` (routers/api/packages/api.go
# reqPackageAccess -> AccessTokenScopeWritePackage).
# Name is REGISTRY_TOKEN, not FORGEJO_TOKEN: Forgejo reserves the
# FORGEJO_/GITHUB_ prefixes and refuses to create or update them via
# the API.
if [ -z "${{ secrets.REGISTRY_TOKEN }}" ]; then
echo "Missing repo secret REGISTRY_TOKEN (user PAT with write:package, not GITHUB_TOKEN)"
exit 1
fi
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login "${{ steps.img.outputs.reg }}" \
-u sirius --password-stdin
- name: Build application image (api / ingester / cameras)
if: steps.plan.outputs.app == '1'
run: |
set -ex
IMG="${{ steps.img.outputs.app }}"
TAG="${{ steps.img.outputs.tag }}"
docker build -f Dockerfile -t "${IMG}:${TAG}" .
docker push "${IMG}:${TAG}"
- name: Build news-scraper image
if: steps.plan.outputs.scraper == '1'
run: |
set -ex
IMG="${{ steps.img.outputs.scraper }}"
TAG="${{ steps.img.outputs.tag }}"
docker build -f news/scraper/Dockerfile -t "${IMG}:${TAG}" news/scraper
docker push "${IMG}:${TAG}"
- name: Build news-summarizer image
if: steps.plan.outputs.summarizer == '1'
run: |
set -ex
IMG="${{ steps.img.outputs.summarizer }}"
TAG="${{ steps.img.outputs.tag }}"
docker build -f news/summerizer/Dockerfile -t "${IMG}:${TAG}" news/summerizer
docker push "${IMG}:${TAG}"
- name: Build / refresh Timescale+PostGIS image
if: steps.plan.outputs.pg == '1'
run: |
set -ex
IMG="${{ steps.img.outputs.pg }}"
TAG="${{ steps.img.outputs.tag }}"
docker build -f Dockerfile.pg -t "${IMG}:${TAG}" .
docker push "${IMG}:${TAG}"
- name: Summary
if: always()
run: |
TAG="${{ steps.img.outputs.tag }}"
PUB="${{ steps.img.outputs.pub }}"
{
echo "## Image plan"
echo "- app: \`${{ steps.plan.outputs.app }}\`"
echo "- news-scraper: \`${{ steps.plan.outputs.scraper }}\`"
echo "- news-summarizer: \`${{ steps.plan.outputs.summarizer }}\`"
echo "- pg (Timescale): \`${{ steps.plan.outputs.pg }}\`"
echo
if [ -n "$TAG" ]; then
echo "## Pin in homek8s (apps/base/osint)"
echo "Pushed tag: \`${TAG}\`. Set the workload images in"
echo "\`apps/base/osint/kustomization.yaml\` to:"
echo
echo '```yaml'
echo "images:"
echo " - name: ${PUB}/${OWNER}/osint-dashboard"
echo " newTag: ${TAG}"
echo " - name: ${PUB}/${OWNER}/osint-news-scraper"
echo " newTag: ${TAG}"
echo " - name: ${PUB}/${OWNER}/osint-news-summarizer"
echo " newTag: ${TAG}"
echo '```'
else
echo "_No tag computed — the earlier steps failed before Image refs._"
fi
echo
echo "Postgres is rebuilt only when \`Dockerfile.pg\` changes (or workflow_dispatch rebuild_pg)."
} >> "$GITHUB_STEP_SUMMARY"