From 1e87930bbb852377f5755e0060060ff0da7b679c Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Sun, 27 Oct 2024 15:32:46 -0700 Subject: [PATCH] Use uv to construct Alpine Docker image --- .docker/Dockerfile.alpine | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/.docker/Dockerfile.alpine b/.docker/Dockerfile.alpine index 979a41054..0befb9f9b 100644 --- a/.docker/Dockerfile.alpine +++ b/.docker/Dockerfile.alpine @@ -8,7 +8,7 @@ # Details # https://gitlab.alpinelinux.org/alpine/aports/-/issues/16143 # https://github.com/ocrmypdf/OCRmyPDF/issues/1395 -FROM alpine:3.19 as base +FROM alpine:3.19 AS base ENV LANG=C.UTF-8 ENV TZ=UTC @@ -17,13 +17,14 @@ RUN apk add --no-cache \ python3 \ zlib -FROM base as builder +FROM base AS builder RUN apk add --no-cache \ ca-certificates \ git \ python3-dev \ - py3-pip + py3-pip \ + curl # On arm64, we need to build cffi from source. ARG TARGETPLATFORM @@ -45,12 +46,12 @@ COPY . /app WORKDIR /app -RUN python3 -m venv .venv +RUN curl -LsSf https://astral.sh/uv/0.4.27/install.sh | sh -RUN source .venv/bin/activate \ - && python3 -m pip install --no-cache-dir --upgrade pip \ - && python3 -m pip install --no-cache-dir wheel \ - && python3 -m pip install --no-cache-dir .[test,webservice,watcher] +ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy + +# Instead of restarting the shell, use uv directly from its installed location. +RUN /root/.cargo/bin/uv sync --extra test --extra webservice --extra watcher FROM base @@ -73,17 +74,7 @@ RUN apk add --no-cache \ WORKDIR /app -COPY --from=builder /usr/local/lib/ /usr/local/lib/ -COPY --from=builder /usr/local/bin/ /usr/local/bin/ - -COPY --from=builder /app/.venv/ /app/.venv/ - -COPY --from=builder /app/misc/webservice.py /app/ -COPY --from=builder /app/misc/watcher.py /app/ - -# Copy minimal project files to get the test suite. -COPY --from=builder /app/pyproject.toml /app/README.md /app/ -COPY --from=builder /app/tests /app/tests +COPY --from=builder --chown=app:app /app /app ENV PATH="/app/.venv/bin:${PATH}"