Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +15 -42
Dockerfile
CHANGED
|
@@ -1,48 +1,21 @@
|
|
| 1 |
-
#
|
| 2 |
-
|
| 3 |
-
FROM python:3.11.4-slim as builder
|
| 4 |
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
-
# Copy
|
| 8 |
-
COPY requirements.txt .
|
| 9 |
-
RUN pip install -q --no-cache-dir -r requirements.txt
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
# Compile all .py files. The -b flag creates legacy .pyc files.
|
| 15 |
-
RUN python -m compileall -b -f .
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
# --- Stage 2: The Final Production Image ---
|
| 19 |
-
# This stage takes only the compiled code and necessary assets.
|
| 20 |
-
FROM python:3.11.4-slim
|
| 21 |
-
|
| 22 |
-
WORKDIR /usr/src/app
|
| 23 |
|
| 24 |
-
# Copy the
|
| 25 |
-
COPY
|
| 26 |
-
COPY --from=builder /usr/src/app/templates ./templates
|
| 27 |
-
COPY --from=builder /usr/src/app/requirements.txt .
|
| 28 |
-
|
| 29 |
-
# --- THIS IS THE KEY FIX FOR THE PATH ERROR ---
|
| 30 |
-
# Install dependencies as the ROOT user first.
|
| 31 |
-
# This ensures executables like 'gunicorn' are installed in a system-wide
|
| 32 |
-
# directory (e.g., /usr/local/bin) that is in the default $PATH.
|
| 33 |
-
RUN pip install -q --no-cache-dir -r requirements.txt
|
| 34 |
-
|
| 35 |
-
# Now, create the non-root user for running the application
|
| 36 |
-
RUN useradd --create-home appuser
|
| 37 |
-
|
| 38 |
-
# Change the ownership of the entire app directory to our new user.
|
| 39 |
-
# This allows the app to write files like client_secrets.json and token.json.
|
| 40 |
-
RUN chown -R appuser:appuser /usr/src/app
|
| 41 |
|
| 42 |
-
#
|
| 43 |
-
|
| 44 |
-
USER appuser
|
| 45 |
|
| 46 |
-
#
|
| 47 |
-
#
|
| 48 |
-
CMD ["gunicorn", "
|
|
|
|
| 1 |
+
# Use the official Python 3.9 slim image as the base
|
| 2 |
+
FROM python:3.9-slim
|
|
|
|
| 3 |
|
| 4 |
+
# Set the working directory inside the container
|
| 5 |
+
WORKDIR /app
|
| 6 |
|
| 7 |
+
# Copy the requirements file first to leverage Docker cache
|
| 8 |
+
COPY requirements.txt requirements.txt
|
|
|
|
| 9 |
|
| 10 |
+
# Install the Python dependencies
|
| 11 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
# Copy the rest of the application code
|
| 14 |
+
COPY . .
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
# Expose the port the app runs on (defined by the PORT environment variable or 5000)
|
| 17 |
+
EXPOSE 5000
|
|
|
|
| 18 |
|
| 19 |
+
# Define the command to run the application
|
| 20 |
+
# Run the application using Gunicorn
|
| 21 |
+
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "app:app"]
|