Skip to content

Commit 0663399

Browse files
author
LazyFP Dev
committed
optimize Dockerfile: multi-stage build to reduce image size
1 parent 9911d35 commit 0663399

1 file changed

Lines changed: 29 additions & 5 deletions

File tree

Dockerfile

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,41 @@
1-
FROM python:3.11-slim
1+
FROM python:3.11-slim AS builder
22

33
ENV PYTHONDONTWRITEBYTECODE=1 \
44
PYTHONUNBUFFERED=1
55

6-
WORKDIR /app
6+
WORKDIR /build
77

8-
RUN apt-get update && apt-get install -y --no-install-recommends libmagic1 && rm -rf /var/lib/apt/lists/*
8+
RUN apt-get update && apt-get install -y --no-install-recommends \
9+
libmagic1 \
10+
gcc \
11+
&& rm -rf /var/lib/apt/lists/*
912

1013
COPY requirements.txt .
11-
RUN pip install --no-cache-dir -r requirements.txt
14+
RUN sed -i 's/\\$//; s/--hash=.*$//' requirements.txt && \
15+
grep -v '^$\|^#\|via ' requirements.txt > clean-requirements.txt && \
16+
pip install --no-cache-dir --prefix=/install -r clean-requirements.txt
1217

1318
COPY . .
14-
RUN pip install --no-cache-dir .
19+
RUN pip install --no-cache-dir --prefix=/install .
20+
21+
FROM python:3.11-slim
22+
23+
ENV PYTHONDONTWRITEBYTECODE=1 \
24+
PYTHONUNBUFFERED=1 \
25+
PATH="/install/bin:$PATH" \
26+
PYTHONPATH="/install/lib/python3.11/site-packages"
27+
28+
WORKDIR /app
29+
30+
RUN apt-get update && apt-get install -y --no-install-recommends \
31+
libmagic1 \
32+
&& rm -rf /var/lib/apt/lists/*
33+
34+
COPY --from=builder /install /install
35+
COPY --from=builder /build/app.py /build/main.py /build/config/ /app/
36+
COPY --from=builder /build/extractors/ /app/extractors/
37+
COPY --from=builder /build/core/ /app/core/
38+
COPY --from=builder /build/static/ /app/static/
1539

1640
RUN mkdir -p fp/dump fp/organized
1741

0 commit comments

Comments
 (0)