readest/docker
Huang Xin 8076905ce5
Some checks are pending
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
CodeQL Advanced / Analyze (rust) (push) Waiting to run
Publish Docker image / build (linux/amd64, ubuntu-latest) (push) Waiting to run
Publish Docker image / build (linux/arm64, ubuntu-24.04-arm) (push) Waiting to run
Publish Docker image / merge (push) Blocked by required conditions
Build with Nix / tests (push) Waiting to run
PR checks / nix_flake_check (push) Waiting to run
PR checks / rust_lint (push) Waiting to run
PR checks / koplugin_rust_lint (push) Waiting to run
PR checks / build_web_app (push) Waiting to run
PR checks / test_web_app (1) (push) Waiting to run
PR checks / test_web_app (2) (push) Waiting to run
PR checks / test_extensions (push) Waiting to run
PR checks / build_tauri_app (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
Deploy to vercel on merge / build_and_deploy (push) Waiting to run
feat(translation): custom translation providers with a prompt library (#6582)
* feat(translation): custom translation providers with a prompt library

Users can add their own translation backends and use them anywhere Readest
translates (inline translation, the translator popup, the updater):

- OpenAI-compatible LLM (OpenAI, DeepSeek, OpenRouter, SiliconFlow, Gemini,
  Ollama, LM Studio, ...): base URL + key + model. Concurrent paragraph
  requests are coalesced into numbered batches; a reply with the wrong block
  count falls back to one request per paragraph. Reasoning blocks are stripped.
- DeepL with the user's own Free/Pro key (app only; DeepL sends no CORS
  headers).

AI translators use a prompt library: a built-in Default prompt plus named
user prompts with {{sourceLang}} {{targetLang}} {{bookTitle}} {{bookAuthor}}
placeholders, chosen per book. Output-format rules are appended by code, and
the cache key folds in the model and the rendered prompt so edits yield fresh
translations.

Requests go straight from the device through getAIFetch; custom providers
never touch the Readest translation quota. Providers and prompts sync as the
custom_translator / translation_prompt replica kinds under one "Translators"
category, with apiKey encrypted; backups strip the key unless credentials are
included.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(translation): address review on custom translators

- Strip only a leading <think> block so a quoted </think> survives.
- Make the DeepL 429 retry wait abortable and cap Retry-After at 10s.
- Associate the editor labels with their inputs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(translation): load the AI SDK lazily in the custom LLM translator

The reader imports the translator registry unconditionally, and the AI SDK
pulls in Node-only modules at import time, which broke the browser test that
imports useTextTranslation. Load ai + @ai-sdk/openai-compatible once, on
first use. Also drop the DeepL retry-wait abort listener once the wait ends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(translation): stop the LLM request timeout once the reply arrives

tauriFetch cancels its request from the signal's abort listener and leaves
that call's rejection unhandled. With AbortSignal.timeout, the timer fired
60 s after every finished request and raised "The resource id ... is
invalid". The timeout is now a cleared timer on an AbortController.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(translation): make custom translators a premium feature

Custom translators follow the other premium features (isCustomizationAllowed:
Plus, Pro, Full Customization, or a self-hosted deployment). The check reads
the session token, so a reader never treats a premium user as free while the
plan loads.

- Settings: the Custom Translators row shows a Premium badge and routes free
  users to the plans page and signed-out users to sign-in.
- Runtime: custom providers carry premiumRequired; isTranslatorAvailable
  excludes them without premium, so inline translation, the popup and the
  updater fall back to a built-in provider. The dropdowns list them as
  "Name (Premium)", disabled, and the Prompt row is hidden.
- NavigationRow gains an optional badge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(translation): customizable font, style, size and color for translated text

Language settings gain a Translated Text group: Font (the book's, or the
reader's serif, sans-serif or monospace font), Font Style (normal, italic,
bold, bold italic), Font Size (relative to the paragraph) and Text Color.
The rules go on .translation-target-block, so translated TOC entries keep
their look, and the defaults leave translations styled like the book.

The color is saved when the picker closes, not on every drag tick, and the
settings are not rewritten for a profile saved before these keys existed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(translation): give the popup layout browser test a decodable token

The premium check for custom translators decodes the session token, and
'test-token' is not a JWT.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(translation): relabel the popup's providers when the session changes

The popup derived provider labels and disabled flags only when the
translator list changed, so a sign-in or a token refresh that changed
premium eligibility left "(Premium)" or "(Login Required)" stale.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(translation): accept batch markers followed by text on the same line

Small local models such as gemma3 reply "[1]Translation…" instead of
putting the marker on its own line. The strict split rejected every such
batch and re-sent each paragraph on its own, so a batch cost one wasted
request. The block count and 1..n order checks still guard the split.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(translation): start translating when it is switched on in Settings

The reader's translation hook only re-runs when the viewSettings object
changes. Settings saved Enable Translation in place, so the book stayed
untranslated until it was reopened. Publish a new object, as the toolbar
toggle and the provider and prompt selects already do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* perf(translation): batch 4 paragraphs per LLM request, 4 requests in flight

Measured against deepseek-flash and a local gemma3 with the reader's
scheduling on 16 paragraphs: batches of up to 8 with 2 in flight made the
first paragraph wait 2-4x longer than smaller batches, while total time
was unchanged and smaller batches cost only a few percent more prompt
tokens. 4 x 4 roughly halves the wait for the first translation and keeps
half of batching's request savings for rate-limited free tiers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(sync): allow the custom_translator and translation_prompt replica kinds in the database

The replica API accepted the two new kinds, but the replicas_kind_allowlist
CHECK did not, so every pushed row would have failed to insert. Migration
025 extends the CHECK (NOT VALID, then VALIDATE, as in 023), and a test now
fails when KIND_ALLOWLIST holds a kind the latest migration does not.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 13:58:02 +02:00
..
volumes feat(translation): custom translation providers with a prompt library (#6582) 2026-10-03 13:58:02 +02:00
.env.example feat(payments): separate storage and customization entitlements, unlock all when self-hosted (#5996) 2026-09-01 07:37:42 +02:00
compose.build.yaml feat(docker): add GHCR and Docker Hub image publishing (#4250) 2026-05-21 19:57:35 +02:00
compose.dev.yaml fix(docker): fix Docker image latest tag and production runtime errors; add dev compose file, Codespace support, and semver release tagging (#7) (#4277) 2026-05-23 10:39:15 +08:00
compose.yaml docker: pull minio images from quay.io, Docker Hub removed them (#6196) 2026-09-16 17:27:50 +02:00
nginx.conf.example fix(docker): apply db migrations on first boot and let the font CDN be overridden (#5550) (#5551) 2026-08-07 10:19:44 +02:00
README.md docker: pull minio images from quay.io, Docker Hub removed them (#6196) 2026-09-16 17:27:50 +02:00

Self-Hosting with Docker/Podman with Compose

Stack

service Image Description
client ghcr.io/readest/readest readest frontend
db supabase/postgres psql db with supabase extensions
kong kong:2.8.1 api gateway routing requests to supabase services
auth supabase/gotrue:v2.185.0 auth service (email, JWT)
rest postgrest/postgrest:v14.3 psql rest api
minio quay.io/minio/minio s3 storage
minio-setup quay.io/minio/mc helper container to create s3 buckets

Exposed ports

Port Service
3000 readest
8000 kong API gateway
9000 MinIO S3 API
9001 MinIO console UI

Running with Docker/Podman Compose

1. setup .env

cp docker/.env.example docker/.env

update docker/.env:

  • update POSTGRES_PASSWORD to a strong password (32+ chars)
  • update JWT_SECRET to a random secret (32+ chars)
  • regenerate ANON_KEY and SERVICE_ROLE_KEY as HS256 JWTs signed with your JWT_SECRET (use jwt.io or a similar tool):
    • ANON_KEY payload: {"role": "anon"}
    • SERVICE_ROLE_KEY payload: {"role": "service_role"}
  • set MINIO_ROOT_PASSWORD to a strong password

2. Start the Stack (pull prebuilt client image)

run from the docker/ directory:

cd docker
docker compose up -d

this pulls ${READEST_IMAGE} (default: ghcr.io/readest/readest:latest) instead of building the client locally. the web client now reads SUPABASE_PUBLIC_URL, SUPABASE_ANON_KEY, API_BASE_URL, OBJECT_STORAGE_TYPE, SELF_HOSTED, STORAGE_FIXED_QUOTA, and TRANSLATION_FIXED_QUOTA from runtime container env, so custom self-hosted values work with pulled images.

SELF_HOSTED unlocks every premium feature — third-party cloud sync (WebDAV, Google Drive, S3, OneDrive), offline Read Aloud downloads, Send to Readest — with or without a signed-in user. the image defaults it to true, so a pulled image is unlocked even if your compose.yaml predates the variable. set SELF_HOSTED=false in docker/.env only if you run a hosted service that sells the plans.

if you prefer Docker Hub, set READEST_IMAGE in docker/.env, for example:

READEST_IMAGE=docker.io/your-dockerhub-username/readest:latest

replace your-dockerhub-username with the Docker Hub namespace that publishes your readest image. for official images, use the namespace configured for this repository's Docker Hub publishing secrets.

published tags:

  • latest: rolling image from the default branch and from release events
  • <release-tag> (for example v1.2.3): published from release events
  • main: rolling image from the default branch
  • sha-<commit>: immutable commit tag

Build locally instead of pulling

Prerequisites for local builds: the packages/foliate-js and packages/simplecc-wasm git submodules must be initialized before building:

git submodule update --init packages/foliate-js packages/simplecc-wasm

In GitHub Codespaces this is done automatically via .devcontainer/devcontainer.json.

cd docker
docker compose -f compose.yaml -f compose.build.yaml up --build -d

3. Access

  • Readest app: http://localhost:3000
  • MinIO console: http://localhost:9001 (login with MINIO_ROOT_USER / MINIO_ROOT_PASSWORD)

Upgrading an existing deployment

pulling a newer client image does not touch the database volume, and the first-boot hook only runs when that volume is empty. so after an upgrade, apply any new migrations yourself:

cd docker
docker compose pull
docker compose up -d
docker compose exec db /docker-entrypoint-initdb.d/zz-readest-migrations.sh

the script records what it applied in readest_meta.migrations and skips those next time, so it is safe to repeat after every upgrade.

if you had previously patched your database by hand, the script may stop on an already exists error. record that file as applied and run it again:

docker compose exec db psql -U supabase_admin -c \
  "INSERT INTO readest_meta.migrations (name) VALUES ('002_add_book_shares.sql') ON CONFLICT DO NOTHING"

Hot Reload (development)

Prerequisites: submodules must be initialized (see above).

to develop using the compose stack, use compose.dev.yaml which sets the build target to development-stage (Next.js dev server) and mounts your local repo for hot reload:

cd docker
docker compose -f compose.yaml -f compose.dev.yaml up --build -d

the first mount overlays your local repo into the container. the remaining anonymous volumes shadow the directories that were pre-built inside the image, so the container's installed deps and vendor assets are used instead of what's on your host.

Stop the Stack

cd docker
docker compose down

to also remove volumes (database and storage data):

cd docker
docker compose down -v

Database schema

path role
volumes/db/init/schema.sql base schema (books, book_configs, book_notes, files)
volumes/db/migrations/*.sql every schema change since, applied in filename order
volumes/db/apply-migrations.sh applies the migrations and records them in readest_meta.migrations

on an empty database volume the supabase image runs everything under /docker-entrypoint-initdb.d in glob order: its own migrate.sh (supabase core schema plus init-scripts/100-schema.sql, which is schema.sql), then zz-readest-migrations.sh, which is apply-migrations.sh. it globs the mounted migrations directory, so adding a migration file needs no compose change.


Serving from a custom domain

the browser talks to three of these services directly, so each needs a URL that resolves from outside the docker network:

variable what the browser uses it for
SITE_URL the readest client itself
SUPABASE_PUBLIC_URL kong, which routes /auth/v1/… and /rest/v1/…
S3_PUBLIC_ENDPOINT minio, reached through path-style presigned URLs

SUPABASE_PUBLIC_URL and S3_PUBLIC_ENDPOINT default to http://${HOST_IP}:<port>, which suits a plain IP/port deployment; set them in docker/.env to override that. putting everything on one origin also means no cross-origin requests at all:

HOST_IP=your-domain.com
SITE_URL=https://your-domain.com
API_EXTERNAL_URL=https://your-domain.com
ADDITIONAL_REDIRECT_URLS=https://your-domain.com/**
SUPABASE_PUBLIC_URL=https://your-domain.com
S3_PUBLIC_ENDPOINT=https://your-domain.com

nginx.conf.example is a working starting point for terminating TLS in front of the stack. two things it gets right that are easy to miss: the Host header has to reach minio unchanged or the presigned signatures will not verify, and the request body limit has to be lifted on the bucket location or large book uploads are truncated.

CJK fonts on a custom domain

the reader loads a few CJK webfont bundles from Readest's CDN, which only sends Access-Control-Allow-Origin for readest.com origins, so the browser blocks them on a self-hosted domain. mirror https://storage.readest.com/public/font/dist/<Family>/ (and the .woff2 files it references) onto a path your proxy serves, then point the client at it:

FONT_BASE_URL=https://your-domain.com/fonts

leaving FONT_BASE_URL empty keeps the default CDN. system and Google fonts are unaffected either way.


Building the Dockerfile standalone

docker build \
  --target production-stage \
  --build-arg NEXT_PUBLIC_APP_PLATFORM=web \
  -t readest-client \
  .

run the built image:

docker run -p 3000:3000 \
  -e SUPABASE_URL=http://host.docker.internal:8000 \
  -e SUPABASE_PUBLIC_URL=http://localhost:8000 \
  -e SUPABASE_ANON_KEY=<anon-key> \
  -e SUPABASE_ADMIN_KEY=<service-role-key> \
  -e API_BASE_URL=http://localhost:3000 \
  -e OBJECT_STORAGE_TYPE=s3 \
  -e S3_ENDPOINT=http://host.docker.internal:9000 \
  -e S3_PUBLIC_ENDPOINT=http://localhost:9000 \
  -e S3_REGION=us-east-1 \
  -e S3_BUCKET_NAME=readest-files \
  -e S3_ACCESS_KEY_ID=<minio-user> \
  -e S3_SECRET_ACCESS_KEY=<minio-password> \
  -e STORAGE_FIXED_QUOTA=1073741824 \
  -e TRANSLATION_FIXED_QUOTA=50000 \
  readest-client

on Linux, some Docker setups do not resolve host.docker.internal by default. in that case, either replace it with your host IP or run with: --add-host=host.docker.internal:host-gateway.