dockerfile modification"
Browse files- Dockerfile +21 -14
Dockerfile
CHANGED
|
@@ -1,27 +1,34 @@
|
|
| 1 |
-
# 1. Use
|
| 2 |
-
FROM python:3.
|
| 3 |
|
| 4 |
-
# 2.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
WORKDIR /app
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
# -
|
|
|
|
| 9 |
RUN apt-get update && \
|
| 10 |
apt-get install -y --no-install-recommends gcc libpq-dev && \
|
| 11 |
rm -rf /var/lib/apt/lists/*
|
|
|
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
COPY requirements.txt .
|
| 15 |
|
| 16 |
-
#
|
| 17 |
RUN python -m pip install --upgrade pip \
|
| 18 |
&& pip install --no-cache-dir -r requirements.txt
|
| 19 |
|
| 20 |
-
#
|
| 21 |
-
COPY . .
|
| 22 |
|
| 23 |
-
#
|
| 24 |
-
EXPOSE
|
| 25 |
|
| 26 |
-
#
|
| 27 |
-
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "
|
|
|
|
| 1 |
+
# 1. Use Hugging Face recommended Python image
|
| 2 |
+
FROM python:3.9
|
| 3 |
|
| 4 |
+
# 2. Create non-root user (required by Hugging Face Spaces)
|
| 5 |
+
RUN useradd -m -u 1000 user
|
| 6 |
+
USER user
|
| 7 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
| 8 |
+
|
| 9 |
+
# 3. Set working directory
|
| 10 |
WORKDIR /app
|
| 11 |
|
| 12 |
+
# 4. Install essential system dependencies
|
| 13 |
+
# - switched to root temporarily
|
| 14 |
+
USER root
|
| 15 |
RUN apt-get update && \
|
| 16 |
apt-get install -y --no-install-recommends gcc libpq-dev && \
|
| 17 |
rm -rf /var/lib/apt/lists/*
|
| 18 |
+
USER user
|
| 19 |
|
| 20 |
+
# 5. Copy requirements first for caching
|
| 21 |
+
COPY --chown=user requirements.txt .
|
| 22 |
|
| 23 |
+
# 6. Upgrade pip & install Python dependencies
|
| 24 |
RUN python -m pip install --upgrade pip \
|
| 25 |
&& pip install --no-cache-dir -r requirements.txt
|
| 26 |
|
| 27 |
+
# 7. Copy the rest of the app code
|
| 28 |
+
COPY --chown=user . .
|
| 29 |
|
| 30 |
+
# 8. Expose Hugging Face default port
|
| 31 |
+
EXPOSE 7860
|
| 32 |
|
| 33 |
+
# 9. Run Uvicorn server for FastAPI app
|
| 34 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]
|