⭐
Log in to mark this repository.
OCR bundling
6908c22 · gmorell · 2026-05-08 04:44
Files changed
modified
Dockerfile
+20
−3
@@ -61,7 +61,20 @@ RUN --mount=type=cache,target=/usr/local/cargo/registry \
| 61 | 61 | && cp target/release/registration-token /out/ |
| 62 | 62 | |
| 63 | 63 | # --------------------------------------------------------------------------- |
| 64 | −# Stage 3 — runtime: minimal Debian slim with the binaries + assets + templates. | |
| 64 | +# Stage 3 — ocr-models: pre-fetch the ocrs detection + recognition .rten | |
| 65 | +# models so the OCR worker has them baked into the image. Stage is separate | |
| 66 | +# so the (slow) downloads cache independently from the cargo build. | |
| 67 | +# --------------------------------------------------------------------------- | |
| 68 | +FROM debian:bookworm-slim AS ocr-models | |
| 69 | +RUN apt-get update \ | |
| 70 | + && apt-get install -y --no-install-recommends ca-certificates curl \ | |
| 71 | + && rm -rf /var/lib/apt/lists/* | |
| 72 | +WORKDIR /models | |
| 73 | +RUN curl -fL --retry 3 -o text-detection.rten https://ocrs-models.s3-accelerate.amazonaws.com/text-detection.rten \ | |
| 74 | + && curl -fL --retry 3 -o text-recognition.rten https://ocrs-models.s3-accelerate.amazonaws.com/text-recognition.rten | |
| 75 | + | |
| 76 | +# --------------------------------------------------------------------------- | |
| 77 | +# Stage 4 — runtime: minimal Debian slim with the binaries + assets + templates. | |
| 65 | 78 | # --------------------------------------------------------------------------- |
| 66 | 79 | FROM debian:bookworm-slim AS runtime |
| 67 | 80 | RUN apt-get update \ |
@@ -78,6 +91,10 @@ COPY --from=rust-builder /out/queue-worker /usr/local/bin/dms-queue-worke
| 78 | 91 | COPY --from=rust-builder /out/registration-token /usr/local/bin/dms-registration-token |
| 79 | 92 | COPY --from=assets /app/assets/f /app/assets/f |
| 80 | 93 | COPY --chown=dms:dms templates /app/templates |
| 94 | +# OCR models bundled at a fixed image path — read-only and tied to the app | |
| 95 | +# version. Override via env if you swap to bigger/smaller models later. | |
| 96 | +COPY --from=ocr-models /models/text-detection.rten /opt/dms/models/text-detection.rten | |
| 97 | +COPY --from=ocr-models /models/text-recognition.rten /opt/dms/models/text-recognition.rten | |
| 81 | 98 | |
| 82 | 99 | USER dms |
| 83 | 100 |
@@ -86,8 +103,8 @@ ENV BIND_ADDRESS=0.0.0.0:3007 \
| 86 | 103 | STORAGE_ROOT=/data/storage \ |
| 87 | 104 | AUTO_MIGRATE=true \ |
| 88 | 105 | REGISTRATION_ENABLED=false \ |
| 89 | − OCRS_DETECTION_MODEL=/data/models/text-detection.rten \ | |
| 90 | − OCRS_RECOGNITION_MODEL=/data/models/text-recognition.rten | |
| 106 | + OCRS_DETECTION_MODEL=/opt/dms/models/text-detection.rten \ | |
| 107 | + OCRS_RECOGNITION_MODEL=/opt/dms/models/text-recognition.rten | |
| 91 | 108 | |
| 92 | 109 | EXPOSE 3007 |
| 93 | 110 | VOLUME ["/data"] |
modified
README.md
+7
−11
@@ -64,15 +64,11 @@ just invite-in-pod # bootstrap a registration token
| 64 | 64 | Visit `http://localhost:3007/register?token=<token>`, sign up, generate an |
| 65 | 65 | API token from `/api-tokens` for the Android app. |
| 66 | 66 | |
| 67 | −For OCR to actually run, drop the `ocrs` models into the `dms_data` | |
| 68 | −volume's `models/` directory. With a host-bind variant of compose: | |
| 69 | − | |
| 70 | −```bash | |
| 71 | −just ocr-models # downloads text-detection.rten + text-recognition.rten | |
| 72 | −``` | |
| 73 | − | |
| 74 | −…then bind-mount `./models` to `/data/models` (with `:Z` if you're on | |
| 75 | −SELinux). | |
| 67 | +OCR models (`ocrs` detection + recognition `.rten` files) are bundled | |
| 68 | +into the image at `/opt/dms/models/` so the OCR worker is ready to go on | |
| 69 | +first boot. Override `OCRS_DETECTION_MODEL` / `OCRS_RECOGNITION_MODEL` | |
| 70 | +via env if you ever want to swap them — bigger model, fine-tuned variant, | |
| 71 | +host-mounted file, etc. | |
| 76 | 72 | |
| 77 | 73 | ## Run it (without containers) |
| 78 | 74 |
@@ -114,8 +110,8 @@ All env-driven — defaults make sense for local dev.
| 114 | 110 | | `DMS_PUBLIC_URL` | (unset) | Override what the QR pairing URL encodes when behind a proxy. Falls back to the request's Host header, then the bind address. | |
| 115 | 111 | | `WORKER_KIND` | (required for workers) | `thumbnail` / `ocr` / `describe` / `extract_tags`. Same as `--kind`. | |
| 116 | 112 | | `WORKER_PREFETCH` | `4` | Per-worker concurrency (RabbitMQ basic_qos). Tune CPU-bound (OCR) lower than I/O-bound. | |
| 117 | −| `OCRS_DETECTION_MODEL` | (required for OCR) | Path to `text-detection.rten`. | | |
| 118 | −| `OCRS_RECOGNITION_MODEL` | (required for OCR) | Path to `text-recognition.rten`. | | |
| 113 | +| `OCRS_DETECTION_MODEL` | `/opt/dms/models/text-detection.rten` | Bundled in the image; override to swap models. Required for OCR — outside Docker (e.g. `cargo run`), set this to a downloaded `.rten` file or the worker DLQs jobs with a clear log line. | | |
| 114 | +| `OCRS_RECOGNITION_MODEL` | `/opt/dms/models/text-recognition.rten` | Same as above. | | |
| 119 | 115 | |
| 120 | 116 | ## Auth |
| 121 | 117 |
modified
compose.yml
+2
−2
@@ -69,8 +69,8 @@ services:
| 69 | 69 | DATABASE_URL: postgres://dms_user:dms_password@postgres:5432/dms |
| 70 | 70 | AMQP_URL: amqp://dms_user:dms_password@rabbitmq:5672/%2f |
| 71 | 71 | STORAGE_ROOT: /data/storage |
| 72 | − OCRS_DETECTION_MODEL: /data/models/text-detection.rten | |
| 73 | − OCRS_RECOGNITION_MODEL: /data/models/text-recognition.rten | |
| 72 | + # OCRS models are bundled into the image at /opt/dms/models — only | |
| 73 | + # set OCRS_*_MODEL here if you swap to different model files. | |
| 74 | 74 | WORKER_PREFETCH: "4" |
| 75 | 75 | WORKER_KIND: thumbnail |
| 76 | 76 | volumes: |
Parents: 3632264