fix(ingest): skip known KEV/FIRMS rows; CI skips unchanged images
CISA KEV republished 1685 NIST URLs every 5 min; FIRMS re-inserted ~325k global hotspots every 15 min. Producer now skips URLs already in event_dedup and FIRMS CSVs that are unchanged (delta-only persist). CI rebuilds only images whose paths changed and never pulls/rebuilds Timescale or bounces osint-db unless Dockerfile.pg changes.
This commit is contained in:
parent
0406eb6b7b
commit
5651d251d0
9 changed files with 438 additions and 94 deletions
|
|
@ -1,6 +1,10 @@
|
|||
# Build all OSINT images, publish to the Forgejo container registry, then
|
||||
# Build changed OSINT images, publish to the Forgejo container registry, then
|
||||
# redeploy on the Pi runner (docker.sock mounted).
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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).
|
||||
|
|
@ -19,6 +23,15 @@ 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' }}
|
||||
|
|
@ -36,6 +49,68 @@ jobs:
|
|||
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
|
||||
COMPOSE=0
|
||||
|
||||
mark() {
|
||||
case "$1" in
|
||||
Dockerfile.pg)
|
||||
PG=1 ;;
|
||||
Dockerfile|app/*|alembic/*|alembic.ini)
|
||||
APP=1 ;;
|
||||
news/scraper/*)
|
||||
SCRAPER=1 ;;
|
||||
news/summerizer/*)
|
||||
SUM=1 ;;
|
||||
docker-compose.yml|scripts/compose-reup.sh)
|
||||
COMPOSE=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"
|
||||
echo "compose=$COMPOSE"
|
||||
} >> "$GITHUB_OUTPUT"
|
||||
echo "plan app=$APP scraper=$SCRAPER summarizer=$SUM pg=$PG compose=$COMPOSE"
|
||||
|
||||
- name: Image refs
|
||||
id: img
|
||||
|
|
@ -59,6 +134,7 @@ jobs:
|
|||
echo "SHA tag: $SHA"
|
||||
|
||||
- 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
|
||||
|
|
@ -71,6 +147,7 @@ jobs:
|
|||
-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 }}"
|
||||
|
|
@ -81,6 +158,7 @@ jobs:
|
|||
docker push "${APP}:${SHA}"
|
||||
|
||||
- name: Build news-scraper image
|
||||
if: steps.plan.outputs.scraper == '1'
|
||||
run: |
|
||||
set -ex
|
||||
IMG="${{ steps.img.outputs.scraper }}"
|
||||
|
|
@ -91,6 +169,7 @@ jobs:
|
|||
docker push "${IMG}:${SHA}"
|
||||
|
||||
- name: Build news-summarizer image
|
||||
if: steps.plan.outputs.summarizer == '1'
|
||||
run: |
|
||||
set -ex
|
||||
IMG="${{ steps.img.outputs.summarizer }}"
|
||||
|
|
@ -101,22 +180,17 @@ jobs:
|
|||
docker push "${IMG}:${SHA}"
|
||||
|
||||
- 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 }}"
|
||||
# Prefer rebuild so registry always has a current pg image. If packagecloud
|
||||
# is unreachable, fall back to whatever local image already exists.
|
||||
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; retagging existing local pg image into registry"
|
||||
docker tag "localhost/osint-dashboard-pg:latest" "${PG}:latest"
|
||||
docker tag "localhost/osint-dashboard-pg:latest" "${PG}:${SHA}"
|
||||
docker push "${PG}:latest"
|
||||
docker push "${PG}:${SHA}"
|
||||
echo "WARN: Dockerfile.pg build failed; keeping existing local pg image"
|
||||
else
|
||||
echo "ERROR: cannot build or find osint-dashboard-pg image"
|
||||
exit 1
|
||||
|
|
@ -126,39 +200,50 @@ jobs:
|
|||
run: |
|
||||
set -ex
|
||||
cd "${GITHUB_WORKSPACE}"
|
||||
# Pull from Forgejo registry into local tags compose expects, then up.
|
||||
# Compose file still uses localhost/* for stable local names; we mirror
|
||||
# registry tags so a cold host can recover via docker pull.
|
||||
REG="${{ steps.img.outputs.reg }}"
|
||||
PUB="${{ steps.img.outputs.pub }}"
|
||||
OWN="${{ env.OWNER }}"
|
||||
for name in osint-dashboard osint-dashboard-pg osint-news-scraper osint-news-summarizer; do
|
||||
docker pull "${REG}/${OWN}/${name}:latest" || true
|
||||
docker tag "${REG}/${OWN}/${name}:latest" "localhost/${name}:latest" || true
|
||||
docker tag "${REG}/${OWN}/${name}:latest" "${PUB}/${OWN}/${name}:latest" || true
|
||||
done
|
||||
# Do NOT set COMPOSE_PROJECT_NAME differently — volumes must stay
|
||||
# osint-dashboard_osint-pgdata (pinned by `name:` in compose).
|
||||
docker compose build --no-cache app ingester camera-service news-scraper news-summarizer || \
|
||||
docker compose build app ingester camera-service news-scraper news-summarizer
|
||||
# Name-pinned containers (container_name: osint-dashboard, …) collide
|
||||
# when compose tries to create instead of recreate — e.g. leftover from
|
||||
# a different working_dir or a half-failed previous up. down + rm -f
|
||||
# the known names, then up the full ingest profile.
|
||||
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
|
||||
COMPOSE_PROJECT_NAME=osint-dashboard COMPOSE_PROFILES=ingest \
|
||||
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 deployed; images also on ${PUB}/${OWN}/"
|
||||
echo "osint-dashboard deploy done; db image left in place unless pg=1"
|
||||
|
||||
- name: Summary
|
||||
if: always()
|
||||
run: |
|
||||
{
|
||||
echo "## Forgejo registry images"
|
||||
echo "Pushed via ${{ steps.img.outputs.reg }} (loopback). Pull publicly:"
|
||||
echo "- \`${{ steps.img.outputs.pub }}/sirius/osint-dashboard:latest\`"
|
||||
echo "- \`${{ steps.img.outputs.pub }}/sirius/osint-dashboard-pg:latest\`"
|
||||
echo "- \`${{ steps.img.outputs.pub }}/sirius/osint-news-scraper:latest\`"
|
||||
echo "- \`${{ steps.img.outputs.pub }}/sirius/osint-news-summarizer:latest\`"
|
||||
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
|
||||
echo "Postgres is rebuilt/pulled only when \`Dockerfile.pg\` changes (or workflow_dispatch rebuild_pg)."
|
||||
} >> "$GITHUB_STEP_SUMMARY"
|
||||
|
|
|
|||
Loading…
Reference in a new issue