Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
51 lines (36 loc) · 1.38 KB
/
Copy pathDockerfile
File metadata and controls
51 lines (36 loc) · 1.38 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
44
45
46
47
48
49
50
51
# syntax=docker/dockerfile:1
# ============================================================
# Stage 1: Build dependencies
# ============================================================
FROM python:3.12-slim AS build
WORKDIR /app
RUN apt-get update && \
apt-get install -y --no-install-recommends gcc libpq-dev && \
rm -rf /var/lib/apt/lists/*
COPY pyproject.toml README.md ./
COPY app/ app/
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir .
# ============================================================
# Stage 2: Production image
# ============================================================
FROM python:3.12-slim
RUN apt-get update && \
apt-get install -y --no-install-recommends libpq5 curl && \
rm -rf /var/lib/apt/lists/*
# Create non-root user
RUN groupadd --system app && useradd --system --gid app app
WORKDIR /app
# Copy installed packages from build stage
COPY --from=build /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
COPY --from=build /usr/local/bin /usr/local/bin
# Copy application code
COPY . .
# Set ownership
RUN chown -R app:app /app
USER app
EXPOSE 8000
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
CMD curl -f http://localhost:8000/up || exit 1
ENTRYPOINT ["./bin/docker-entrypoint.sh"]
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]