-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
43 lines (28 loc) · 1.04 KB
/
Copy pathDockerfile
File metadata and controls
43 lines (28 loc) · 1.04 KB
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
# Stage 1: Builder
FROM python:3.11-slim AS builder
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
&& rm -rf /var/lib/apt/lists/*
RUN python -m venv /app/.venv
ENV PATH="/app/.venv/bin:$PATH"
COPY pyproject.toml /app/
# Create dummy src structure to allow dependencies installation via pip
RUN mkdir -p /app/src && touch /app/src/__init__.py
RUN pip install --no-cache-dir --upgrade pip "setuptools>=83.0.0" && \
pip install --no-cache-dir .
# Stage 2: Runtime
FROM python:3.11-slim AS runtime
WORKDIR /app
RUN python -m pip install --no-cache-dir --upgrade pip "setuptools>=83.0.0" wheel
RUN groupadd -g 1000 appuser && \
useradd -u 1000 -g appuser -m -s /bin/bash appuser
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PATH="/app/.venv/bin:$PATH"
COPY --from=builder /app/.venv /app/.venv
COPY src/ /app/src/
RUN chown -R appuser:appuser /app
USER appuser
EXPOSE 8000
ENTRYPOINT ["uvicorn", "src.api.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "4"]