ARG BASE_IMAGE=debian:bookworm
FROM ${BASE_IMAGE}
ARG DEBIAN_FRONTEND=noninteractive

ARG POSTGRES_VERSION=16
ARG DEB_PACKAGE_REL_PATH=packages/postgresql-16-documentdb-1_1.0.0_amd64.deb

RUN apt-get update

RUN apt-get install -y --no-install-recommends \
    make \
    wget \
    gnupg2 \
    lsb-release \
    ca-certificates \
    locales \
    python3

RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \
    locale-gen en_US.UTF-8

ENV LC_ALL=en_US.UTF-8
ENV LANGUAGE=en_US
ENV LC_COLLATE=en_US.UTF-8
ENV LC_CTYPE=en_US.UTF-8
ENV LANG=en_US.UTF-8

RUN echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main ${POSTGRES_VERSION}" > /etc/apt/sources.list.d/pgdg.list && \
    wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -

# actual dependencies of the package
RUN apt-get update && apt-get install -y \
    postgresql-${POSTGRES_VERSION} \
    postgresql-${POSTGRES_VERSION}-cron \
    postgresql-${POSTGRES_VERSION}-pgvector \
    postgresql-${POSTGRES_VERSION}-postgis-3 \
    postgresql-${POSTGRES_VERSION}-rum

WORKDIR /test-install

COPY . /test-install

RUN dpkg -i ${DEB_PACKAGE_REL_PATH}

COPY packaging/test_packages/test-install-entrypoint.sh /usr/local/bin/test-install-entrypoint.sh

ENTRYPOINT ["test-install-entrypoint.sh"]