Containerize for Pi: env-var config, compose stack, CI workflow
Some checks failed
build-and-deploy / build (push) Failing after 18s
Some checks failed
build-and-deploy / build (push) Failing after 18s
- Add app/config.py (12-factor, env-driven: DB/NATS/MinIO, URL-encoded pw) - Route database/ingestor/sources/alembic through config; kill hardcoded svc.cluster.local hostnames - Drop unused redis dependency - Add docker-compose.yml (timescaledb-postgis pg13 arm64 + optional nats) - Add .env.example, .dockerignore, .forgejo/workflows/build.yml (arm64 build+SSH deploy)
This commit is contained in:
parent
93b8b89639
commit
3d53ed2c1c
11 changed files with 175 additions and 17 deletions
42
app/config.py
Normal file
42
app/config.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
"""OSINT Dashboard — centralized configuration (12-factor, env-driven).
|
||||
|
||||
All infrastructure endpoints are read from the environment with
|
||||
container-friendly defaults. No secrets, hostnames, or cluster-specific
|
||||
addresses are hardcoded anywhere in the codebase.
|
||||
|
||||
Override per environment via environment variables (docker-compose,
|
||||
k8s ConfigMap/Secret, or systemd):
|
||||
|
||||
DB_USER, DB_PASSWORD, DB_HOST, DB_PORT, DB_NAME
|
||||
NATS_URL
|
||||
MINIO_ENDPOINT, MINIO_ACCESS_KEY, MINIO_SECRET_KEY, MINIO_SECURE
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from urllib.parse import quote_plus
|
||||
|
||||
# ── PostgreSQL ────────────────────────────────────────────────────────────
|
||||
# Defaults assume docker-compose/k8s service names. Override for your stack.
|
||||
DB_USER = os.getenv("DB_USER", "osint")
|
||||
DB_PASSWORD = os.getenv("DB_PASSWORD", "")
|
||||
DB_HOST = os.getenv("DB_HOST", "postgres")
|
||||
DB_PORT = os.getenv("DB_PORT", "5432")
|
||||
DB_NAME = os.getenv("DB_NAME", "osint_data")
|
||||
|
||||
# Async SQLAlchemy URL. Password is URL-encoded so special chars are safe.
|
||||
DATABASE_URL = (
|
||||
f"postgresql+asyncpg://"
|
||||
f"{DB_USER}:{quote_plus(DB_PASSWORD)}@{DB_HOST}:{DB_PORT}/{DB_NAME}"
|
||||
)
|
||||
|
||||
# ── NATS JetStream ─────────────────────────────────────────────────────────
|
||||
NATS_URL = os.getenv("NATS_URL", "nats://nats:4222")
|
||||
|
||||
# ── MinIO (document storage) ────────────────────────────────────────────────
|
||||
MINIO_ENDPOINT = os.getenv("MINIO_ENDPOINT", "minio:9000")
|
||||
MINIO_ACCESS_KEY = os.getenv("MINIO_ACCESS_KEY", "")
|
||||
MINIO_SECRET_KEY = os.getenv("MINIO_SECRET_KEY", "")
|
||||
# "false" / "0" / "no" (case-insensitive) → plain HTTP (e.g. local compose).
|
||||
MINIO_SECURE = os.getenv("MINIO_SECURE", "false").lower() not in ("false", "0", "no")
|
||||
|
|
@ -1,15 +1,7 @@
|
|||
import os
|
||||
|
||||
from sqlalchemy import MetaData, event, text
|
||||
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
|
||||
|
||||
DB_USER = os.getenv("DB_USER", "osint")
|
||||
DB_PASS = os.getenv("DB_PASSWORD", "")
|
||||
DB_HOST = os.getenv("DB_HOST", "osint-pgdb-rw.customer1.svc.cluster.local")
|
||||
DB_PORT = os.getenv("DB_PORT", "5432")
|
||||
DB_NAME = os.getenv("DB_NAME", "osint_data")
|
||||
|
||||
DATABASE_URL = f"postgresql+asyncpg://{DB_USER}:{DB_PASS}@{DB_HOST}:{DB_PORT}/{DB_NAME}"
|
||||
from config import DATABASE_URL
|
||||
|
||||
engine = create_async_engine(
|
||||
DATABASE_URL, echo=False, pool_size=5, max_overflow=10, pool_recycle=300
|
||||
|
|
|
|||
|
|
@ -11,17 +11,15 @@ from nats.errors import TimeoutError
|
|||
|
||||
from database import async_session
|
||||
from models import events as events_table
|
||||
from config import NATS_URL
|
||||
|
||||
logger = logging.getLogger("osint.ingestor")
|
||||
|
||||
# NATS connection settings
|
||||
NATS_URLS = "nats://osint-nats.customer1.svc.cluster.local:4222"
|
||||
NATS_URLS = NATS_URL
|
||||
NATS_STREAM = "events"
|
||||
NATS_DURABLE = "osint-ingestor"
|
||||
|
||||
# Redis cache settings
|
||||
REDIS_URL = "redis://osint-redis-sentinel.customer1.svc.cluster.local:26379/0"
|
||||
|
||||
|
||||
async def ingest_event(msg: dict):
|
||||
"""Ingest a single event from NATS into PostgreSQL."""
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ uvicorn[standard]>=0.34
|
|||
sqlalchemy[asyncio]>=2.0
|
||||
asyncpg>=0.30
|
||||
nats-py>=2.9
|
||||
redis[hiredis]>=5.2
|
||||
minio>=7.2
|
||||
pydantic>=2.10
|
||||
alembic>=1.14
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ import httpx
|
|||
import feedparser
|
||||
import nats
|
||||
|
||||
from config import NATS_URL
|
||||
|
||||
logger = logging.getLogger("osint.sources")
|
||||
|
||||
|
||||
|
|
@ -24,7 +26,7 @@ def _parse_rfc822(date_str: object) -> str | None:
|
|||
return None
|
||||
|
||||
# NATS connection
|
||||
NATS_URLS = "nats://osint-nats.customer1.svc.cluster.local:4222"
|
||||
NATS_URLS = NATS_URL
|
||||
|
||||
|
||||
async def publish_event(subject: str, event: dict):
|
||||
|
|
|
|||
Loading…
Reference in a new issue