Skip to content

Commit 564d5f4

Browse files
committed
Optimize image size with multi-stage build
1 parent 47587b1 commit 564d5f4

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

Dockerfile

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
FROM python:3.13-slim-bookworm
1+
FROM python:3.13-slim-bookworm AS builder
22

3-
# Installing/Updating system dependencies
3+
# Installing build dependencies
44
RUN apt update -y && \
55
apt install -y --no-install-recommends \
6-
postgresql git curl \
6+
postgresql-client git curl \
77
&& rm -rf /var/lib/apt/lists/*
88

99
# Install rust toolchain
@@ -14,12 +14,21 @@ WORKDIR /bot
1414

1515
# Install python dependencies
1616
COPY requirements.txt ./
17-
RUN pip install -r requirements.txt
17+
RUN pip install --no-cache-dir -r requirements.txt
18+
19+
FROM python:3.13-slim-bookworm
20+
21+
# Copy installed Python packages from builder
22+
COPY --from=builder /usr/local /usr/local
1823

1924
# Disable output buffering
2025
ENV PYTHONUNBUFFERED=1
2126

2227
# Copy source code
2328
COPY . .
2429

30+
# Generate __pycache__ directories
31+
ENV PYTHONDONTWRITEBYTECODE=1
32+
RUN python -m compileall -q app
33+
2534
CMD ["python3", "main.py"]

app/common

0 commit comments

Comments
 (0)