# Cluster build of the OSINT Postgres image (amd64).
#
# Identical to `Dockerfile.pg` in sirius/osint-dashboard EXCEPT the base image
# is pinned to bookworm. The upstream `FROM postgres:16` now resolves to Debian
# trixie, where postgresql-16-postgis-3 (3.7.0+pgdg13) fails to load against
# PostgreSQL 16.15:
#   could not load library "/usr/lib/postgresql/16/lib/postgis-3.so":
#   undefined symbol: heap_datum_check
# On bookworm (+pgdg12) both extensions load and create_hypertable() works.
FROM postgres:16-bookworm

RUN apt-get update && apt-get install -y --no-install-recommends \
        ca-certificates curl gnupg lsb-release && \
    curl -fsSL https://packagecloud.io/install/repositories/timescale/timescaledb/script.deb.sh | bash && \
    apt-get update && apt-get install -y --no-install-recommends \
        postgresql-16-postgis-3 timescaledb-2-postgresql-16 && \
    mkdir -p /etc/postgresql/16/main/conf.d && \
    echo "shared_preload_libraries = 'timescaledb'" > /etc/postgresql/16/main/conf.d/timescaledb.conf && \
    rm -rf /var/lib/apt/lists/*

# The official postgres entrypoint remains the CMD and handles
# POSTGRES_USER / POSTGRES_DB / POSTGRES_PASSWORD and pg_hba setup.
