# Multi-stage build: build MkDocs site then serve as static files
FROM python:3.12.13-bookworm AS builder
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
WORKDIR /src
# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
ca-certificates && rm -rf /var/lib/apt/lists/*
# Copy source code
COPY . /src
# Upgrade pip and install MkDocs and plugins
RUN python -m pip install --upgrade pip
RUN pip install --no-cache-dir \
mkdocs-material mkdocs-video mkdocs-redirects mkdocs-glightbox mkdocs-rss-plugin \
git+https://github.com/pikvm/markdown-include
# Build the MkDocs site
RUN mkdocs build --clean
# Runtime stage: serve the static site with Python's simple HTTP server
FROM python:3.12.13-bookworm AS runtime
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
WORKDIR /app
# Copy the generated site from builder
COPY --from=builder /src/site /app/site
# Expose port for the static site
EXPOSE 8000
# Serve the site
CMD ["python","-m","http.server","8000","--directory","/app/site"]