-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfileDistroless
More file actions
60 lines (46 loc) · 1.2 KB
/
Copy pathDockerfileDistroless
File metadata and controls
60 lines (46 loc) · 1.2 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
52
53
54
55
56
57
58
59
60
# ============================
# 1) Build stage
# ============================
FROM python:3.14-slim AS builder
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
WORKDIR /app
# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
gcc \
&& rm -rf /var/lib/apt/lists/*
# Install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Install PyInstaller
RUN pip install --no-cache-dir pyinstaller
# Copy application
COPY main.py /app/
# Build standalone binary
RUN pyinstaller \
--onedir \
--name main \
--distpath /app/dist \
--workpath /tmp/pyinstaller-build \
--collect-all fastapi \
--collect-all uvicorn \
--collect-all starlette \
--collect-all cryptography \
--collect-all jinja2 \
--collect-all multipart \
main.py
# ============================
# 2) Runtime stage
# ============================
FROM gcr.io/distroless/cc
ENV PYTHONUNBUFFERED=1
WORKDIR /app
# Copy compiled binary
COPY --from=builder /app/dist/main/. /app/
COPY templates/ /app/templates/
COPY static/ /app/static/
# Non-root user
USER 65532
EXPOSE 2000
ENTRYPOINT ["/app/main"]