⭐
Log in to mark this repository.
Image build: fetch the OCR models with ADD instead of RUN curl
248c3c7 · Gabriel Morell · 2026-09-26 04:07
Message
{commit_body(@commit)}
Files changed
modified
Dockerfile
+8
−14
@@ -32,10 +32,6 @@ RUN cd assets \
| 32 | 32 | # (Cargo.toml/Cargo.lock first, then src) still helps local rebuilds. |
| 33 | 33 | # --------------------------------------------------------------------------- |
| 34 | 34 | FROM rust:1.92-bookworm AS rust-builder |
| 35 | −# mkdir in a RUN rather than letting WORKDIR create it: on the forge's | |
| 36 | −# BuildKit runner a WORKDIR-created directory isn't writable by the RUN | |
| 37 | −# steps' root, and cargo writes target/ straight into it. | |
| 38 | −RUN mkdir -p /app | |
| 39 | 35 | WORKDIR /app |
| 40 | 36 | |
| 41 | 37 | RUN apt-get update \ |
@@ -67,17 +63,15 @@ RUN cargo build --release \
| 67 | 63 | # Stage 3 — ocr-models: pre-fetch the ocrs detection + recognition .rten |
| 68 | 64 | # models so the OCR worker has them baked into the image. Stage is separate |
| 69 | 65 | # so the (slow) downloads cache independently from the cargo build. |
| 66 | +# | |
| 67 | +# ADD rather than `RUN curl`: on the forge's BuildKit runner curl could not | |
| 68 | +# create its output file ("Permission denied", even in a freshly mkdir'd | |
| 69 | +# directory), while the builder fetching the URL itself needs no RUN step | |
| 70 | +# at all — and so no base image, apt or curl either. | |
| 70 | 71 | # --------------------------------------------------------------------------- |
| 71 | −FROM debian:bookworm-slim AS ocr-models | |
| 72 | −RUN apt-get update \ | |
| 73 | − && apt-get install -y --no-install-recommends ca-certificates curl \ | |
| 74 | − && rm -rf /var/lib/apt/lists/* | |
| 75 | −# Same WORKDIR caveat as rust-builder: curl got "Permission denied" writing | |
| 76 | −# into a WORKDIR-created /models there. | |
| 77 | −RUN mkdir -p /models | |
| 78 | −WORKDIR /models | |
| 79 | −RUN curl -fL --retry 3 -o text-detection.rten https://ocrs-models.s3-accelerate.amazonaws.com/text-detection.rten \ | |
| 80 | − && curl -fL --retry 3 -o text-recognition.rten https://ocrs-models.s3-accelerate.amazonaws.com/text-recognition.rten | |
| 72 | +FROM scratch AS ocr-models | |
| 73 | +ADD --chmod=0644 https://ocrs-models.s3-accelerate.amazonaws.com/text-detection.rten /models/text-detection.rten | |
| 74 | +ADD --chmod=0644 https://ocrs-models.s3-accelerate.amazonaws.com/text-recognition.rten /models/text-recognition.rten | |
| 81 | 75 | |
| 82 | 76 | # --------------------------------------------------------------------------- |
| 83 | 77 | # Stage 4 — runtime: minimal Debian slim with the binaries + assets + templates. |
Parents: 0074a50