Update Dockerfile
Browse files- Dockerfile +16 -28
Dockerfile
CHANGED
|
@@ -1,69 +1,57 @@
|
|
| 1 |
-
#
|
| 2 |
-
# Multi-stage build for optimized image
|
| 3 |
-
|
| 4 |
FROM python:3.11-slim as builder
|
| 5 |
|
| 6 |
-
# Install build dependencies
|
| 7 |
RUN apt-get update && apt-get install -y \
|
| 8 |
build-essential \
|
| 9 |
cmake \
|
| 10 |
git \
|
| 11 |
&& rm -rf /var/lib/apt/lists/*
|
| 12 |
|
| 13 |
-
# Set working directory
|
| 14 |
WORKDIR /build
|
| 15 |
-
|
| 16 |
-
# Copy requirements first for caching
|
| 17 |
COPY requirements.txt .
|
| 18 |
-
|
| 19 |
-
# Install Python dependencies
|
| 20 |
RUN pip install --no-cache-dir --upgrade pip && \
|
| 21 |
pip wheel --no-cache-dir --wheel-dir=/wheels -r requirements.txt
|
| 22 |
|
| 23 |
-
# Production
|
| 24 |
FROM python:3.11-slim
|
| 25 |
|
| 26 |
-
# Set environment variables
|
| 27 |
ENV PYTHONDONTWRITEBYTECODE=1 \
|
| 28 |
PYTHONUNBUFFERED=1 \
|
| 29 |
PYTHONPATH=/app
|
| 30 |
|
| 31 |
-
# Install runtime dependencies
|
| 32 |
RUN apt-get update && apt-get install -y \
|
| 33 |
libgomp1 \
|
| 34 |
curl \
|
| 35 |
&& rm -rf /var/lib/apt/lists/* \
|
| 36 |
&& useradd --create-home --shell /bin/bash nur
|
| 37 |
|
| 38 |
-
# Set working directory
|
| 39 |
WORKDIR /app
|
| 40 |
|
| 41 |
-
#
|
| 42 |
COPY --from=builder /wheels /wheels
|
| 43 |
-
|
| 44 |
-
# Install Python packages from wheels
|
| 45 |
RUN pip install --no-cache-dir --upgrade pip && \
|
| 46 |
pip install --no-cache-dir /wheels/* && \
|
| 47 |
rm -rf /wheels
|
| 48 |
|
| 49 |
-
# Create
|
| 50 |
RUN mkdir -p /app/models && chown -R nur:nur /app
|
| 51 |
|
| 52 |
-
# Copy
|
| 53 |
COPY --chown=nur:nur app/ /app/app/
|
| 54 |
|
| 55 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
USER nur
|
| 57 |
|
| 58 |
-
#
|
| 59 |
-
EXPOSE
|
| 60 |
|
| 61 |
-
#
|
| 62 |
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
| 63 |
-
CMD curl -f http://localhost:
|
| 64 |
|
| 65 |
-
#
|
| 66 |
-
|
| 67 |
-
COPY entrypoint.sh .
|
| 68 |
-
RUN chmod +x entrypoint.sh
|
| 69 |
-
ENTRYPOINT ["./entrypoint.sh"]
|
|
|
|
| 1 |
+
# --- STAGE 1: Builder ---
|
|
|
|
|
|
|
| 2 |
FROM python:3.11-slim as builder
|
| 3 |
|
|
|
|
| 4 |
RUN apt-get update && apt-get install -y \
|
| 5 |
build-essential \
|
| 6 |
cmake \
|
| 7 |
git \
|
| 8 |
&& rm -rf /var/lib/apt/lists/*
|
| 9 |
|
|
|
|
| 10 |
WORKDIR /build
|
|
|
|
|
|
|
| 11 |
COPY requirements.txt .
|
|
|
|
|
|
|
| 12 |
RUN pip install --no-cache-dir --upgrade pip && \
|
| 13 |
pip wheel --no-cache-dir --wheel-dir=/wheels -r requirements.txt
|
| 14 |
|
| 15 |
+
# --- STAGE 2: Production ---
|
| 16 |
FROM python:3.11-slim
|
| 17 |
|
|
|
|
| 18 |
ENV PYTHONDONTWRITEBYTECODE=1 \
|
| 19 |
PYTHONUNBUFFERED=1 \
|
| 20 |
PYTHONPATH=/app
|
| 21 |
|
|
|
|
| 22 |
RUN apt-get update && apt-get install -y \
|
| 23 |
libgomp1 \
|
| 24 |
curl \
|
| 25 |
&& rm -rf /var/lib/apt/lists/* \
|
| 26 |
&& useradd --create-home --shell /bin/bash nur
|
| 27 |
|
|
|
|
| 28 |
WORKDIR /app
|
| 29 |
|
| 30 |
+
# Install dependencies from builder
|
| 31 |
COPY --from=builder /wheels /wheels
|
|
|
|
|
|
|
| 32 |
RUN pip install --no-cache-dir --upgrade pip && \
|
| 33 |
pip install --no-cache-dir /wheels/* && \
|
| 34 |
rm -rf /wheels
|
| 35 |
|
| 36 |
+
# 1. Create directory while ROOT
|
| 37 |
RUN mkdir -p /app/models && chown -R nur:nur /app
|
| 38 |
|
| 39 |
+
# 2. Copy code
|
| 40 |
COPY --chown=nur:nur app/ /app/app/
|
| 41 |
|
| 42 |
+
# 3. CRITICAL: Copy and Fix Entrypoint while ROOT
|
| 43 |
+
COPY entrypoint.sh /app/entrypoint.sh
|
| 44 |
+
RUN chmod +x /app/entrypoint.sh && chown nur:nur /app/entrypoint.sh
|
| 45 |
+
|
| 46 |
+
# 4. Switch to User for safety
|
| 47 |
USER nur
|
| 48 |
|
| 49 |
+
# 5. Hugging Face Port
|
| 50 |
+
EXPOSE 7860
|
| 51 |
|
| 52 |
+
# 6. Healthcheck
|
| 53 |
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
| 54 |
+
CMD curl -f http://localhost:7860/health || exit 1
|
| 55 |
|
| 56 |
+
# 7. Start the Brain
|
| 57 |
+
ENTRYPOINT ["/app/entrypoint.sh"]
|
|
|
|
|
|
|
|
|