Spaces:
Paused
Paused
File size: 1,360 Bytes
68da5cc 4525c7c 68da5cc 4525c7c 68da5cc 4525c7c 68da5cc 4525c7c 68da5cc 4525c7c 68da5cc 4525c7c 68da5cc 4525c7c 68da5cc 4525c7c 68da5cc 4525c7c 68da5cc 4525c7c 68da5cc 4525c7c 68da5cc 4525c7c |
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 |
# Stage 1 - Build wheels
FROM python:3.11-slim as builder
# Set working directory
WORKDIR /app
# Install build dependencies
RUN apt-get update && apt-get install -y \
gcc \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
# Install Python dependencies into wheel format
COPY requirements.txt .
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /app/wheels -r requirements.txt
# Stage 2 - Final image
FROM python:3.11-slim
# Create non-root user
RUN useradd -m appuser
# Set working directory
WORKDIR /app
# Install system runtime dependencies
RUN apt-get update && apt-get install -y \
libpq5 \
&& rm -rf /var/lib/apt/lists/*
# Copy built wheels
COPY --from=builder /app/wheels /wheels
COPY --from=builder /app/requirements.txt .
# Install packages from wheels
RUN pip install --no-cache /wheels/*
# Copy app source code
COPY ./app app/
COPY ./alembic.ini .
COPY ./alembic alembic/
# Create runtime directories and set permissions
RUN mkdir -p /app/logs /app/uploads/images /app/uploads/documents /app/backups && \
chown -R appuser:appuser /app
# Switch to non-root user
USER appuser
# Set environment variables
ENV PYTHONPATH=/app \
PYTHONUNBUFFERED=1 \
REDIS_URL=redis://redis:6379/0
# Expose FastAPI port
EXPOSE 7860
# Start the FastAPI server
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
|