Skip to content

Commit 518090d

Browse files
authored
cache python packages for build speedup(DOCKER_BUILDKIT=1) (#15)
Signed-off-by: Oleksander Piskun <[email protected]>
1 parent 5106478 commit 518090d

File tree

3 files changed

+34
-27
lines changed

3 files changed

+34
-27
lines changed

Dockerfile

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
1-
FROM python:3.11-slim-bookworm
1+
FROM python:3.12-slim-bookworm AS builder
22

3-
RUN apt-get update && apt-get install -y curl procps iputils-ping netcat-traditional && \
4-
apt-get clean && \
5-
rm -rf /var/lib/apt/lists/*
3+
RUN apt-get update && apt-get install -y curl && \
4+
apt-get clean && rm -rf /var/lib/apt/lists/*
65

76
ARG BUILD_TYPE
87
COPY requirements.txt /
98

10-
ADD /ex_app/cs[s] /ex_app/css
11-
ADD /ex_app/im[g] /ex_app/img
12-
ADD /ex_app/j[s] /ex_app/js
13-
ADD /ex_app/l10[n] /ex_app/l10n
14-
ADD /ex_app/li[b] /ex_app/lib
15-
16-
COPY --chmod=775 healthcheck.sh /
17-
COPY --chmod=775 start.sh /
18-
199
# Download and install FRP client
2010
RUN set -ex; \
2111
ARCH=$(uname -m); \
@@ -33,20 +23,37 @@ RUN set -ex; \
3323
rm -rf /tmp/frp /tmp/frp.tar.gz
3424

3525
# Installing PyTorch based on BUILD_TYPE
36-
RUN ARCH=$(uname -m) && \
26+
RUN --mount=type=cache,target=/root/.cache/pip \
27+
ARCH=$(uname -m) && \
3728
if [ "$ARCH" = "aarch64" ]; then \
3829
echo "Installing PyTorch for ARM64"; \
39-
python3 -m pip install torch==2.4.1 torchvision torchaudio; \
30+
python3 -m pip install --root-user-action=ignore torch==2.4.1 torchvision torchaudio; \
4031
elif [ "$BUILD_TYPE" = "rocm" ]; then \
41-
python3 -m pip install torch==2.4.1 torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm6.1; \
32+
python3 -m pip install --root-user-action=ignore torch==2.4.1 torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm6.1; \
4233
elif [ "$BUILD_TYPE" = "cpu" ]; then \
43-
python3 -m pip install torch==2.4.1 torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu; \
34+
python3 -m pip install --root-user-action=ignore torch==2.4.1 torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu; \
4435
else \
45-
python3 -m pip install torch==2.4.1 torchvision torchaudio; \
36+
python3 -m pip install --root-user-action=ignore torch==2.4.1 torchvision torchaudio; \
4637
fi
4738

48-
RUN \
49-
python3 -m pip install -r requirements.txt && rm -rf ~/.cache && rm requirements.txt
39+
RUN --mount=type=cache,target=/root/.cache/pip \
40+
python3 -m pip install --root-user-action=ignore -r requirements.txt && rm requirements.txt
41+
42+
FROM python:3.12-slim-bookworm
43+
44+
COPY --from=builder /usr/local/ /usr/local/
45+
46+
RUN apt-get update && apt-get install -y curl procps iputils-ping netcat-traditional && \
47+
apt-get clean && rm -rf /var/lib/apt/lists/*
48+
49+
ADD /ex_app/cs[s] /ex_app/css
50+
ADD /ex_app/im[g] /ex_app/img
51+
ADD /ex_app/j[s] /ex_app/js
52+
ADD /ex_app/l10[n] /ex_app/l10n
53+
ADD /ex_app/li[b] /ex_app/lib
54+
55+
COPY --chmod=775 healthcheck.sh /
56+
COPY --chmod=775 start.sh /
5057

5158
WORKDIR /ex_app/lib
5259
ENTRYPOINT ["/start.sh"]

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ help:
2626
.PHONY: build-push
2727
build-push:
2828
docker login ghcr.io
29-
docker buildx build --push --platform linux/arm64/v8,linux/amd64 --tag ghcr.io/nextcloud/$(APP_ID):release --build-arg BUILD_TYPE=cpu .
30-
docker buildx build --push --platform linux/amd64 --tag ghcr.io/nextcloud/$(APP_ID):release-cuda --build-arg BUILD_TYPE=cuda .
31-
docker buildx build --push --platform linux/amd64 --tag ghcr.io/nextcloud/$(APP_ID):release-rocm --build-arg BUILD_TYPE=rocm .
29+
DOCKER_BUILDKIT=1 docker buildx build --progress=plain --push --platform linux/arm64/v8,linux/amd64 --tag ghcr.io/nextcloud/$(APP_ID):release --build-arg BUILD_TYPE=cpu .
30+
DOCKER_BUILDKIT=1 docker buildx build --progress=plain --push --platform linux/amd64 --tag ghcr.io/nextcloud/$(APP_ID):release-cuda --build-arg BUILD_TYPE=cuda .
31+
DOCKER_BUILDKIT=1 docker buildx build --progress=plain --push --platform linux/amd64 --tag ghcr.io/nextcloud/$(APP_ID):release-rocm --build-arg BUILD_TYPE=rocm .
3232

3333
.PHONY: build-push-latest
3434
build-push-latest:
3535
docker login ghcr.io
36-
docker buildx build --push --platform linux/arm64/v8,linux/amd64 --tag ghcr.io/nextcloud/$(APP_ID):latest --build-arg BUILD_TYPE=cpu .
37-
docker buildx build --push --platform linux/amd64 --tag ghcr.io/nextcloud/$(APP_ID):latest-cuda --build-arg BUILD_TYPE=cuda .
38-
docker buildx build --push --platform linux/amd64 --tag ghcr.io/nextcloud/$(APP_ID):latest-rocm --build-arg BUILD_TYPE=rocm .
36+
DOCKER_BUILDKIT=1 docker buildx build --progress=plain --push --platform linux/arm64/v8,linux/amd64 --tag ghcr.io/nextcloud/$(APP_ID):latest --build-arg BUILD_TYPE=cpu .
37+
DOCKER_BUILDKIT=1 docker buildx build --progress=plain --push --platform linux/amd64 --tag ghcr.io/nextcloud/$(APP_ID):latest-cuda --build-arg BUILD_TYPE=cuda .
38+
DOCKER_BUILDKIT=1 docker buildx build --progress=plain --push --platform linux/amd64 --tag ghcr.io/nextcloud/$(APP_ID):latest-rocm --build-arg BUILD_TYPE=rocm .
3939

4040
.PHONY: run30
4141
run30:

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)