# syntax=docker/dockerfile:1

ARG APP_USER="text-client"
ARG APP_RELATIVE_PATH="inference/text-client"


FROM python:3.10-alpine3.17 as build
ARG APP_RELATIVE_PATH

WORKDIR /build

COPY ./${APP_RELATIVE_PATH}/requirements.txt .

RUN --mount=type=cache,target=/var/cache/pip \
    pip install                  \
      --cache-dir=/var/cache/pip \
      --target=lib               \
      -r requirements.txt



FROM python:3.10-alpine3.17 as base-env
ARG APP_USER
ARG APP_RELATIVE_PATH

ENV APP_ROOT="/opt/${APP_RELATIVE_PATH}"
ENV APP_LIBS="/var/opt/${APP_RELATIVE_PATH}/lib"

ENV PATH="${PATH}:${APP_LIBS}/bin"
ENV PYTHONPATH="${PYTHONPATH}:${APP_LIBS}"


RUN adduser               \
      --disabled-password \
      --no-create-home    \
      "${APP_USER}"

USER ${APP_USER}

WORKDIR ${APP_ROOT}

COPY --chown="${APP_USER}:${APP_USER}" --from=build /build/lib                         ${APP_LIBS}
COPY --chown="${APP_USER}:${APP_USER}"              ./${APP_RELATIVE_PATH}/__main__.py .



FROM base-env as prod


CMD python3 __main__.py --backend-url "${BACKEND_URL}"
