Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +16 -13
Dockerfile
CHANGED
|
@@ -6,7 +6,7 @@ WORKDIR /usr/src/app
|
|
| 6 |
|
| 7 |
# Copy and install dependencies
|
| 8 |
COPY requirements.txt ./
|
| 9 |
-
RUN pip install --no-cache-dir -r requirements.txt
|
| 10 |
|
| 11 |
# Copy the application source code
|
| 12 |
COPY . .
|
|
@@ -21,25 +21,28 @@ FROM python:3.11.4-slim
|
|
| 21 |
|
| 22 |
WORKDIR /usr/src/app
|
| 23 |
|
| 24 |
-
#
|
| 25 |
-
RUN useradd --create-home appuser
|
| 26 |
-
|
| 27 |
-
# Copy the compiled .pyc files and other assets
|
| 28 |
COPY --from=builder /usr/src/app/*.pyc .
|
| 29 |
COPY --from=builder /usr/src/app/templates ./templates
|
| 30 |
COPY --from=builder /usr/src/app/requirements.txt .
|
| 31 |
|
| 32 |
-
# --- THIS IS THE KEY FIX FOR
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
# Change the ownership of the entire app directory to our new user.
|
| 34 |
-
# This allows the
|
| 35 |
RUN chown -R appuser:appuser /usr/src/app
|
| 36 |
|
| 37 |
-
# Switch to the non-root user
|
|
|
|
| 38 |
USER appuser
|
| 39 |
|
| 40 |
-
# Install the runtime dependencies into the final image
|
| 41 |
-
RUN pip install --no-cache-dir -r requirements.txt
|
| 42 |
-
|
| 43 |
# The command to run the application.
|
| 44 |
-
#
|
| 45 |
-
CMD ["gunicorn", "app:app", "--bind", "0.0.0.0
|
|
|
|
| 6 |
|
| 7 |
# Copy and install dependencies
|
| 8 |
COPY requirements.txt ./
|
| 9 |
+
RUN pip install -q --no-cache-dir -r requirements.txt
|
| 10 |
|
| 11 |
# Copy the application source code
|
| 12 |
COPY . .
|
|
|
|
| 21 |
|
| 22 |
WORKDIR /usr/src/app
|
| 23 |
|
| 24 |
+
# Copy the compiled .pyc files and other assets from the builder stage
|
|
|
|
|
|
|
|
|
|
| 25 |
COPY --from=builder /usr/src/app/*.pyc .
|
| 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 |
+
# Switch to the non-root user for running the application.
|
| 43 |
+
# This is the final security step before execution.
|
| 44 |
USER appuser
|
| 45 |
|
|
|
|
|
|
|
|
|
|
| 46 |
# The command to run the application.
|
| 47 |
+
# Gunicorn is now in the $PATH, and the 'appuser' has permission to run it.
|
| 48 |
+
CMD ["gunicorn", "app:app", "--bind", "0.0.0.0:$PORT"]
|