# 16.4 LTS Databricks Image (Spark 3.5.2, Ubuntu 24.04.2 LTS)
FROM databricksruntime/standard:16.4-LTS

# Necessary from DBR 13.3 and on. https://askubuntu.com/questions/909277/avoiding-user-interaction-with-tzdata-when-installing-certbot-in-a-docker-contai.
ARG DEBIAN_FRONTEND=noninteractive

# noble-pgdg is specified for Ubuntu 24.04.
RUN apt-get update && apt-get install --no-install-recommends -y gnupg &&\
    apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8 &&\
    echo "deb http://apt.postgresql.org/pub/repos/apt/ noble-pgdg main" > /etc/apt/sources.list.d/pgdg.list &&\
    apt-get update && apt-get install --no-install-recommends -y software-properties-common postgresql-12 postgresql-client-12 postgresql-contrib-12 postgresql-12-postgis-3 postgresql-12-postgis-3-scripts &&\
    rm -rf /var/lib/apt/lists/*

COPY ../pg_hba.conf /etc/postgresql/12/main/
COPY ../postgresql.conf /etc/postgresql/12/main/

USER postgres

RUN /etc/init.d/postgresql start &&\
    psql --command "ALTER USER postgres WITH PASSWORD 'postgres';" &&\
    createdb -O postgres geoenrichment &&\
    psql --dbname=geoenrichment --command "CREATE EXTENSION postgis;"

EXPOSE 5432

USER root

# Databricks will ignore CMD & ENTRYPOINT