diff --git a/Dockerfile b/Dockerfile index 8c2b637..0fc5ebe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,18 @@ -FROM python:3.11-slim-bookworm +############################# +# Stage 1: Builder +############################# +FROM python:3.12-slim-bookworm AS builder -RUN apt-get update && apt-get install -y curl procps && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* +# Install build dependencies +RUN apt-get update && apt-get install -y curl && \ + apt-get clean && rm -rf /var/lib/apt/lists/* +# Copy requirements and install Python dependencies using a cache mount. COPY requirements.txt / +RUN --mount=type=cache,target=/root/.cache/pip \ + python3 -m pip install --root-user-action=ignore -r requirements.txt && rm requirements.txt -RUN \ - python3 -m pip install -r requirements.txt && rm -rf ~/.cache && rm requirements.txt - -ADD /ex_app/cs[s] /ex_app/css -ADD /ex_app/im[g] /ex_app/img -ADD /ex_app/j[s] /ex_app/js -ADD /ex_app/l10[n] /ex_app/l10n -ADD /ex_app/li[b] /ex_app/lib - -COPY --chmod=775 healthcheck.sh / -COPY --chmod=775 start.sh / - -# Download and install FRP client +# Download and install FRP client into /usr/local/bin. RUN set -ex; \ ARCH=$(uname -m); \ if [ "$ARCH" = "aarch64" ]; then \ @@ -34,6 +28,30 @@ RUN set -ex; \ chmod +x /usr/local/bin/frpc; \ rm -rf /tmp/frp /tmp/frp.tar.gz +############################# +# Stage 2: Final Runtime Image +############################# +FROM python:3.12-slim-bookworm + +# Copy installed Python packages and FRP client from the builder. +COPY --from=builder /usr/local/ /usr/local/ + +# Install any runtime apt packages your app needs. +RUN apt-get update && apt-get install -y curl procps && \ + apt-get clean && rm -rf /var/lib/apt/lists/* + +# Add application files. +ADD /ex_app/cs[s] /ex_app/css +ADD /ex_app/im[g] /ex_app/img +ADD /ex_app/j[s] /ex_app/js +ADD /ex_app/l10[n] /ex_app/l10n +ADD /ex_app/li[b] /ex_app/lib + +# Copy scripts with the proper permissions. +COPY --chmod=775 healthcheck.sh / +COPY --chmod=775 start.sh / + +# Set working directory and define entrypoint/healthcheck. WORKDIR /ex_app/lib ENTRYPOINT ["/start.sh"] HEALTHCHECK --interval=2s --timeout=2s --retries=300 CMD /healthcheck.sh diff --git a/Makefile b/Makefile index a904b9a..f82273d 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ help: .PHONY: build-push build-push: docker login ghcr.io - docker buildx build --push --platform linux/arm64/v8,linux/amd64 --tag ghcr.io/nextcloud/app-skeleton-python:latest . + DOCKER_BUILDKIT=1 docker buildx build --push --platform linux/arm64/v8,linux/amd64 --tag ghcr.io/nextcloud/app-skeleton-python:latest . .PHONY: run30 run29: diff --git a/requirements.txt b/requirements.txt index caac5a9..ccef928 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -nc_py_api[app]>=0.19.1 +nc_py_api[app]>=0.19.2