Skip to content

Commit a4854b2

Browse files
author
codewitching
committed
add multi-stage dockerfile with test stage
1 parent 622a5a3 commit a4854b2

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

Dockerfile

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
1-
FROM python:3.12-slim
1+
# ======================
2+
# Stage 1: Test stage
3+
# ======================
4+
FROM python:3.12-slim AS test
25

36
WORKDIR /app
47

58
COPY requirements.txt .
6-
RUN pip install --no-cache-dir -r requirements.txt
9+
RUN pip install --no-cache-dir -r requirements.txt pytest
710

811
COPY . .
912

10-
# 👇 THIS IS THE IMPORTANT FIX
11-
ENV PYTHONPATH=/app
12-
1313
CMD ["pytest"]
14+
15+
16+
# ======================
17+
# Stage 2: Production stage
18+
# ======================
19+
FROM python:3.12-slim AS production
20+
21+
WORKDIR /app
22+
23+
COPY requirements.txt .
24+
RUN pip install --no-cache-dir -r requirements.txt
25+
26+
COPY app ./app
27+
COPY app.py .
28+
29+
CMD ["python", "app.py"]

0 commit comments

Comments
 (0)