Spaces:
Sleeping
Sleeping
File size: 2,054 Bytes
c173896 34e27fb c173896 34e27fb c173896 34e27fb c173896 34e27fb c173896 34e27fb c173896 34e27fb c173896 34e27fb c173896 34e27fb c173896 34e27fb c173896 34e27fb c173896 34e27fb c173896 34e27fb c173896 34e27fb c173896 34e27fb c173896 34e27fb c173896 34e27fb c173896 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | # =========================
# Stage 1 — Builder
# =========================
FROM python:3.13-slim AS builder
WORKDIR /app
# Install system deps
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc curl wget \
&& rm -rf /var/lib/apt/lists/*
# Install uv (fast dependency manager)
RUN pip install --no-cache-dir uv
# Install Dapr CLI
RUN curl -fsSL https://raw.githubusercontent.com/dapr/cli/master/install/install.sh | /bin/bash
# Init dapr runtime (slim = no Redis/Zipkin containers)
RUN dapr init --slim
# Copy dependency files first (better caching)
COPY pyproject.toml uv.lock* ./
# Create venv + install deps
ENV UV_SYSTEM_PYTHON=0
RUN uv venv /app/.venv && \
. /app/.venv/bin/activate && \
uv pip install -r pyproject.toml
# Copy app code
COPY . .
# =========================
# Stage 2 — Runner
# =========================
FROM python:3.13-slim AS runner
# Create non-root user
RUN groupadd --system --gid 1001 appgroup && \
useradd --system --uid 1001 --gid appgroup --create-home appuser
WORKDIR /app
# Copy virtual environment
COPY --from=builder /app/.venv /app/.venv
# Copy app source
COPY --from=builder /app/src /app/src
# Copy Dapr binaries + config
COPY --from=builder /usr/local/bin/dapr /usr/local/bin/dapr
COPY --from=builder /root/.dapr /home/appuser/.dapr
# Permissions
RUN chown -R appuser:appgroup /app /home/appuser/.dapr
USER appuser
# Environment
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV PORT=7860
# Expose ports
EXPOSE 7860 3500
# Healthcheck (matches FastAPI port)
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:7860/health || exit 1
# =========================
# Start Dapr + FastAPI
# =========================
CMD ["/bin/sh", "-c", "\
/home/appuser/.dapr/bin/daprd \
--app-id taskflow \
--app-port 7860 \
--dapr-http-port 3500 \
--resources-path /home/appuser/.dapr/components \
& \
/app/.venv/bin/uvicorn src.main:app --host 0.0.0.0 --port 7860 \
"]
|