Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +57 -23
Dockerfile
CHANGED
|
@@ -1,42 +1,76 @@
|
|
| 1 |
-
FROM python:3.11.11-slim-bullseye
|
| 2 |
|
|
|
|
| 3 |
RUN apt-get update -qq \
|
| 4 |
&& apt-get -qqq install --no-install-recommends -y pkg-config gcc g++ \
|
| 5 |
&& apt-get clean \
|
| 6 |
&& rm -rf /var/lib/apt/lists/*
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
|
|
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
RUN
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
&& ./venv/bin/pip install torch==2.2.0 --extra-index-url https://download.pytorch.org/whl/cpu \
|
| 15 |
&& ./venv/bin/pip install "numpy<2" \
|
| 16 |
&& ./venv/bin/pip install . \
|
|
|
|
| 17 |
&& ./venv/bin/pip cache purge
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
USER libretranslate
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
if [ ! -z "$models" ]; then \
|
| 35 |
-
./venv/bin/python scripts/install_models.py --load_only_lang_codes "$models"; \
|
| 36 |
-
else \
|
| 37 |
-
./venv/bin/python scripts/install_models.py; \
|
| 38 |
-
fi \
|
| 39 |
-
fi
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11.11-slim-bullseye
|
| 2 |
|
| 3 |
+
# Install system dependencies
|
| 4 |
RUN apt-get update -qq \
|
| 5 |
&& apt-get -qqq install --no-install-recommends -y pkg-config gcc g++ \
|
| 6 |
&& apt-get clean \
|
| 7 |
&& rm -rf /var/lib/apt/lists/*
|
| 8 |
|
| 9 |
+
# Create non-root user
|
| 10 |
+
RUN addgroup --system --gid 1032 libretranslate \
|
| 11 |
+
&& adduser --system --uid 1032 --gid 1032 libretranslate
|
| 12 |
+
|
| 13 |
+
# Set working directory
|
| 14 |
+
WORKDIR /app
|
| 15 |
+
|
| 16 |
+
# Create virtual environment
|
| 17 |
+
RUN python -m venv venv
|
| 18 |
|
| 19 |
+
# Upgrade pip
|
| 20 |
+
RUN ./venv/bin/pip install --upgrade pip
|
| 21 |
|
| 22 |
+
# Clone LibreTranslate repository
|
| 23 |
+
RUN apt-get update -qq \
|
| 24 |
+
&& apt-get install -y git \
|
| 25 |
+
&& git clone https://github.com/LibreTranslate/LibreTranslate.git . \
|
| 26 |
+
&& apt-get remove -y git \
|
| 27 |
+
&& apt-get autoremove -y \
|
| 28 |
+
&& apt-get clean \
|
| 29 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 30 |
+
|
| 31 |
+
# Install Python dependencies
|
| 32 |
+
RUN ./venv/bin/pip install Babel==2.12.1 \
|
| 33 |
+
&& ./venv/bin/python scripts/compile_locales.py \
|
| 34 |
&& ./venv/bin/pip install torch==2.2.0 --extra-index-url https://download.pytorch.org/whl/cpu \
|
| 35 |
&& ./venv/bin/pip install "numpy<2" \
|
| 36 |
&& ./venv/bin/pip install . \
|
| 37 |
+
&& ./venv/bin/pip install gunicorn \
|
| 38 |
&& ./venv/bin/pip cache purge
|
| 39 |
|
| 40 |
+
# Create necessary directories
|
| 41 |
+
RUN mkdir -p /app/db /app/logs /tmp/prometheus_data \
|
| 42 |
+
&& chown -R libretranslate:libretranslate /app /tmp/prometheus_data
|
| 43 |
|
| 44 |
+
# Copy wsgi.py file (if not in the repo)
|
| 45 |
+
RUN echo 'from app.main import create_app\n\
|
| 46 |
+
\n\
|
| 47 |
+
def app(*args, **kwargs):\n\
|
| 48 |
+
import argparse\n\
|
| 49 |
+
parser = argparse.ArgumentParser()\n\
|
| 50 |
+
import app.main as main\n\
|
| 51 |
+
main.get_args(parser)\n\
|
| 52 |
+
args = parser.parse_args([])\n\
|
| 53 |
+
for k, v in kwargs.items():\n\
|
| 54 |
+
setattr(args, k, v)\n\
|
| 55 |
+
return create_app(args)' > /app/wsgi.py
|
| 56 |
|
| 57 |
+
# Switch to non-root user
|
| 58 |
USER libretranslate
|
| 59 |
|
| 60 |
+
# Set environment variables
|
| 61 |
+
ENV PROMETHEUS_MULTIPROC_DIR=/tmp/prometheus_data
|
| 62 |
+
ENV LT_LOAD_ONLY=""
|
| 63 |
+
ENV LT_UPDATE_MODELS=false
|
| 64 |
|
| 65 |
+
# Expose port
|
| 66 |
+
EXPOSE 7860
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
+
# Default command with Gunicorn
|
| 69 |
+
CMD ["./venv/bin/gunicorn", \
|
| 70 |
+
"--workers", "3", \
|
| 71 |
+
"--bind", "0.0.0.0:7860", \
|
| 72 |
+
"--timeout", "300", \
|
| 73 |
+
"--log-level", "info", \
|
| 74 |
+
"--access-logfile", "-", \
|
| 75 |
+
"--error-logfile", "-", \
|
| 76 |
+
"wsgi:app"]
|