Spaces:
Running
Running
Update Dockerfile
Browse files- Dockerfile +42 -26
Dockerfile
CHANGED
@@ -1,37 +1,53 @@
|
|
1 |
-
|
|
|
2 |
|
3 |
-
#
|
4 |
-
ENV
|
5 |
-
|
6 |
-
# Python & app environment
|
7 |
-
ENV PYTHONUNBUFFERED=1 \
|
8 |
-
PORT=7860
|
9 |
|
|
|
10 |
WORKDIR /app
|
11 |
|
12 |
-
#
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
#
|
21 |
-
RUN pip install --
|
22 |
-
|
23 |
|
24 |
-
#
|
25 |
-
|
26 |
-
|
27 |
|
28 |
-
#
|
29 |
-
RUN
|
30 |
-
&& chmod -R 777 cache uploads results checkpoints temp
|
31 |
|
32 |
-
# Copy
|
33 |
-
COPY .
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
EXPOSE 7860
|
36 |
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Use an official Python runtime as a parent image
|
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 build dependencies for numba/llvmlite (LLVM) and then numpy
|
15 |
+
# This needs to be done before installing the rest of requirements.txt
|
16 |
+
RUN apt-get update && \
|
17 |
+
apt-get install -y --no-install-recommends \
|
18 |
+
llvm-11-dev \
|
19 |
+
libllvm11 \
|
20 |
+
clang && \
|
21 |
+
rm -rf /var/lib/apt/lists/*
|
22 |
+
|
23 |
+
# Install numpy first, as numba/llvmlite depend on it for building
|
24 |
+
RUN pip install --no-cache-dir numpy
|
25 |
|
26 |
+
# Install the rest of the dependencies and the SpaCy model in a single layer to optimize image size
|
27 |
+
RUN pip install --no-cache-dir -r requirements.txt && \
|
28 |
+
python -m spacy download en_core_web_sm
|
29 |
|
30 |
+
# Create necessary directories with appropriate permissions
|
31 |
+
RUN mkdir -p /tmp/flask_sessions /app/flask_sessions /app/uploads && \
|
32 |
+
chmod -R 777 /tmp/flask_sessions /app/flask_sessions /app/uploads
|
33 |
|
34 |
+
# Ensure all relevant directories have the correct permissions
|
35 |
+
RUN chmod -R 777 /app
|
|
|
36 |
|
37 |
+
# Copy the rest of the application code to /app
|
38 |
+
COPY . /app/
|
39 |
|
40 |
+
# Ensure the upload directory and app directory have the correct permissions
|
41 |
+
RUN mkdir -p /app/uploads && \
|
42 |
+
chmod -R 777 /app/uploads && \
|
43 |
+
chmod -R 777 /app
|
44 |
+
|
45 |
+
# Expose the port the app runs on
|
46 |
EXPOSE 7860
|
47 |
|
48 |
+
# Set environment variables for Flask
|
49 |
+
ENV FLASK_APP=app.py \
|
50 |
+
FLASK_ENV=production
|
51 |
+
|
52 |
+
# Command to run the application
|
53 |
+
CMD ["gunicorn", "-w", "1", "-b", "0.0.0.0:7860", "--timeout", "120", "app:app"]
|