Something went wrong. Try again.
A free, open-source, self-hosted place to write a novel.
Something went wrong. Try again.
Fablewright Dockerfile
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172# Fablewright, for `docker compose up` or a plain `docker run`.## The build stage needs the whole toolchain. The runtime stage needs one process,# the built app, and the migrations. No native compilation happens anywhere,# because SQLite comes from Node itself.
FROM node:24-bookworm-slim AS buildWORKDIR /app
# The commit this image was built from. A build context has no `.git` directory,# so the version and commit that the app reports come from here.ARG APP_COMMIT=unknown
# pnpm is the package manager this project pins, so install the version the# lockfile was written with rather than whatever npm ships.RUN corepack enable && corepack prepare pnpm@12.21.0 --activate
# pnpm links the agent skills a dependency ships into `.agents/skills` at# the project root, and the install fails when that directory is missing.# The skills are a tool for the person working on the code, so the image# creates the directory and ships none of them.RUN mkdir -p .agents/skills
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./RUN pnpm install --frozen-lockfile
COPY . .RUN pnpm build# The production dependencies only: the build output is already on disk.RUN pnpm prune --prod
FROM node:24-bookworm-slim AS runtimeWORKDIR /app
# Repeated from the build stage so the entry point can name the build in its log# and in the refusal message, before the app itself has loaded.ARG APP_COMMIT=unknown
ENV NODE_ENV=production \ PORT=3000 \ HOST=0.0.0.0 \ APP_COMMIT=${APP_COMMIT} \ DATABASE_URL=/data/fablewright.db
# A non-root user, because nothing here needs privilege.RUN groupadd --system --gid 1001 fablewright \ && useradd --system --uid 1001 --gid fablewright --home /app fablewright \ && mkdir -p /data && chown fablewright:fablewright /data
COPY --from=build --chown=fablewright:fablewright /app/build ./buildCOPY --from=build --chown=fablewright:fablewright /app/node_modules ./node_modulesCOPY --from=build --chown=fablewright:fablewright /app/drizzle ./drizzleCOPY --from=build --chown=fablewright:fablewright /app/package.json ./package.jsonCOPY --from=build --chown=fablewright:fablewright /app/server.js ./server.jsCOPY --from=build --chown=fablewright:fablewright /app/scripts ./scriptsCOPY --chown=fablewright:fablewright docker-entrypoint.sh ./docker-entrypoint.sh
RUN chmod +x ./docker-entrypoint.sh
# The entry point starts as root, makes the data directory writable, and drops to# fablewright before the app runs. A bind mount arrives owned by the host user, so# the image cannot assume that the directory is already writable.VOLUME ["/data"]EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \ CMD node -e "fetch('http://127.0.0.1:'+(process.env.PORT||3000)+'/api/health').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"
ENTRYPOINT ["./docker-entrypoint.sh"]CMD ["node", "server.js"]