diff --git a/.forgejo/workflows/build.yml b/.forgejo/workflows/build.yml index b2c2a0d..b51b488 100644 --- a/.forgejo/workflows/build.yml +++ b/.forgejo/workflows/build.yml @@ -1,21 +1,28 @@ -# Build changed OSINT images, publish to the Forgejo container registry, then -# redeploy on the Pi runner (docker.sock mounted). +# 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 or pulled on a normal merge — Postgres stays up. Rebuild it only -# when Dockerfile.pg changes, or via workflow_dispatch rebuild_pg. +# 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. # -# Public pull host: forgejo.siriusdevops.com (NOT ghcr.io) -# CI push host: 127.0.0.1:3000 — Cloudflare 413s layers ≳100MB on the public -# hostname, even from the Pi (hairpins out through the tunnel). # Images (public names): -# forgejo.siriusdevops.com/sirius/osint-dashboard -# forgejo.siriusdevops.com/sirius/osint-dashboard-pg -# forgejo.siriusdevops.com/sirius/osint-news-scraper -# forgejo.siriusdevops.com/sirius/osint-news-summarizer +# forgejo.siriusdevops.com/sirius/osint-dashboard:amd64- +# forgejo.siriusdevops.com/sirius/osint-dashboard-pg:amd64- +# forgejo.siriusdevops.com/sirius/osint-news-scraper:amd64- +# forgejo.siriusdevops.com/sirius/osint-news-summarizer:amd64- # # Optional repo variable FORGEJO_REGISTRY overrides the *public* pull host. -# Deploy still uses the local docker socket on the runner host (rpi). name: build-and-deploy @@ -35,17 +42,19 @@ on: env: PUBLIC_REGISTRY: ${{ vars.FORGEJO_REGISTRY || 'forgejo.siriusdevops.com' }} - PUSH_REGISTRY: 127.0.0.1:3000 + PUSH_REGISTRY: forgejo.forgejo.svc.cluster.local:3000 OWNER: sirius - # Keep compose project/volumes stable on the Pi - COMPOSE_PROJECT_NAME: osint-dashboard jobs: - build-push-deploy: - runs-on: docker - permissions: - contents: read - packages: write + 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 @@ -60,7 +69,6 @@ jobs: SCRAPER=0 SUM=0 PG=0 - COMPOSE=0 mark() { case "$1" in @@ -72,8 +80,6 @@ jobs: SCRAPER=1 ;; news/summerizer/*) SUM=1 ;; - docker-compose.yml|scripts/compose-reup.sh) - COMPOSE=1 ;; esac } @@ -108,9 +114,8 @@ jobs: echo "scraper=$SCRAPER" echo "summarizer=$SUM" echo "pg=$PG" - echo "compose=$COMPOSE" } >> "$GITHUB_OUTPUT" - echo "plan app=$APP scraper=$SCRAPER summarizer=$SUM pg=$PG compose=$COMPOSE" + echo "plan app=$APP scraper=$SCRAPER summarizer=$SUM pg=$PG" - name: Image refs id: img @@ -120,10 +125,11 @@ jobs: PUB="${PUBLIC_REGISTRY}" OWN="${OWNER}" SHA="${GITHUB_SHA::12}" + TAG="amd64-${SHA}" { echo "reg=$PUSH" echo "pub=$PUB" - echo "sha=$SHA" + echo "tag=$TAG" echo "app=$PUSH/$OWN/osint-dashboard" echo "pg=$PUSH/$OWN/osint-dashboard-pg" echo "scraper=$PUSH/$OWN/osint-news-scraper" @@ -131,113 +137,69 @@ jobs: } >> "$GITHUB_OUTPUT" echo "Push registry: $PUSH" echo "Public pull: $PUB" - echo "SHA tag: $SHA" + 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 with write:package. - if [ -z "${{ secrets.FORGEJO_TOKEN }}" ]; then - echo "Missing repo secret FORGEJO_TOKEN (user PAT, not GITHUB_TOKEN)" + # 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.FORGEJO_TOKEN }}" | docker login "${{ steps.img.outputs.reg }}" \ + 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 - APP="${{ steps.img.outputs.app }}" - SHA="${{ steps.img.outputs.sha }}" - docker build -f Dockerfile -t "${APP}:latest" -t "${APP}:${SHA}" \ - -t "localhost/osint-dashboard:latest" . - docker push "${APP}:latest" - docker push "${APP}:${SHA}" + 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 }}" - SHA="${{ steps.img.outputs.sha }}" - docker build -f news/scraper/Dockerfile -t "${IMG}:latest" -t "${IMG}:${SHA}" \ - -t "localhost/osint-news-scraper:latest" news/scraper - docker push "${IMG}:latest" - docker push "${IMG}:${SHA}" + 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 }}" - SHA="${{ steps.img.outputs.sha }}" - docker build -f news/summerizer/Dockerfile -t "${IMG}:latest" -t "${IMG}:${SHA}" \ - -t "localhost/osint-news-summarizer:latest" news/summerizer - docker push "${IMG}:latest" - docker push "${IMG}:${SHA}" + 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 - PG="${{ steps.img.outputs.pg }}" - SHA="${{ steps.img.outputs.sha }}" - if docker build -f Dockerfile.pg -t "${PG}:latest" -t "${PG}:${SHA}" \ - -t "localhost/osint-dashboard-pg:latest" .; then - docker push "${PG}:latest" - docker push "${PG}:${SHA}" - elif docker image inspect "localhost/osint-dashboard-pg:latest" >/dev/null 2>&1; then - echo "WARN: Dockerfile.pg build failed; keeping existing local pg image" - else - echo "ERROR: cannot build or find osint-dashboard-pg image" - exit 1 - fi - - - name: Deploy on runner host (compose) - run: | - set -ex - cd "${GITHUB_WORKSPACE}" - APP="${{ steps.plan.outputs.app }}" - SCRAPER="${{ steps.plan.outputs.scraper }}" - SUM="${{ steps.plan.outputs.summarizer }}" - PG="${{ steps.plan.outputs.pg }}" - COMPOSE="${{ steps.plan.outputs.compose }}" - - SVCS=() - [ "$APP" = "1" ] && SVCS+=(app ingester camera-service) - [ "$SCRAPER" = "1" ] && SVCS+=(news-scraper) - [ "$SUM" = "1" ] && SVCS+=(news-summarizer) - if [ "$COMPOSE" = "1" ]; then - # compose/script change: bounce workers so env/command updates apply. - # Still do not bounce Postgres. - for s in app ingester camera-service news-scraper news-summarizer; do - case " ${SVCS[*]} " in - *" $s "*) ;; - *) SVCS+=("$s") ;; - esac - done - fi - - chmod +x scripts/compose-reup.sh - if [ "$PG" = "1" ]; then - FORCE_RECREATE_DB=1 COMPOSE_PROJECT_NAME=osint-dashboard COMPOSE_PROFILES=ingest \ - scripts/compose-reup.sh "${SVCS[@]}" db - elif [ "${#SVCS[@]}" -gt 0 ]; then - COMPOSE_PROJECT_NAME=osint-dashboard COMPOSE_PROFILES=ingest \ - scripts/compose-reup.sh "${SVCS[@]}" - else - echo "No image or compose changes — leave running containers alone" - docker compose --profile ingest ps - fi - docker image prune -f - echo "osint-dashboard deploy done; db image left in place unless pg=1" + 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 }}\`" @@ -245,5 +207,23 @@ jobs: echo "- news-summarizer: \`${{ steps.plan.outputs.summarizer }}\`" echo "- pg (Timescale): \`${{ steps.plan.outputs.pg }}\`" echo - echo "Postgres is rebuilt/pulled only when \`Dockerfile.pg\` changes (or workflow_dispatch rebuild_pg)." + 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"