ARG PYTHON_VERSION=3.12-slim-bullseye

FROM python:${PYTHON_VERSION}

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

RUN mkdir -p /code

WORKDIR /code

COPY pyproject.toml /tmp/pyproject.toml

# Regenerate lock file, because we trust pyproject.toml but not poetry.lock.
RUN set -ex && \
    pip install --upgrade pip && \
    pip install poetry && \
    cd /tmp/ && \
    poetry config virtualenvs.create false && \
    poetry lock && \
    poetry install --with deploy && \
    rm -rf /root/.cache/

COPY . /code/

RUN ON_FLYIO_SETUP="1" python manage.py collectstatic --noinput

EXPOSE 8000

CMD ["gunicorn", "--bind", ":8000", "--workers", "2", "{{ django_project_name }}.wsgi"]
