@@ -10,16 +10,9 @@ RUN npm ci --legacy-peer-deps --no-audit --no-fund
1010COPY ./frontend/ ./
1111RUN npm run build
1212
13- # Runtime image
14- FROM python:3.11-slim AS deploy-stage
15-
16- ARG DOCKER_COMPOSE_VERSION=v2.40.3
17-
18- ENV PYTHONIOENCODING=UTF-8
19- ENV THEME=Default
20- ENV PYTHONPATH=/api
13+ # Build Python wheels in an isolated stage so compiler toolchains do not land in runtime.
14+ FROM python:3.11-slim AS python-wheel-builder
2115
22- WORKDIR /api
2316COPY ./backend/requirements.txt ./
2417
2518RUN apt-get update && \
@@ -34,42 +27,41 @@ RUN apt-get update && \
3427 zlib1g-dev \
3528 libyaml-dev \
3629 python3-dev \
37- nginx \
38- curl \
3930 ca-certificates \
40- bash && \
31+ && \
4132 rm -rf /var/lib/apt/lists/*
4233
43- RUN set -eux; \
44- arch="$(uname -m)" ; \
45- case "${arch}" in \
46- x86_64) compose_arch="x86_64" ;; \
47- aarch64) compose_arch="aarch64" ;; \
48- armv7l) compose_arch="armv7" ;; \
49- armv6l) compose_arch="armv6" ;; \
50- ppc64le) compose_arch="ppc64le" ;; \
51- s390x) compose_arch="s390x" ;; \
52- riscv64) compose_arch="riscv64" ;; \
53- *) echo "Unsupported architecture: ${arch}" && exit 1 ;; \
54- esac; \
55- curl -fL "https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-linux-${compose_arch}" -o /usr/local/bin/docker-compose; \
56- chmod +x /usr/local/bin/docker-compose
57-
5834RUN pip3 install --upgrade pip setuptools wheel && \
59- pip3 install --no-cache-dir -r requirements.txt && \
60- apt-get purge -y --auto-remove \
61- build-essential \
62- pkg-config \
63- libffi-dev \
64- libssl-dev \
65- libpq-dev \
66- default-libmysqlclient-dev \
67- libjpeg-dev \
68- zlib1g-dev \
69- libyaml-dev \
70- python3-dev && \
35+ pip3 wheel --wheel-dir /wheels -r requirements.txt setuptools
36+
37+ # Runtime image
38+ FROM python:3.11-slim AS deploy-stage
39+
40+ ENV PYTHONIOENCODING=UTF-8
41+ ENV THEME=Default
42+ ENV PYTHONPATH=/api
43+
44+ WORKDIR /api
45+ COPY ./backend/requirements.txt ./
46+
47+ RUN apt-get update && \
48+ apt-get install -y --no-install-recommends \
49+ nginx \
50+ docker-compose \
51+ ca-certificates \
52+ bash \
53+ libpq5 \
54+ libmariadb3 \
55+ libjpeg62-turbo \
56+ && \
7157 rm -rf /var/lib/apt/lists/*
7258
59+ COPY --from=python-wheel-builder /wheels /wheels
60+
61+ RUN pip3 install --no-cache-dir --no-index --find-links=/wheels setuptools && \
62+ pip3 install --no-cache-dir --no-index --find-links=/wheels -r requirements.txt && \
63+ rm -rf /wheels
64+
7365RUN groupadd -r abc && useradd -r -g abc abc
7466
7567COPY ./backend/ /api/
0 commit comments