NitinBot001 commited on
Commit
68c9637
·
verified ·
1 Parent(s): 3c843c7

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +26 -35
Dockerfile CHANGED
@@ -1,45 +1,36 @@
1
- FROM python:3.11.11-slim-bullseye
 
2
 
3
- ARG with_models=false
4
- ARG models=""
5
-
6
- # Install system dependencies
7
- RUN apt-get update && apt-get install -y --no-install-recommends \
8
- build-essential \
9
- pkg-config \
10
  && rm -rf /var/lib/apt/lists/*
11
 
12
- # Create non-root user
13
- RUN useradd -m -u 1000 libretranslate && \
14
- mkdir -p /home/libretranslate/.local && \
15
- chown -R libretranslate:libretranslate /home/libretranslate
 
 
16
 
17
- USER libretranslate
18
- WORKDIR /home/libretranslate
19
 
20
- # Create virtual environment and install packages
21
- RUN python -m venv venv
22
- ENV PATH="/home/libretranslate/venv/bin:$PATH"
23
 
24
- # Install LibreTranslate and Gunicorn
25
- RUN pip install --no-cache-dir --upgrade pip && \
26
- pip install --no-cache-dir libretranslate gunicorn
27
 
28
- # Download models if specified
29
- RUN if [ "$with_models" = "true" ]; then \
30
- if [ ! -z "$models" ]; then \
31
- python -c "from argostranslate import package; from libretranslate import get_available_packages; [package.install_from_path(p) for p in get_available_packages() if any(lang in p for lang in '${models}'.split(','))]"; \
32
- else \
33
- libretranslate --update-models; \
34
- fi \
35
- fi
36
 
37
- # Create simple WSGI file
38
- RUN echo 'from libretranslate.app import create_app\n\
39
- \n\
40
- app = create_app()' > wsgi.py
41
 
42
- EXPOSE 7860
 
43
 
44
- # Run with gunicorn
45
- CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--workers", "2", "--timeout", "300", "wsgi:app"]
 
1
+ # Use Python 3.11 base image
2
+ FROM python:3.11
3
 
4
+ # Update system and install git and curl
5
+ RUN apt-get update && apt-get install -y \
6
+ git \
7
+ curl \
 
 
 
8
  && rm -rf /var/lib/apt/lists/*
9
 
10
+ # Create a non-root user
11
+ RUN useradd -m -u 1000 appuser
12
+
13
+ # Clone LibreTranslate repository and set working directory
14
+ RUN git clone https://github.com/LibreTranslate/LibreTranslate.git
15
+ WORKDIR /LibreTranslate
16
 
17
+ # Change ownership of the application directory to the non-root user
18
+ RUN chown -R appuser:appuser /LibreTranslate
19
 
20
+ # Switch to non-root user
21
+ USER appuser
 
22
 
23
+ # Install Python requirements
24
+ RUN pip install --user -r requirements.txt
 
25
 
26
+ # Install gunicorn
27
+ RUN pip install --user gunicorn
 
 
 
 
 
 
28
 
29
+ # Add user's local bin to PATH
30
+ ENV PATH="/home/appuser/.local/bin:${PATH}"
 
 
31
 
32
+ # Expose port 5000
33
+ EXPOSE 5000
34
 
35
+ # Run the application
36
+ CMD ["gunicorn", "--bind", "0.0.0.0:5000", "wsgi:app"]