from {{ base_image }}

# Set the working directory to /geneva, where the code will be placed
WORKDIR /geneva

# Setup UV to use local caching, which is outside of the build context
# so that it can be shared between builds. So we need to copy.
RUN pip install --no-cache-dir uv || pip install --no-cache-dir uv --break-system-packages
ENV UV_LINK_MODE=copy

# RUN uv venv create --python={{ python_version }}

# Install dependencies -- this is done first so that the cache can be used
# if the code changes
RUN --mount=type=cache,target=/root/.cache/uv \
    --mount=type=bind,source=uv.lock,target=uv.lock \
    --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
    --mount=type=bind,source=wheelhouse,target=wheelhouse \
    uv sync --frozen --no-install-project --no-editable --extra ray

# *** DO NOT COPY CODE UNTILL DEPENDENCIES ARE INSTALLED ***
# so changing code does not invalidate the cache
COPY ./src /geneva/src
COPY ./pyproject.toml /geneva/pyproject.toml
COPY ./README.md /geneva/README.md
COPY ./uv.lock /geneva/uv.lock

# finally sync the local code
RUN --mount=type=bind,source=uv.lock,target=uv.lock \
    uv sync --frozen --no-editable --extra ray --python /home/ray/anaconda3/bin/python

# install package in the ray python environment
RUN uv pip install --verbose --python /home/ray/anaconda3/bin/python .
RUN uv pip install --verbose --python /home/ray/anaconda3/bin/python .[ray]
