# Étape 1 : builder temporaire pour compiler pgTAP
FROM debian:trixie AS builder

# Installer les outils nécessaires pour compiler pgTAP
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        git \
        build-essential \
        ca-certificates \
        postgresql-server-dev-17 \
        make

# Cloner et compiler pgTAP
RUN git clone --depth 1 https://github.com/theory/pgtap.git /usr/src/pgtap && \
    cd /usr/src/pgtap && \
    make && \
    make install DESTDIR=/pgtap-dist

# Étape 2 : image finale PostgreSQL propre
FROM postgres:17.6

RUN set -eux; \
  apt-get update; \
  apt-get install -y --no-install-recommends \
    locales; \
  sed -i '/fr_FR.UTF-8/s/^# //' /etc/locale.gen; \
  locale-gen

ENV TZ=Europe/Paris
ENV LANG=fr_FR.UTF-8
ENV LANGUAGE=fr_FR:fr
ENV LC_ALL=fr_FR.UTF-8

RUN set -eux; \
  apt-get update; \
  apt-get install -y --no-install-recommends \
    postgresql-postgis

# Copier uniquement les fichiers installés depuis le builder
COPY --from=builder /pgtap-dist/ /
