Spaces:
Runtime error
Runtime error
Update Dockerfile
Browse files- Dockerfile +49 -29
Dockerfile
CHANGED
|
@@ -1,13 +1,11 @@
|
|
| 1 |
FROM python:3.11-slim-bookworm
|
| 2 |
|
| 3 |
-
|
|
|
|
| 4 |
LABEL org.opencontainers.image.authors="Bram Vanroy"
|
| 5 |
LABEL org.opencontainers.image.title="MAchine Translation Evaluation Online - Demo"
|
| 6 |
|
| 7 |
-
# Avoid prompts from apt
|
| 8 |
ENV DEBIAN_FRONTEND=noninteractive
|
| 9 |
-
|
| 10 |
-
# Install dependencies in a single RUN command to reduce image layers
|
| 11 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 12 |
build-essential \
|
| 13 |
curl \
|
|
@@ -15,43 +13,65 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
| 15 |
&& apt-get clean \
|
| 16 |
&& rm -rf /var/lib/apt/lists/*
|
| 17 |
|
| 18 |
-
#
|
| 19 |
RUN useradd -m -u 1000 mateo_user
|
| 20 |
USER mateo_user
|
| 21 |
ENV HOME="/home/mateo_user"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
ENV PORT=7860 \
|
| 25 |
SERVER="localhost" \
|
|
|
|
|
|
|
| 26 |
HF_HUB_ENABLE_HF_TRANSFER=1 \
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
WORKDIR ${HOME}/mateo
|
| 31 |
|
| 32 |
-
#
|
| 33 |
-
RUN
|
| 34 |
-
|
| 35 |
|
| 36 |
-
#
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
&& python -m pip install --no-cache-dir --upgrade .
|
| 40 |
-
|
| 41 |
-
# Pre-download default models
|
| 42 |
-
RUN huggingface-cli download bert-base-multilingual-cased model.safetensors tokenizer.json vocab.txt; \
|
| 43 |
-
huggingface-cli download facebook/nllb-200-distilled-600M pytorch_model.bin sentencepiece.bpe.model tokenizer.json; \
|
| 44 |
-
python -c "import comet; from comet import download_model; download_model('Unbabel/wmt22-comet-da')"; \
|
| 45 |
-
python -c "import evaluate; evaluate.load('bleurt', 'BLEURT-20')"
|
| 46 |
|
| 47 |
# Expose the port the app runs on
|
| 48 |
EXPOSE $PORT
|
| 49 |
|
| 50 |
-
# Healthcheck
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
-
|
| 54 |
-
WORKDIR src/mateo_st
|
| 55 |
|
| 56 |
-
#
|
| 57 |
-
CMD
|
|
|
|
| 1 |
FROM python:3.11-slim-bookworm
|
| 2 |
|
| 3 |
+
COPY --from=ghcr.io/astral-sh/uv:0.6.16 /uv /uvx /bin/
|
| 4 |
+
|
| 5 |
LABEL org.opencontainers.image.authors="Bram Vanroy"
|
| 6 |
LABEL org.opencontainers.image.title="MAchine Translation Evaluation Online - Demo"
|
| 7 |
|
|
|
|
| 8 |
ENV DEBIAN_FRONTEND=noninteractive
|
|
|
|
|
|
|
| 9 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 10 |
build-essential \
|
| 11 |
curl \
|
|
|
|
| 13 |
&& apt-get clean \
|
| 14 |
&& rm -rf /var/lib/apt/lists/*
|
| 15 |
|
| 16 |
+
# --- Application User ---
|
| 17 |
RUN useradd -m -u 1000 mateo_user
|
| 18 |
USER mateo_user
|
| 19 |
ENV HOME="/home/mateo_user"
|
| 20 |
+
WORKDIR $HOME
|
| 21 |
+
|
| 22 |
+
# --- Application Code & Dependencies ---
|
| 23 |
+
ARG REPO_BRANCH=v1.6.0
|
| 24 |
+
RUN git clone --depth 1 --branch ${REPO_BRANCH} https://github.com/BramVanroy/mateo-demo.git $HOME/mateo-demo
|
| 25 |
+
|
| 26 |
+
WORKDIR $HOME/mateo-demo
|
| 27 |
|
| 28 |
+
ARG USE_CUDA=false
|
| 29 |
+
RUN uv venv .venv --python 3.11 \
|
| 30 |
+
&& . .venv/bin/activate \
|
| 31 |
+
&& uv pip install --no-cache-dir --upgrade pip wheel setuptools \
|
| 32 |
+
# Conditionally install PyTorch (CPU or CUDA 12.1)
|
| 33 |
+
&& if [ "$USE_CUDA" = "true" ]; then \
|
| 34 |
+
echo "Installing PyTorch with CUDA 12.1 support"; \
|
| 35 |
+
uv pip install --no-cache-dir torch==2.2.1 --index-url https://download.pytorch.org/whl/cu121; \
|
| 36 |
+
else \
|
| 37 |
+
echo "Installing PyTorch with CPU support"; \
|
| 38 |
+
uv pip install --no-cache-dir torch==2.2.1+cpu --index-url https://download.pytorch.org/whl/cpu; \
|
| 39 |
+
fi \
|
| 40 |
+
&& uv pip install --no-cache-dir --upgrade $HOME/mateo-demo[patch] \
|
| 41 |
+
&& uv cache clean
|
| 42 |
+
|
| 43 |
+
# --- Runtime Configuration ---
|
| 44 |
+
# Set runtime environment variables
|
| 45 |
+
# NOTE: for Hugging Face spaces we set XSRF to false and demo mode to false
|
| 46 |
ENV PORT=7860 \
|
| 47 |
SERVER="localhost" \
|
| 48 |
+
BASE="" \
|
| 49 |
+
DEMO_MODE=false \
|
| 50 |
HF_HUB_ENABLE_HF_TRANSFER=1 \
|
| 51 |
+
PRELOAD_METRICS=true \
|
| 52 |
+
PATH="$HOME/.local/bin:$HOME/mateo-demo/.venv/bin:${PATH}" \
|
| 53 |
+
ENABLE_XSRF_PROTECTION=false
|
|
|
|
| 54 |
|
| 55 |
+
# --- Set default cache dir for the user ---
|
| 56 |
+
RUN mkdir -p "$HOME/.cache" \
|
| 57 |
+
&& chown -R mateo_user:mateo_user "$HOME/.cache"
|
| 58 |
|
| 59 |
+
# --- Entrypoint & CMD ---
|
| 60 |
+
COPY --chown=mateo_user:mateo_user entrypoint.sh /usr/local/bin/entrypoint.sh
|
| 61 |
+
RUN chmod +x /usr/local/bin/entrypoint.sh
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
# Expose the port the app runs on
|
| 64 |
EXPOSE $PORT
|
| 65 |
|
| 66 |
+
# Healthcheck (adjust start-period if runtime loading takes longer)
|
| 67 |
+
# Note: SERVER env var needs to be passed at runtime if not localhost
|
| 68 |
+
HEALTHCHECK --interval=30s --timeout=5s --start-period=60s \
|
| 69 |
+
CMD curl --fail http://${SERVER:-localhost}:${PORT}${BASE}/_stcore/health || exit 1
|
| 70 |
+
|
| 71 |
+
# Set the working directory for the application
|
| 72 |
+
WORKDIR $HOME/mateo-demo/src/mateo_st
|
| 73 |
|
| 74 |
+
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
|
|
|
| 75 |
|
| 76 |
+
# CMD is now empty as the entrypoint handles the final command execution
|
| 77 |
+
CMD []
|