1- FROM python:3.11-slim-bookworm
1+ # ############################
2+ # Stage 1: Builder
3+ # ############################
4+ FROM python:3.12-slim-bookworm AS builder
25
3- RUN apt-get update && apt-get install -y curl procps && \
4- apt-get clean && \
5- rm -rf /var/lib/apt/lists/*
6+ # Install build dependencies
7+ RUN apt-get update && apt-get install -y curl && \
8+ apt-get clean && rm -rf /var/lib/apt/lists/*
69
10+ # Copy requirements and install Python dependencies using a cache mount.
711COPY requirements.txt /
12+ RUN --mount=type=cache,target=/root/.cache/pip \
13+ python3 -m pip install --root-user-action=ignore -r requirements.txt && rm requirements.txt
814
9- RUN \
10- python3 -m pip install -r requirements.txt && rm -rf ~/.cache && rm requirements.txt
11-
12- ADD /ex_app/cs[s] /ex_app/css
13- ADD /ex_app/im[g] /ex_app/img
14- ADD /ex_app/j[s] /ex_app/js
15- ADD /ex_app/l10[n] /ex_app/l10n
16- ADD /ex_app/li[b] /ex_app/lib
17-
18- COPY --chmod=775 healthcheck.sh /
19- COPY --chmod=775 start.sh /
20-
21- # Download and install FRP client
15+ # Download and install FRP client into /usr/local/bin.
2216RUN set -ex; \
2317 ARCH=$(uname -m); \
2418 if [ "$ARCH" = "aarch64" ]; then \
@@ -34,6 +28,30 @@ RUN set -ex; \
3428 chmod +x /usr/local/bin/frpc; \
3529 rm -rf /tmp/frp /tmp/frp.tar.gz
3630
31+ # ############################
32+ # Stage 2: Final Runtime Image
33+ # ############################
34+ FROM python:3.12-slim-bookworm
35+
36+ # Copy installed Python packages and FRP client from the builder.
37+ COPY --from=builder /usr/local/ /usr/local/
38+
39+ # Install any runtime apt packages your app needs.
40+ RUN apt-get update && apt-get install -y curl procps && \
41+ apt-get clean && rm -rf /var/lib/apt/lists/*
42+
43+ # Add application files.
44+ ADD /ex_app/cs[s] /ex_app/css
45+ ADD /ex_app/im[g] /ex_app/img
46+ ADD /ex_app/j[s] /ex_app/js
47+ ADD /ex_app/l10[n] /ex_app/l10n
48+ ADD /ex_app/li[b] /ex_app/lib
49+
50+ # Copy scripts with the proper permissions.
51+ COPY --chmod=775 healthcheck.sh /
52+ COPY --chmod=775 start.sh /
53+
54+ # Set working directory and define entrypoint/healthcheck.
3755WORKDIR /ex_app/lib
3856ENTRYPOINT ["/start.sh" ]
3957HEALTHCHECK --interval=2s --timeout=2s --retries=300 CMD /healthcheck.sh
0 commit comments