readest/docker
Huang Xin 94653dc741
feat(sync): limit the Free plan to 3 devices, with a list to sign them out (#7945)
* feat(sync): limit the Free plan to 3 devices, with a list to sign them out

A Free account (no subscription or purchase, and not self-hosted) that is
already signed in on three other devices can't finish signing in on a
fourth. The login page lists those devices instead, each with Sign Out.
Signing one out finishes the sign-in; Cancel or Go Back ends the new
session. Every plan can see its devices and sign them out under Devices in
the profile's Manage Sync view.

Devices come from the account's Supabase sessions, grouped by the kind of
device their user agent names (Chrome on macOS, Readest on Pixel 7,
KOReader on Kindle Paperwhite 5), so a device holding several sessions
counts once. Only devices signed in before this session count, so the
first three are never sent away by later ones. An error skips the check
rather than block a sign-in.

- Migration 035 adds list_user_sessions and delete_user_sessions, callable
  by the service role only. Apply it to production before this merges;
  until then the check is skipped and the list stays hidden.
- GET /api/auth/sessions lists the devices with the plan's limit and
  whether this one is over it; DELETE signs another device out.
- The auth-proxy Worker forwards User-Agent, so password sign-ins and
  refreshes record the device instead of the Worker. It needs a redeploy.
- handleAuthCallback also checks the session supabase-js took from the
  URL. On web it clears the hash before the callback page runs, so web
  OAuth and magic links went straight to the library.

Verified:
- Each new test failed before the change and passes with it:
  auth-page-device-limit.test.tsx ("Unable to find an element with the
  text: Chrome on macOS"), helpers/auth.test.ts URL-session case (expected
  navigate to be called with '/auth'), auth-proxy.test.ts (expected null
  to be 'KOReader/v2025.08'), device-limit-access.test.ts (getDeviceLimit
  is not a function), syncDevices.test.ts and auth-sessions-route.test.ts
  (modules missing).
- Related suites: 115 files, 1513 tests passed. pnpm lint clean.
- dev-web against a local self-hosted Supabase (GoTrue v2.185) with
  migration 035, 13/13 end-to-end checks: a fourth device is held;
  signing out KOReader finishes the sign-in and deletes its session;
  Manage Sync names this device and signs another out; Cancel ends the
  new session; a magic link is held on /auth. Screens checked in light,
  dark, e-ink and at 360px wide.
- anon and authenticated get "permission denied" on both functions;
  GoTrue rewrites a session's user_agent on every refresh.

Not run: the Tauri desktop and mobile apps, RTL, the full pnpm test.

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

* fix(sync): keep a held sign-in out of the app until a device signs out

Answers the CodeRabbit review of #7945.

- AuthProvider published every session the SDK reported, so a sign-in held
  at the device limit was signed in for the rest of the app, and again
  after a restart. A new Free plan sign-in (no stored user, or another
  account) now waits for the device check and is published only when let
  in; a device already signed in is published as before, unchecked.
- A device sign-out that answers after Cancel or Go Back no longer signs in
  the session they ended.
- DELETE /api/auth/sessions answers from the one read it makes, so a
  second read that fails after the sign-out can't report it as failed.
- A held callback goes to /auth?redirect=<destination>, so a held password
  recovery still reaches /auth/recovery.
- A device that signs in again keeps its place from its first sign-in, so
  the held fourth device can't push one of the first three out.
- Tibetan: "{{limit}} and above" is now "at most {{limit}}".
- Migration 035 turns off check_function_bodies: on a fresh self-hosted
  database it runs before GoTrue has created auth.sessions, and failed.

Verified:
- New tests failed before the fix and pass with it:
  auth-context-device-limit.test.tsx (expected the check to be called with
  'held-token'), auth-page-device-limit.test.tsx after-Cancel case
  (expected login not to be called, called once), auth-sessions-route
  (expected 500 to be 200), helpers/auth.test.ts recovery case (expected
  navigate with '/auth?redirect=%2Fauth%2Frecovery'), syncDevices.test.ts
  sign-in-again case on the old cutoff (expected true to be false).
- auth-context-logout.test.tsx mocks the device check: its token has no
  plan claim, so it read as a Free sign-in and fetched the live API.
- Related suites: 187 files, 2278 tests passed. pnpm lint clean.
- 035 applied on a database before GoTrue started (it failed there before),
  then list_user_sessions answered once GoTrue had migrated; anon is still
  refused.
- dev-web against a local self-hosted Supabase, 15/15 end-to-end checks,
  now including that no token or user is stored while held. Reloading the
  app during a hold leaves it signed out, and opening sign-in again shows
  the device list.

Not run: the Tauri desktop and mobile apps.

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

* fix(sync): drop a device check that answers after Go Back or Sign Out

Answers CodeRabbit's second review of #7945.

- Go Back now abandons a Free plan sign-in whose device check is still
  running, as it already did for one that is held: it signs the session
  out, and the check's answer neither signs in nor shows the device list.
  A check answering after the page unmounts is dropped too.
- AuthProvider doesn't publish a session whose device check answers while
  Sign Out is running.

Verified:
- New tests failed before the fix and pass with it:
  auth-page-device-limit.test.tsx ("abandons a sign-in whose device check
  is still running on Go Back": expected signOut with { scope: 'local' },
  not called) and auth-context-device-limit.test.tsx ("does not sign in
  when the device check answers during Sign Out": expected 'new-token' to
  be null).
- Related suites: 187 files, 2280 tests passed. pnpm lint clean.
- dev-web against a local self-hosted Supabase: 15/15 end-to-end checks
  and both reload-during-hold checks pass again.

Not run: the Tauri desktop and mobile apps.

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

* fix(sync): keep the refresh token of a sign-in let in after a hold

Answers CodeRabbit's third review of #7945.

AuthProvider never publishes a sign-in held at the device limit, and
login() stores only the token and user. Once a device was signed out and
the held sign-in finished, nothing stored refresh_token until the next
token refresh, so an offline launch before then found none and signed
the user out. The login page now stores it when it finishes a sign-in.

Verified:
- auth-page-device-limit.test.tsx ("finishes signing in once a device is
  signed out") now checks refresh_token: it failed before with "expected
  null to be 'free-refresh'" and passes with the fix.
- Auth page, AuthContext and auth helper suites: 14 files, 81 tests
  passed. pnpm lint clean.
- dev-web against a local self-hosted Supabase, 16/16 end-to-end checks,
  now including that token and refresh_token are stored once the held
  sign-in is let in.

Not run: the Tauri desktop and mobile apps.

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

* fix(sync): open the recovery form after a held reset link in the app

Answers CodeRabbit's follow-ups on #7945.

In the desktop and mobile apps a sign-in link arrives as a deep link,
handled on the login page, whose onDeviceLimit did nothing. Once a device
was signed out, the held sign-in went to the page's redirect or /library,
so a password reset link never reached /auth/recovery. The page now keeps
the destination the callback would have opened under the limit, goes
there when the sign-in is let in, and forgets it on Cancel or Go Back.

Adds a test for the other follow-up, a device check started by a token
refresh while the list is open that answers after Cancel. The guard from
2f02f8275 already drops it.

Verified:
- auth-page-device-limit.test.tsx:
  - "opens the recovery form once a held password reset link is let in"
    delivers the link through onOpenUrl. Before the fix it failed with
    replace called with '/library', not '/auth/recovery'.
  - "forgets a cancelled reset link when signing in again" fails with
    "expected ... '/library'" when Cancel doesn't clear the destination.
  - "drops a device check that answers after Cancel" fails with login
    called once when the 2f02f8275 guard is taken out.
- Related suites: 187 files, 2283 tests passed. pnpm lint clean.
- dev-web against a local self-hosted Supabase: 16/16 end-to-end checks
  and both reload-during-hold checks pass, so the web path is unchanged.

Not run: the deep link itself in the Tauri desktop and mobile apps.

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

* fix(sync): ignore a reset link's device check that answers after Cancel

Answers CodeRabbit's fourth review of #7945.

A deep link's own device check runs after the page's, so it can answer
after Cancel or Go Back. It then still stored the link's destination, and
the next sign-in on the same page followed it, to the recovery form for a
password reset link. The callback now drops the destination when the
sign-in was abandoned since the link arrived.

Verified:
- auth-page-device-limit.test.tsx ("forgets a reset link whose device
  check answers after Cancel") holds the link's check until after Cancel.
  Before the fix it failed with replace not called with '/library'.
- Auth page, AuthContext and auth helper suites: 14 files, 85 tests
  passed. pnpm lint clean.

Not run: the deep link in the Tauri desktop and mobile apps, and dev-web,
which never runs this callback.

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

* fix(sync): tie a held sign-in's checks and destination to its session

Answers CodeRabbit's follow-ups on #7945.

- A deep link's destination is kept when the link arrives, not when its
  own device check answers. The device list can show first, and a device
  signed out before that check answered sent a reset link to /library.
  The callback no longer writes it, so a late answer after Cancel can't
  either. The destination is used only when a held sign-in is let in, so
  a sign-in under the limit goes where it did before.
- Every auth event on the login page moves the sign-in on. A device check
  or sign-out started for an older session is dropped when it answers.
  When the session ends, the page goes back to the sign-in form.

Verified:
- New tests in auth-page-device-limit.test.tsx failed before the fix:
  - "opens the recovery form when a device is signed out before the link
    check answers": replace not called with '/auth/recovery'.
  - "drops a device check when the session ends while it runs": login
    called once.
  - "signs in only the newer session when one replaces it during the
    check": login called for the replaced session.
- Auth page, AuthContext and auth helper suites pass. pnpm lint clean.
- dev-web against a local self-hosted Supabase: 16/16 end-to-end checks.

Not run: the deep link in the Tauri desktop and mobile apps.

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

* fix(sync): let a new sign-in into the app only on the server's answer

Found re-running the end-to-end checks for #7945. Reloading the app while
a sign-in was held let it in. The reload aborted AuthProvider's device
check, which was still running. The check fails open, so AuthProvider
published the session just before the page unloaded. After the reload
the stored user matched, so the device was never checked again. It
reproduced 3 of 3 runs, and 1 of 3 on the previous head.

AuthProvider now publishes a new Free plan sign-in only when the server
answers that it is let in. The sign-in screens still sign in on their own
answer, which fails open. The web callback's branch for tokens that
supabase-js took from the URL relied on AuthProvider to publish, so it
now signs in itself.

Verified:
- auth-context-device-limit.test.tsx ("does not sign in when the device
  check fails") failed before with "expected 'new-token' to be null".
  helpers/auth.test.ts ("signs in a session supabase-js already took
  from the URL") failed with login not called.
- Related suites: 187 files, 2289 tests passed. pnpm lint clean.
- dev-web against a local self-hosted Supabase:
  - 16/16 end-to-end checks.
  - The reload-during-hold check passes 3 of 3, including a run where the
    browser aborted the check.
  - A magic link under the limit lands signed in on /library, also with
    /api/auth/sessions answering 500. Without the callback's login() the
    500 case landed signed out.

Not run: the Tauri desktop and mobile apps.

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

* fix(sync): finish a held sign-in with its newest session, drop links after Cancel

Answers CodeRabbit's follow-ups on #7945.

- A token refresh while the device list shows left the old session on
  screen, and a device sign-out then signed in that session and its spent
  refresh token. The page now keeps the newest session it heard of. A
  device check answers only for that session, and a held sign-in finishes
  with it.
- In the desktop and mobile apps, a link's own device check fails open.
  When it failed after Cancel, the callback still signed in and navigated.
  Its login and navigate now do nothing once the sign-in was abandoned.
  This needs a counter that only abandoning moves, since the callback's
  own setSession fires an auth event. The newest session handles
  replacement.

Verified:
- New tests in auth-page-device-limit.test.tsx failed before the fix:
  - "finishes with the refreshed session when a device is signed out
    meanwhile": login called with 'free-token', not 'refreshed-token'.
  - "does not sign in a link whose own check lets it in after Cancel":
    login called once. It fails again with the callback guard taken out.
  - "opens the recovery form for a reset link under the limit, as
    before" passes with and without the guard.
- Related suites: 187 files, 2292 tests passed. pnpm lint clean.
- dev-web against a local self-hosted Supabase:
  - 16/16 end-to-end checks.
  - Reload during a hold: 3 of 3 stay signed out, two with the check
    aborted.
  - Magic link under the limit signs in, also with /api/auth/sessions
    answering 500.

Not run: the deep link in the Tauri desktop and mobile apps.

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

* fix(sync): apply a device sign-out's answer only to the account that asked

Answers CodeRabbit's follow-up on #7945.

A held sign-in finishes with the newest session the page heard of, so a
token refresh carries over. If another account signed in while a device
sign-out was pending (from another tab, say), the answer for the first
account signed in the second before its own device check had answered.
The answer now applies only when the newest session is the same user.

Verified:
- auth-page-device-limit.test.tsx ("does not sign in another account on
  a sign-out answered for the first") failed before with login called
  once. The refresh case ("finishes with the refreshed session...") still
  passes.
- Auth page, AuthContext and auth helper suites: 14 files, 94 tests
  passed. pnpm lint clean.
- dev-web against a local self-hosted Supabase: 16/16 end-to-end checks,
  including a held sign-in finishing through a device sign-out. The
  reload-during-hold check passes too.

Not run: the Tauri desktop and mobile apps.

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

* fix(sync): keep the refresh token when the auth callback signs in itself

Answers CodeRabbit's review of a6a5d6cfa on #7945.

AuthProvider stores nothing for a new sign-in whose device check failed
(a6a5d6cfa), and login() stores only the token and user. When both device
checks failed and the callback signed in itself, refresh_token was never
stored. An offline launch whose INITIAL_SESSION is null then found no
refresh token and signed the user out. Both of the callback's sign-in
branches (tokens in the link, or taken from the URL by supabase-js) now
store it, as the login page does.

Verified:
- helpers/auth.test.ts: "should login and navigate to next URL on
  successful auth" and "signs in a session supabase-js already took from
  the URL" now check refresh_token. Before the fix they failed with
  "expected null to be 'good-refresh'" and "... 'url-refresh'".
- Related suites: 187 files, 2293 tests passed. pnpm lint clean.
- dev-web against a local self-hosted Supabase:
  - A magic link under the limit stores token, user and refresh_token,
    also with /api/auth/sessions answering 500.
  - 16/16 end-to-end checks.
  - The reload-during-hold check passes, with the check aborted.

Not run: the Tauri desktop and mobile apps.

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

* fix(sync): keep the SDK's refresh token, not the link's, after a callback

ba3a6cf8e stored the refresh token from the sign-in link when the auth
callback signed in itself. If the link's access token had expired,
setSession refreshed it, and that spent the link's refresh token. The
stored one could then never restore the sign-in. The callback now stores
the refresh token of the SDK's session, which still works.

CodeQL flagged ba3a6cf8e (js/clear-text-storage-of-sensitive-data,
alert 161) for storing a value parsed from the callback URL. The app
already keeps its refresh token in localStorage, as AuthProvider does on
main, and that key now comes from the SDK's session as everywhere else.

Verified:
- helpers/auth.test.ts ("should login and navigate to next URL on
  successful auth") now has getSession return a rotated refresh token.
  Before the fix it failed with "expected 'good-refresh' to be
  'rotated-refresh'".
- Related suites: 187 files, 2293 tests passed. pnpm lint clean.
- dev-web against a local self-hosted Supabase: a magic link under the
  limit stores token, user and refresh_token, also with
  /api/auth/sessions answering 500. 16/16 end-to-end checks.

Not run: the Tauri desktop and mobile apps.

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

* fix(sync): keep a callback's refresh token only for the account it signed in

Answers CodeRabbit's review of 499b39262 on #7945.

The auth callback reads the SDK's session after its device check, to keep
a refresh token that setSession may have rotated. A second deep link can
replace that session during the check. The first callback then stored
the other account's refresh token next to its own token and user. It now
keeps the token only when the SDK's session is the same user. It compares
user ids, since a rotated session has a new access token.

Verified:
- helpers/auth.test.ts ("doesn't keep the refresh token of another
  account's session") failed before with "expected 'other-refresh' to be
  null". The rotated-token case still passes.
- Related suites: 187 files, 2294 tests passed. pnpm lint clean.

Not run: this branch in a browser. dev-web never takes it, since
supabase-js takes the tokens from the URL first. Not run in the Tauri
apps either.

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

* feat(plans): list the number of devices on each plan (owner: Free plan Number of devices: 3; other plan limitations Number of devices: Unlimited)

The plan cards' What's Included box gets a Number of Devices row: 3 on
Free, Unlimited on Plus and Pro. Lifetime has no limits box, so no row.
The Free value comes from FREE_PLAN_DEVICE_LIMIT, which moves to
services/constants so the card and the server check read one number.

PlanCard now passes string values through _(): plan.ts builds its
limits with stubTranslation, so "Unlimited" stayed English. The
existing values ('500 MB', '10K') have no translation and pass through
unchanged.

Verified:
- plan.test.ts "lists the number of devices for the <plan> plan"
  fails without plan.ts (expected undefined to be 3 / 'Unlimited').
- PlanCardLimits.test.tsx fails without the PlanCard change: expected
  'Anzahl der GeräteUnlimited' to be 'Anzahl der GeräteUnbegrenzt'.
- dev-web: the row on each card in light, dark, e-ink, German and at
  390px; German reads "Anzahl der Geräte 3 / Unbegrenzt".
- Translations for both keys in all 34 locales.

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

* fix(sync): line the Devices list up with Manage Sync's categories (owner: Manage sync page the indent is wrong)

The Devices list used the settings BoxedList: a white card with an
invisible border and dividers inset by the row padding, under a
bordered list whose dividers run edge to edge. It now uses the same
list as the categories above it (border-base-300, rounded-lg, px-4
py-3 rows, text-sm title, text-xs line). The auth page's Device limit
reached panel shares the component and looks the same.

Both lists get eink-bordered, so e-ink shows the same border on each;
the categories list had none before.

Verified on dev-web: both lists span the same edges with 16px row
padding at 1024px (112-912) and 390px (24-366), in light, dark and
e-ink; the 16 device-limit end-to-end checks pass. No unit test: the
change is styling only.

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

---------

Co-authored-by: Claude Code (Claude Opus 5.5) <noreply@anthropic.com>
2026-11-26 05:26:52 +01:00
..
volumes feat(sync): limit the Free plan to 3 devices, with a list to sign them out (#7945) 2026-11-26 05:26:52 +01:00
.env.example fix(opds): allow trusted private catalogs at runtime (#7225) 2026-11-01 17:26:53 +01: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 fix(opds): allow trusted private catalogs at runtime (#7225) 2026-11-01 17:26:53 +01: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 fix(opds): allow trusted private catalogs at runtime (#7225) 2026-11-01 17:26:53 +01: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

OPDS catalogs on a private network

The web OPDS proxy blocks private, loopback and link-local addresses by default, including public hostnames that resolve to them. To reach trusted LAN catalogs, set an exact, comma-separated allowlist in docker/.env:

READEST_TRUSTED_PRIVATE_HOSTS=books.home.arpa,calibre.lan,192.168.1.20

Recreate the client with docker compose up -d client after changing it. With docker run, pass -e READEST_TRUSTED_PRIVATE_HOSTS=books.home.arpa instead. This setting is read by the server at request time and works with prebuilt images; no rebuild or NODE_ENV change is needed.

Entries are hostnames or IP addresses only, without schemes, ports, paths, wildcards or CIDR ranges. Matching ignores case and trailing DNS dots. An entry allows any port on that host, so only list hosts whose services you trust. For IPv6 literals, include brackets, for example [fd00::20].

Each redirect destination must pass the same checks. List any additional private hosts used for feeds, covers or downloads. Unlisted hosts keep the private-address and DNS checks, and credentials are still removed on cross-origin redirects. The allowlist applies only to OPDS, not KOSync or Send to Readest.

Anyone who can reach your Readest instance can use its OPDS proxy to reach the listed hosts. Keep the instance behind your LAN/VPN or access controls when allowing private services. SELF_HOSTED=true lets the catalog form submit LAN URLs, but does not grant server access by itself.

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.