From 4a7a1513a70dc85fb494779611a745ee22df5825 Mon Sep 17 00:00:00 2001 From: Alan Jean Date: Mon, 30 Jan 2023 22:30:29 +0400 Subject: [PATCH] =?UTF-8?q?feat(inference):=20add=20Dockerfile=20for=20the?= =?UTF-8?q?=20inference=20stack's=20orchestrator=20image=20=F0=9F=90=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Initial definition of the inference stack's coordination/orchestration server container image. Notes: - The base layer uses python:3-slim to avoid having to install cargo on top of alpine. Cargo is required to install orjson, which is in turns a dependency of fastapi[all]. - The oasst-shared package is installed as root as a workaround: it seems that python 3.10+ doesn't pick up on a .egg-link file installed on the PYTHONPATH anywhere other than at a global site-package directory. This quirk is similar to the behaviour described here https://groups.google.com/g/python-virtualenv/c/sKVq_6gG5z4. - pydantic 1.9.1 (specified by oasst-shared) is incompatible with python 3.11, and needs to be upgraded. For now, this image uses python 3.10, as specified by the .python-version file --- docker/inference/Dockerfile.server | 68 ++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 docker/inference/Dockerfile.server diff --git a/docker/inference/Dockerfile.server b/docker/inference/Dockerfile.server new file mode 100644 index 00000000..34d8e0c9 --- /dev/null +++ b/docker/inference/Dockerfile.server @@ -0,0 +1,68 @@ +# syntax=docker/dockerfile:1 + +ARG MODULE="inference" +ARG SERVICE="server" + +ARG APP_USER="${MODULE}-${SERVICE}" +ARG APP_RELATIVE_PATH="${MODULE}/${SERVICE}" + + +FROM python:3-slim 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 dev +ARG APP_USER +ARG APP_RELATIVE_PATH +ARG MODULE +ARG SERVICE + +ENV APP_BASE="/opt/${MODULE}" +ENV APP_ROOT="${APP_BASE}/${SERVICE}" +ENV APP_LIBS="/var/opt/${APP_RELATIVE_PATH}/lib" +ENV SHARED_LIBS_BASE="${APP_BASE}/lib" + +ENV PATH="${PATH}:${APP_LIBS}/bin" +ENV PYTHONPATH="${PYTHONPATH}:${APP_LIBS}" + +ENV PORT="8000" + + +RUN adduser \ + --disabled-password \ + --no-create-home \ + "${APP_USER}" + + +WORKDIR ${APP_ROOT} + + +COPY --chown="${APP_USER}:${APP_USER}" ./oasst-shared ${SHARED_LIBS_BASE}/oasst-shared +RUN --mount=type=cache,target=/var/cache/pip,from=build \ + pip install \ + --cache-dir=/var/cache/pip \ + -e "${SHARED_LIBS_BASE}/oasst-shared" + + +USER ${APP_USER} + + +COPY --chown="${APP_USER}:${APP_USER}" --from=build /build/lib ${APP_LIBS} +COPY --chown="${APP_USER}:${APP_USER}" ./${APP_RELATIVE_PATH}/main.py . + + +VOLUME [ "${APP_BASE}/lib/oasst-shared" ] + + +CMD uvicorn main:app --reload --host 0.0.0.0 --port "${PORT}"