Skip to content

Commit 23d2ce1

Browse files
committed
user Docker Stage Build
Signed-off-by: Oleksander Piskun <[email protected]>
1 parent 44110b1 commit 23d2ce1

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

Dockerfile

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
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.
711
COPY requirements.txt /
8-
912
RUN --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)
1216
ADD /ex_app/cs[s] /ex_app/css
1317
ADD /ex_app/im[g] /ex_app/img
1418
ADD /ex_app/j[s] /ex_app/js
1519
ADD /ex_app/l10[n] /ex_app/l10n
1620
ADD /ex_app/li[b] /ex_app/lib
1721

22+
# Copy scripts with the proper permissions.
1823
COPY --chmod=775 healthcheck.sh /
1924
COPY --chmod=775 start.sh /
2025

21-
# Download and install FRP client
26+
# Download and install FRP client into /usr/local/bin.
2227
RUN 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.
3759
WORKDIR /ex_app/lib
3860
ENTRYPOINT ["/start.sh"]
3961
HEALTHCHECK --interval=2s --timeout=2s --retries=300 CMD /healthcheck.sh

0 commit comments

Comments
 (0)