Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +24 -69
Dockerfile
CHANGED
|
@@ -2,86 +2,41 @@
|
|
| 2 |
FROM python:3.9-slim
|
| 3 |
|
| 4 |
# Set environment variables for Python
|
| 5 |
-
ENV PYTHONDONTWRITEBYTECODE
|
| 6 |
-
|
| 7 |
|
| 8 |
-
# Set
|
| 9 |
-
ENV TRANSFORMERS_CACHE=/app/.cache/huggingface
|
| 10 |
-
ENV HF_HOME=/app/.cache/huggingface
|
| 11 |
-
ENV MPLCONFIGDIR=/app/.cache/matplotlib
|
| 12 |
-
|
| 13 |
-
# Create cache directories and assign permissions
|
| 14 |
-
RUN mkdir -p /app/.cache/huggingface /app/.cache/matplotlib
|
| 15 |
-
|
| 16 |
-
# Install system dependencies
|
| 17 |
-
RUN apt-get update && apt-get install -y \
|
| 18 |
-
libgl1-mesa-glx \
|
| 19 |
-
libgomp1 \
|
| 20 |
-
libglib2.0-0 \
|
| 21 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 22 |
-
|
| 23 |
-
# Create a non-root user and group
|
| 24 |
-
RUN groupadd -r appgroup && useradd -r -g appgroup appuser
|
| 25 |
-
|
| 26 |
-
# Create necessary directories and set permissions
|
| 27 |
-
RUN mkdir -p /app/flask_sessions /app/uploads /app/data /app/JSON /app/Models /app/logs \
|
| 28 |
-
&& chmod -R 777 /app/uploads /app/data /app/JSON /app/Models \
|
| 29 |
-
&& chown -R appuser:appgroup /app
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
# Create necessary directories and set permissions
|
| 33 |
-
RUN mkdir -p /app/uploads /app/data /app/JSON /app/Models /app/logs \
|
| 34 |
-
&& chown -R appuser:appgroup /app
|
| 35 |
-
|
| 36 |
-
# Set permissions for uploads
|
| 37 |
-
RUN chmod -R 777 /app/uploads
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
# Create necessary directories
|
| 42 |
-
RUN mkdir -p /app/flask_sessions /app/uploads /app/data /app/JSON /app/Models /app/logs /tmp/matplotlib /tmp/transformers_cache
|
| 43 |
-
|
| 44 |
-
# Create directories for uploads and set permissions
|
| 45 |
-
RUN mkdir -p /app/uploads && chmod -R 777 /app/uploads
|
| 46 |
-
|
| 47 |
-
# Create directories for data and set permissions
|
| 48 |
-
RUN mkdir -p /app/data && chmod -R 777 /app/data
|
| 49 |
-
|
| 50 |
-
# Create directories for JSON and set permissions
|
| 51 |
-
RUN mkdir -p /app/JSON && chmod -R 777 /app/JSON
|
| 52 |
-
|
| 53 |
-
# Create directories for Models and set permissions
|
| 54 |
-
RUN mkdir -p /app/Models && chmod -R 777 /app/Models
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
# Set permissions for app directories
|
| 58 |
-
RUN chown -R appuser:appgroup /app /tmp/matplotlib /tmp/transformers_cache \
|
| 59 |
-
&& chmod -R 755 /app /tmp/matplotlib /tmp/transformers_cache
|
| 60 |
-
|
| 61 |
-
# Set working directory
|
| 62 |
WORKDIR /app
|
| 63 |
|
| 64 |
# Copy the requirements file into the container at /app
|
| 65 |
COPY requirements.txt /app/
|
| 66 |
|
| 67 |
-
# Install
|
| 68 |
-
RUN pip install --no-cache-dir
|
|
|
|
| 69 |
|
| 70 |
-
#
|
| 71 |
-
|
|
|
|
| 72 |
|
| 73 |
-
# Ensure
|
| 74 |
-
RUN
|
| 75 |
|
| 76 |
-
#
|
| 77 |
-
|
| 78 |
|
| 79 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
EXPOSE 7860
|
| 81 |
|
| 82 |
# Set environment variables for Flask
|
| 83 |
-
ENV FLASK_APP=app.py
|
| 84 |
-
|
| 85 |
|
| 86 |
-
# Command to run the
|
| 87 |
-
CMD ["gunicorn", "
|
|
|
|
|
|
| 2 |
FROM python:3.9-slim
|
| 3 |
|
| 4 |
# Set environment variables for Python
|
| 5 |
+
ENV PYTHONDONTWRITEBYTECODE=1 \
|
| 6 |
+
PYTHONUNBUFFERED=1
|
| 7 |
|
| 8 |
+
# Set the working directory
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
WORKDIR /app
|
| 10 |
|
| 11 |
# Copy the requirements file into the container at /app
|
| 12 |
COPY requirements.txt /app/
|
| 13 |
|
| 14 |
+
# Install dependencies and the SpaCy model in a single layer to optimize image size
|
| 15 |
+
RUN pip install --no-cache-dir -r requirements.txt && \
|
| 16 |
+
python -m spacy download en_core_web_sm
|
| 17 |
|
| 18 |
+
# Create necessary directories with appropriate permissions
|
| 19 |
+
RUN mkdir -p /tmp/flask_sessions /app/flask_sessions /app/uploads /app/JSON /app/data /app/Models && \
|
| 20 |
+
chmod -R 777 /tmp/flask_sessions /app/flask_sessions /app/uploads /app/JSON /app/data /app/Models
|
| 21 |
|
| 22 |
+
# Ensure all relevant directories have the correct permissions
|
| 23 |
+
RUN chmod -R 777 /app
|
| 24 |
|
| 25 |
+
# Copy the rest of the application code to /app
|
| 26 |
+
COPY . /app/
|
| 27 |
|
| 28 |
+
# Ensure the upload directory and app directory have the correct permissions
|
| 29 |
+
RUN mkdir -p /app/uploads /app/JSON /app/data /app/Models && \
|
| 30 |
+
chmod -R 777 /app/uploads /app/JSON /app/data /app/Models && \
|
| 31 |
+
chmod -R 777 /app
|
| 32 |
+
|
| 33 |
+
# Expose the port the app runs on
|
| 34 |
EXPOSE 7860
|
| 35 |
|
| 36 |
# Set environment variables for Flask
|
| 37 |
+
ENV FLASK_APP=app.py \
|
| 38 |
+
FLASK_ENV=production
|
| 39 |
|
| 40 |
+
# Command to run the application
|
| 41 |
+
CMD ["gunicorn", "-w", "1", "-b", "0.0.0.0:7860", "--timeout", "120", "app:app"]
|
| 42 |
+
#CMD ["gunicorn", "--workers=5", "--threads=2", "--bind=0.0.0.0:7860", "--timeout=120", "app:app"]
|