FROM alpine:3.20 AS builder

ENV PYTHONUNBUFFERED=1

RUN apk add --no-cache \
    ca-certificates \
    bash \
    git \
    openssh-client \
    python3 \
    python3-dev \
    py3-pip \
    build-base \
    weasyprint

RUN python -m venv /src/env
ENV PATH="/src/env/bin:$PATH"

WORKDIR /src

COPY requirements.txt /src/
RUN pip install --upgrade pip && \
    pip install -r /src/requirements.txt && \
    rm -rf /tmp/* /var/cache/apk/*

FROM builder as makestatic

COPY docs /src/docs/
COPY zensical.toml /src/

RUN cp -r /src/mkdocs.yml /src/ 2>/dev/null || true
RUN cp -r /src/custom_theme /src/overrides 2>/dev/null || true
RUN cd /src && zensical build --config-file zensical.toml


FROM nginx:alpine

COPY docker/default.conf /etc/nginx/conf.d/default.conf
COPY --from=makestatic /src/site /sites/app.lexema.ru/docs
EXPOSE 80