FROM python:3 as builder
# Not using an Alpine build as we need Git to be installed

RUN apt-get update

## Install pngcrush
RUN apt-get install -y pngcrush

# Install Sass
RUN mkdir -p /opt
ADD "https://github.com/sass/dart-sass/releases/download/1.83.0/dart-sass-1.83.0-linux-x64.tar.gz" /opt/
RUN bash -c '(cd /opt && tar xzvf /opt/dart-sass-1.83.0-linux-x64.tar.gz)'
ENV PATH=$PATH:/opt/dart-sass/

## Install Poetry
ENV PIP_DISABLE_PIP_VERSION_CHECK=on
RUN pip install poetry

## Install Poetry deps
COPY poetry.lock pyproject.toml ./
RUN poetry config virtualenvs.create false
RUN poetry install --no-interaction --no-root --without dev

## Let's build! :D
WORKDIR /usr/src

COPY generator/ generator/
COPY site/ site/
COPY .git/ .git/

RUN poetry run python3 generator/ generate site/ --production

# ===================================================================

FROM caddy:2-alpine

COPY --from=builder /usr/src/_dist /var/www
WORKDIR /var/www
EXPOSE 8080
CMD ["caddy", "run", "--config", "caddy_config.json"]
