# syntax=docker/dockerfile:1

# python3-xapian has a python3 >= 3.9 < 3.10 dependency in bullseye (debian 11)
# See https://packages.debian.org/bullseye/python3-xapian

# python3-xapian has a python3 >= 3.11 < 3.12 dependency in bookworm (debian 12)
# See https://packages.debian.org/bullseye/python3-xapian

FROM python:3.11-bookworm

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    POETRY_HOME=/opt/poetry \
    VIRTUAL_ENV=/opt/venv

# RUN apt update \
#   && DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
#     # Required to install pylibmc (memcache backend)
#     libmemcached-dev \
#   # Clean up apt data
#   && apt-get clean \
#   # Remove files from apt-get update
#   && rm -rf /var/lib/apt/lists/*

# Create virtual env
RUN python -m venv $VIRTUAL_ENV
# Enable virtual env & add Poetry to the path
ENV PATH=$VIRTUAL_ENV/bin:$POETRY_HOME/bin:$PATH

# Install Poetry for dependency management as described at
# https://python-poetry.org/docs/master/#installation
RUN curl -sSL https://install.python-poetry.org | python -

WORKDIR /code

# # Copy across dependencies info first, so that normal code changes do not force re-installation
COPY pyproject.toml /code/
COPY poetry.lock /code/
RUN $POETRY_HOME/bin/poetry install

# Copy across rest of code, so that code changes don't trigger re-installation of dependencies.
COPY . /code/