# Zweistufiger Build: Hugo erzeugt die Seite, nginx liefert nur noch aus.
# Das fertige HTML steckt im Image - zur Laufzeit wird nichts mehr gebaut
# oder aus git geholt.

FROM debian:bookworm-slim AS builder

ARG HUGO_VERSION=0.147.0

RUN apt-get update && apt-get install -y --no-install-recommends \
      curl \
      ca-certificates \
    && rm -rf /var/lib/apt/lists/*

RUN curl -fsSL "https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.tar.gz" \
    | tar -xz -C /usr/local/bin hugo

WORKDIR /src
COPY . .

# themes/gokarna ist ein Submodule und muss im Build-Context liegen.
# In der CI sorgt actions/checkout mit submodules:recursive dafuer.
RUN test -f themes/gokarna/theme.toml \
    || { echo "FEHLER: themes/gokarna fehlt - Submodule nicht ausgecheckt"; exit 1; }

RUN hugo --minify --destination /public


FROM nginx:1.27-alpine

COPY docker/nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=builder /public /usr/share/nginx/html

EXPOSE 80
