1- FROM python:3.12-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 /
8-
912RUN --mount=type=cache,target=/root/.cache/pip \
10- python3 -m pip install -r requirements.txt && rm requirements.txt
13+ python3 -m pip install -r requirements.txt && rm requirements.txt
1114
15+ # Add application files (using your ADD patterns)
1216ADD /ex_app/cs[s] /ex_app/css
1317ADD /ex_app/im[g] /ex_app/img
1418ADD /ex_app/j[s] /ex_app/js
1519ADD /ex_app/l10[n] /ex_app/l10n
1620ADD /ex_app/li[b] /ex_app/lib
1721
22+ # Copy scripts with the proper permissions.
1823COPY --chmod=775 healthcheck.sh /
1924COPY --chmod=775 start.sh /
2025
21- # Download and install FRP client
26+ # Download and install FRP client into /usr/local/bin.
2227RUN set -ex; \
2328 ARCH=$(uname -m); \
2429 if [ "$ARCH" = "aarch64" ]; then \
@@ -34,6 +39,23 @@ RUN set -ex; \
3439 chmod +x /usr/local/bin/frpc; \
3540 rm -rf /tmp/frp /tmp/frp.tar.gz
3641
42+ # ############################
43+ # Stage 2: Final Runtime Image
44+ # ############################
45+ FROM python:3.12-slim-bookworm
46+
47+ # Install any runtime apt packages your app needs.
48+ RUN apt-get update && apt-get install -y curl procps && \
49+ apt-get clean && rm -rf /var/lib/apt/lists/*
50+
51+ # Copy installed Python packages and FRP client from the builder.
52+ COPY --from=builder /usr/local/ /usr/local/
53+ # Copy application files and scripts from the builder.
54+ COPY --from=builder /ex_app/ /ex_app/
55+ COPY --from=builder /healthcheck.sh /healthcheck.sh
56+ COPY --from=builder /start.sh /start.sh
57+
58+ # Set working directory and define entrypoint/healthcheck.
3759WORKDIR /ex_app/lib
3860ENTRYPOINT ["/start.sh" ]
3961HEALTHCHECK --interval=2s --timeout=2s --retries=300 CMD /healthcheck.sh
0 commit comments