-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
48 lines (36 loc) · 1.02 KB
/
Dockerfile
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
# Use multi-stage build for smaller final image
FROM python:3.11-slim as builder
# Set working directory
WORKDIR /app
# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Copy only requirements first for better cache utilization
COPY requirements.txt .
COPY setup.py .
COPY README.md .
# Create venv and install dependencies
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
RUN pip install --no-cache-dir -r requirements.txt
# Final stage
FROM python:3.11-slim
# Copy virtual env from builder
COPY --from=builder /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Set working directory
WORKDIR /app
# Copy application code
COPY src/ src/
# Create non-root user
RUN useradd -m -u 1000 appuser
USER appuser
# Set environment variables
ENV PYTHONUNBUFFERED=1
ENV PYTHONPATH=/app/src
# Expose port
EXPOSE 8000
# Default command
ENTRYPOINT ["uvicorn"]
CMD ["mab_platform.api.main:app", "--host", "0.0.0.0", "--port", "8000"]