Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +32 -2
Dockerfile
CHANGED
@@ -3,14 +3,44 @@
|
|
3 |
|
4 |
FROM python:3.11
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
RUN useradd -m -u 1000 user
|
7 |
USER user
|
8 |
ENV PATH="/home/user/.local/bin:$PATH"
|
9 |
-
|
10 |
WORKDIR /app
|
11 |
|
|
|
|
|
12 |
COPY --chown=user ./requirements.txt requirements.txt
|
13 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
14 |
|
|
|
|
|
15 |
COPY --chown=user . /app
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
FROM python:3.11
|
5 |
|
6 |
+
# Set DEBIAN_FRONTEND to noninteractive to avoid prompts during apt-get install
|
7 |
+
ENV DEBIAN_FRONTEND=noninteractive
|
8 |
+
|
9 |
+
# --- System Package Installation (as root) ---
|
10 |
+
# Copy the packages list first
|
11 |
+
COPY ./packages.txt /app/packages.txt
|
12 |
+
|
13 |
+
# Update apt lists, install packages from packages.txt, and clean up in one layer
|
14 |
+
# Ensure packages.txt exists and has content, otherwise apt-get might fail.
|
15 |
+
# Handle potential errors if packages.txt is empty or doesn't exist.
|
16 |
+
RUN apt-get update && \
|
17 |
+
# Check if packages.txt exists and is not empty before trying to install
|
18 |
+
if [ -s /app/packages.txt ]; then \
|
19 |
+
apt-get install -y --no-install-recommends $(cat /app/packages.txt | grep -v '^#' | grep -v '^\s*$'); \
|
20 |
+
else \
|
21 |
+
echo "packages.txt not found or is empty, skipping system package installation."; \
|
22 |
+
fi && \
|
23 |
+
apt-get clean && \
|
24 |
+
rm -rf /var/lib/apt/lists/*
|
25 |
+
|
26 |
+
# --- User Setup ---
|
27 |
+
# Create a non-root user and switch to it
|
28 |
RUN useradd -m -u 1000 user
|
29 |
USER user
|
30 |
ENV PATH="/home/user/.local/bin:$PATH"
|
|
|
31 |
WORKDIR /app
|
32 |
|
33 |
+
# --- Python Package Installation (as user) ---
|
34 |
+
# Copy only requirements.txt first to leverage Docker cache
|
35 |
COPY --chown=user ./requirements.txt requirements.txt
|
36 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
37 |
|
38 |
+
# --- Application Code ---
|
39 |
+
# Copy the rest of the application code
|
40 |
COPY --chown=user . /app
|
41 |
+
|
42 |
+
# --- Run Command ---
|
43 |
+
# Expose the port the app runs on (optional but good practice)
|
44 |
+
EXPOSE 7860
|
45 |
+
# Start the application
|
46 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|