Skip to content

Commit

Permalink
feat: uv instead of conda in inference container (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyuwoo-choi authored Dec 20, 2024
1 parent 8d22ad2 commit 9575f11
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 87 deletions.
77 changes: 6 additions & 71 deletions container/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,77 +1,10 @@
FROM alpine:3.15.0 as alpine-glibc

LABEL src=https://github.com/frol/docker-alpine-glibc
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8

SHELL ["/bin/ash", "-eo", "pipefail", "-c"]

# hadolint ignore=DL3018
RUN ALPINE_GLIBC_BASE_URL="https://github.com/sgerrand/alpine-pkg-glibc/releases/download" && \
ALPINE_GLIBC_PACKAGE_VERSION="2.34-r0" && \
ALPINE_GLIBC_BASE_PACKAGE_FILENAME="glibc-$ALPINE_GLIBC_PACKAGE_VERSION.apk" && \
ALPINE_GLIBC_BIN_PACKAGE_FILENAME="glibc-bin-$ALPINE_GLIBC_PACKAGE_VERSION.apk" && \
ALPINE_GLIBC_I18N_PACKAGE_FILENAME="glibc-i18n-$ALPINE_GLIBC_PACKAGE_VERSION.apk" && \
apk add -q --no-cache --virtual=.build-dependencies wget ca-certificates && \
echo \
"-----BEGIN PUBLIC KEY-----\
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApZ2u1KJKUu/fW4A25y9m\
y70AGEa/J3Wi5ibNVGNn1gT1r0VfgeWd0pUybS4UmcHdiNzxJPgoWQhV2SSW1JYu\
tOqKZF5QSN6X937PTUpNBjUvLtTQ1ve1fp39uf/lEXPpFpOPL88LKnDBgbh7wkCp\
m2KzLVGChf83MS0ShL6G9EQIAUxLm99VpgRjwqTQ/KfzGtpke1wqws4au0Ab4qPY\
KXvMLSPLUp7cfulWvhmZSegr5AdhNw5KNizPqCJT8ZrGvgHypXyiFvvAH5YRtSsc\
Zvo9GI2e2MaZyo9/lvb+LbLEJZKEQckqRj4P26gmASrZEPStwc+yqy1ShHLA0j6m\
1QIDAQAB\
-----END PUBLIC KEY-----" | sed 's/ */\n/g' > "/etc/apk/keys/sgerrand.rsa.pub" && \
wget -q \
"$ALPINE_GLIBC_BASE_URL/$ALPINE_GLIBC_PACKAGE_VERSION/$ALPINE_GLIBC_BASE_PACKAGE_FILENAME" \
"$ALPINE_GLIBC_BASE_URL/$ALPINE_GLIBC_PACKAGE_VERSION/$ALPINE_GLIBC_BIN_PACKAGE_FILENAME" \
"$ALPINE_GLIBC_BASE_URL/$ALPINE_GLIBC_PACKAGE_VERSION/$ALPINE_GLIBC_I18N_PACKAGE_FILENAME" && \
apk add -q --no-cache \
"$ALPINE_GLIBC_BASE_PACKAGE_FILENAME" \
"$ALPINE_GLIBC_BIN_PACKAGE_FILENAME" \
"$ALPINE_GLIBC_I18N_PACKAGE_FILENAME" && \
\
rm "/etc/apk/keys/sgerrand.rsa.pub" && \
/usr/glibc-compat/bin/localedef --force --inputfile POSIX --charmap UTF-8 "$LANG" || true && \
echo "export LANG=$LANG" > /etc/profile.d/locale.sh && \
\
apk del -q glibc-i18n && \
\
rm "/root/.wget-hsts" && \
apk del -q .build-dependencies && \
rm \
"$ALPINE_GLIBC_BASE_PACKAGE_FILENAME" \
"$ALPINE_GLIBC_BIN_PACKAGE_FILENAME" \
"$ALPINE_GLIBC_I18N_PACKAGE_FILENAME"


############################################################################################################
# Prepare miniforge image to run nubison-model server
#
FROM alpine-glibc
FROM python:3.12.8-slim-bookworm

# Install necessary dependencies
RUN apk add --no-cache \
RUN apt-get update && apt-get install -y \
bash \
curl \
bzip2 \
ca-certificates \
libstdc++ \
&& rm -rf /var/cache/apk/*

# Set environment variables for Miniforge installation
ENV MINIFORGE_VERSION=24.9.2-0
ENV MINIFORGE_URL=https://github.com/conda-forge/miniforge/releases/download/${MINIFORGE_VERSION}/Miniforge3-${MINIFORGE_VERSION}-Linux-x86_64.sh
ENV CONDA_DIR=/opt/conda

# Install Miniforge
RUN curl -L -o /tmp/miniforge.sh $MINIFORGE_URL && \
bash /tmp/miniforge.sh -b -p $CONDA_DIR && \
rm /tmp/miniforge.sh && \
$CONDA_DIR/bin/conda clean -afy

# Update PATH to include Conda
ENV PATH=$CONDA_DIR/bin:$PATH
&& rm -rf /var/lib/apt/lists/*

# Use bash as the default shell
SHELL ["bash", "-c"]
Expand All @@ -92,5 +25,7 @@ ENV PORT=3000
# Expose the port specified by the PORT environment variable
EXPOSE ${PORT}

RUN pip install uv==0.5.10

# Define the command to run your application
ENTRYPOINT [ "/app/start_server.sh" ]
ENTRYPOINT [ "/app/start_server.sh" ]
20 changes: 4 additions & 16 deletions container/start_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,11 @@ ENV_NAME="nubison"
echo "MLFLOW_TRACKING_URI: '$MLFLOW_TRACKING_URI'"
echo "MLFLOW_MODEL_URI: '$MLFLOW_MODEL_URI'"

echo "Downloading conda.yaml for run $run_uuid"
echo "Downloading conda.yaml & requirements.txt for run $run_uuid"
curl -L -o conda.yaml "${MLFLOW_TRACKING_URI}/get-artifact?path=conda.yaml&run_uuid=${run_uuid}"
curl -L -o requirements.txt "${MLFLOW_TRACKING_URI}/get-artifact?path=requirements.txt&run_uuid=${run_uuid}"

# Create the Conda environment
echo "Creating Conda environment from conda.yaml"
conda env create -f conda.yaml -n $ENV_NAME
python_version=$(grep "python=" conda.yaml | awk -F= '{print $2}')

echo "Activating Conda environment '$ENV_NAME'"
# Initialize Conda for bash
source ${CONDA_DIR}/etc/profile.d/conda.sh

# Activate the environment
conda activate "$ENV_NAME"

# Verify that the environment is activated
echo "Conda environment '$ENV_NAME' is activated"

# Execute the BentoML serve command
echo "Starting BentoML server..."
exec bentoml serve nubison_model.Service:InferenceService --port ${PORT} ${DEBUG:+--debug}
exec uv run --python $python_version --with-requirements requirements.txt bentoml serve nubison_model.Service:InferenceService --port ${PORT} ${DEBUG:+--debug}

0 comments on commit 9575f11

Please sign in to comment.