Skip to content

Commit 4d5513f

Browse files
authored
Merge pull request #41 from nextcloud/feat/use-DOCKER_BUILDKIT
feat: cache python packages for speedup(DOCKER_BUILDKIT=1)
2 parents 1505170 + ca73874 commit 4d5513f

File tree

3 files changed

+37
-19
lines changed

3 files changed

+37
-19
lines changed

Dockerfile

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
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.
711
COPY 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.
2216
RUN 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.
3755
WORKDIR /ex_app/lib
3856
ENTRYPOINT ["/start.sh"]
3957
HEALTHCHECK --interval=2s --timeout=2s --retries=300 CMD /healthcheck.sh

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ help:
3131
.PHONY: build-push
3232
build-push:
3333
docker login ghcr.io
34-
docker buildx build --push --platform linux/arm64/v8,linux/amd64 --tag ghcr.io/nextcloud/app-skeleton-python:latest .
34+
DOCKER_BUILDKIT=1 docker buildx build --push --platform linux/arm64/v8,linux/amd64 --tag ghcr.io/nextcloud/app-skeleton-python:latest .
3535

3636
.PHONY: run30
3737
run29:

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nc_py_api[app]>=0.19.1
1+
nc_py_api[app]>=0.19.2

0 commit comments

Comments
 (0)