FROM node:22-bookworm-slim AS deps WORKDIR /app RUN corepack enable COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./ RUN pnpm install --frozen-lockfile --config.node-linker=hoisted FROM node:22-bookworm-slim AS builder WORKDIR /app ENV NEXT_TELEMETRY_DISABLED=1 RUN corepack enable COPY --from=deps /app/node_modules ./node_modules COPY . . RUN pnpm --config.node-linker=hoisted build FROM node:22-bookworm-slim AS runner WORKDIR /app ENV NODE_ENV=production ENV NEXT_TELEMETRY_DISABLED=1 ENV HOSTNAME=0.0.0.0 ENV PORT=3000 ENV DATA_DIR=/app/data RUN groupadd --system --gid 1001 nodejs \ && useradd --system --uid 1001 --gid nodejs nextjs \ && mkdir -p /app/data \ && chown -R nextjs:nodejs /app/data COPY --from=builder /app/public ./public COPY --from=builder /app/.next/standalone ./ COPY --from=builder /app/scripts ./scripts COPY --from=builder /app/server/db/migrations ./server/db/migrations COPY --from=builder /app/node_modules/drizzle-orm ./node_modules/drizzle-orm COPY --from=builder /app/node_modules/better-sqlite3 ./node_modules/better-sqlite3 COPY --from=builder /app/node_modules/bindings ./node_modules/bindings COPY --from=builder /app/node_modules/file-uri-to-path ./node_modules/file-uri-to-path USER nextjs EXPOSE 3000 VOLUME ["/app/data"] CMD ["sh", "-c", "node scripts/migrate.mjs && node server.js"]