mirror of
https://github.com/readest/readest.git
synced 2026-11-29 19:02:28 +00:00
The Docker image shipped without a service worker, so the self-hosted web app couldn't load offline or work as an offline PWA: @serwist/next only emits public/sw.js from a webpack build, and `next build` uses Turbopack by default. Run `pnpm patch-build-webpack` before `pnpm build-web`, as `pnpm deploy` does, with the 8 GB heap the release workflows give the webpack build. #7695 made webpack builds keep the server's runtime config on cached loads, which this image relies on. Verified: - docker-image-build.test.ts fails on main's Dockerfile (expected 'RUN pnpm build-web' to match /^RUN pnpm patch-build-webpack && /) and passes here. - docker build with #7695: /sw.js served with /offline precached; cached loads use the configured Supabase and API hosts; with the container stopped, the library, an opened book and the offline page load in a tab and in the installed app. - CI green. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
83 lines
4.3 KiB
Docker
83 lines
4.3 KiB
Docker
FROM docker.io/library/node:24-slim@sha256:55fb5f5a527ea2c5c4a95f963e48ef90aa38c7b346054fdc8ee9957a2b55d205 AS dependencies
|
|
ENV PNPM_HOME="/pnpm"
|
|
ENV PATH="$PNPM_HOME:$PATH"
|
|
RUN corepack enable
|
|
RUN corepack prepare pnpm@11.1.1 --activate
|
|
WORKDIR /app
|
|
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
|
|
COPY apps/readest-app/package.json ./apps/readest-app/
|
|
COPY patches/ ./patches/
|
|
COPY packages/ ./packages/
|
|
RUN --mount=type=cache,id=pnpm,sharing=locked,target=/pnpm/store pnpm install --frozen-lockfile
|
|
RUN test -f packages/foliate-js/vendor/pdfjs/annotation_layer_builder.css \
|
|
&& test -d packages/simplecc-wasm/dist/web \
|
|
|| { printf '\nERROR: Required git submodules are not initialized in the source directory.\nEnsure submodules are initialized before running docker build.\nRun: git submodule update --init packages/foliate-js packages/simplecc-wasm\n\n'; exit 1; }
|
|
RUN pnpm --filter @readest/readest-app setup-vendors
|
|
|
|
FROM docker.io/library/node:24-slim@sha256:55fb5f5a527ea2c5c4a95f963e48ef90aa38c7b346054fdc8ee9957a2b55d205 AS development-stage
|
|
ENV PNPM_HOME="/pnpm"
|
|
ENV PATH="$PNPM_HOME:$PATH"
|
|
RUN corepack enable
|
|
RUN corepack prepare pnpm@11.1.1 --activate
|
|
WORKDIR /app
|
|
COPY --from=dependencies /app /app
|
|
COPY . .
|
|
WORKDIR /app/apps/readest-app
|
|
EXPOSE 3000
|
|
ENTRYPOINT ["pnpm", "dev-web", "-H", "0.0.0.0"]
|
|
|
|
FROM docker.io/library/node:24-slim@sha256:55fb5f5a527ea2c5c4a95f963e48ef90aa38c7b346054fdc8ee9957a2b55d205 AS build
|
|
ENV PNPM_HOME="/pnpm"
|
|
ENV PATH="$PNPM_HOME:$PATH"
|
|
RUN corepack enable
|
|
RUN corepack prepare pnpm@11.1.1 --activate
|
|
WORKDIR /app
|
|
ARG NEXT_PUBLIC_SUPABASE_URL
|
|
ARG NEXT_PUBLIC_SUPABASE_ANON_KEY
|
|
ARG NEXT_PUBLIC_APP_PLATFORM
|
|
ARG NEXT_PUBLIC_API_BASE_URL
|
|
ARG NEXT_PUBLIC_OBJECT_STORAGE_TYPE
|
|
ARG NEXT_PUBLIC_STORAGE_FIXED_QUOTA
|
|
ARG NEXT_PUBLIC_TRANSLATION_FIXED_QUOTA
|
|
COPY --from=dependencies /app/node_modules /app/node_modules
|
|
COPY --from=dependencies /app/apps/readest-app/node_modules /app/apps/readest-app/node_modules
|
|
COPY --from=dependencies /app/apps/readest-app/public/vendor /app/apps/readest-app/public/vendor
|
|
COPY --from=dependencies /app/packages/foliate-js/node_modules /app/packages/foliate-js/node_modules
|
|
COPY . .
|
|
WORKDIR /app/apps/readest-app
|
|
# Opt into the self-contained `.next/standalone` tree for this image only;
|
|
# next.config.mjs gates `output: 'standalone'` on BUILD_STANDALONE so other
|
|
# web builds keep their default output.
|
|
ENV BUILD_STANDALONE=true
|
|
# @serwist/next only emits the service worker (public/sw.js) from a webpack
|
|
# build, so switch `next build` to webpack as `pnpm deploy` does. The webpack
|
|
# build runs out of memory with Node's default heap; give it the 8 GB the
|
|
# release workflows use.
|
|
RUN pnpm patch-build-webpack && NODE_OPTIONS=--max-old-space-size=8192 pnpm build-web
|
|
|
|
# Production runtime ships only the standalone server, its traced node_modules,
|
|
# and the static/public assets — no pnpm, no source tree, no dev dependencies,
|
|
# no build cache. `output: 'standalone'` (next.config.mjs) emits the self-contained
|
|
# tree under .next/standalone, so the entrypoint is a plain `node server.js`.
|
|
FROM docker.io/library/node:24-slim@sha256:55fb5f5a527ea2c5c4a95f963e48ef90aa38c7b346054fdc8ee9957a2b55d205 AS production-stage
|
|
ENV NODE_ENV=production
|
|
ENV PORT=3000
|
|
ENV HOSTNAME=0.0.0.0
|
|
# This image is the self-hosted artifact — web.readest.com runs on
|
|
# Cloudflare/Vercel, never on it — so premium features are unlocked by default
|
|
# rather than left to the operator's compose file. `compose.yaml` passes
|
|
# `SELF_HOSTED: ${SELF_HOSTED:-true}`, but that line only landed in #5996: a
|
|
# compose file copied before it survives every `docker compose pull`, so the
|
|
# container came up gated with nothing on screen to explain why (#6093).
|
|
# An operator running a hosted service that sells plans sets SELF_HOSTED=false.
|
|
ENV SELF_HOSTED=true
|
|
WORKDIR /app
|
|
# Monorepo-rooted standalone tree: server.js + hoisted, traced node_modules.
|
|
COPY --from=build --chown=node:node /app/apps/readest-app/.next/standalone ./
|
|
# Static and public assets are not part of the standalone trace; copy them next
|
|
# to the server so their default relative paths resolve.
|
|
COPY --from=build --chown=node:node /app/apps/readest-app/.next/static ./apps/readest-app/.next/static
|
|
COPY --from=build --chown=node:node /app/apps/readest-app/public ./apps/readest-app/public
|
|
USER node
|
|
EXPOSE 3000
|
|
ENTRYPOINT ["node", "apps/readest-app/server.js"]
|