# hadolint ignore=DL3006,DL3007
FROM cgr.dev/chainguard/wolfi-base:latest AS base

SHELL ["/bin/ash", "-ex", "-c"]

ARG USERID=1000
ARG GROUPID=1000

ENV USERNAME="huesoporro"
ENV APP_HOME="/home/$USERNAME"
ENV APP_PATH="$APP_HOME"

ENV POETRY_VERSION=1.8.3
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONPATH="$APP_PATH"
ENV PATH="$APP_HOME/.local/bin:$PATH"

# hadolint ignore=DL3001,DL3008,DL3018
RUN apk add --no-cache make python3~=3.13 curl git \
    && adduser -S -u "$USERID" -h "$APP_HOME" "$USERNAME" \
    && mkdir -p "$APP_PATH" \
    && chown -R "$USERID:$GROUPID" "$APP_PATH"

COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv

USER "$USERNAME"

WORKDIR "$APP_PATH"

COPY --chown=$USERNAME pyproject.toml uv.lock Makefile README.md ./

COPY --chown=$USERNAME src/ src/

RUN uv sync

COPY --chown=$USERNAME migrations/ migrations/


FROM base AS serve

CMD ["make", "serve"]


FROM base AS migrate

CMD ["make", "migrate"]