# pull official base image
FROM python:3.12-alpine AS builder

COPY --from=ghcr.io/astral-sh/uv:0.10.10 /uv /uvx /bin/

# compile tools
RUN apk add gcc musl-dev mariadb-connector-c-dev gettext curl python3-dev libpq-dev

# Install the project into `/app`
WORKDIR /app
RUN mkdir /app/static

# Enable bytecode compilation
ENV UV_COMPILE_BYTECODE=0

# Copy from the cache instead of linking since it's a mounted volume
#ENV UV_LINK_MODE=copy

# Omit development dependencies
ENV UV_NO_DEV=1

ENV UV_NO_CACHE=1

# # Configure the Python directory so it is consistent
# ENV UV_PYTHON_INSTALL_DIR=/python

# # Only use the managed Python version
# ENV UV_PYTHON_PREFERENCE=only-managed

# # Install Python before the project for caching
# RUN uv python install 3.12

# Ensure installed tools can be executed out of the box
ENV UV_TOOL_BIN_DIR=/usr/local/bin

ENV UV_PROJECT_ENVIRONMENT=/.venv
# Place executables in the environment at the front of the path
ENV PATH="/.venv/bin:$PATH"



COPY pyproject.toml uv.lock ./
RUN uv sync --frozen --no-dev --no-install-project

COPY . .
RUN uv sync --frozen --no-dev


COPY ./docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh
CMD ["/docker-entrypoint.sh"]

# FROM python:3.12-alpine
# WORKDIR /app
# COPY --from=builder /python /python
# COPY --from=builder /app /app
# COPY --from=builder /.venv /.venv
# ENV PATH="/.venv/bin:$PATH"
# COPY ./docker-entrypoint.sh /docker-entrypoint.sh
# RUN chmod +x /docker-entrypoint.sh
# CMD ["/docker-entrypoint.sh"]