39 lines
1.3 KiB
Docker
39 lines
1.3 KiB
Docker
FROM node:20-slim AS base
|
|
RUN corepack enable && corepack prepare pnpm@latest --activate
|
|
WORKDIR /app
|
|
|
|
FROM base AS deps
|
|
COPY package.json ./
|
|
COPY . .
|
|
# better-sqlite3 requires native compilation tools
|
|
RUN apt-get update && apt-get install -y python3 make g++ --no-install-recommends && rm -rf /var/lib/apt/lists/*
|
|
RUN if [ -f pnpm-lock.yaml ]; then \
|
|
pnpm install --frozen-lockfile; \
|
|
else \
|
|
echo "WARN: pnpm-lock.yaml not found in build context; running non-frozen install"; \
|
|
pnpm install --no-frozen-lockfile; \
|
|
fi
|
|
|
|
FROM base AS build
|
|
COPY --from=deps /app ./
|
|
RUN pnpm build
|
|
|
|
FROM node:20-slim AS runtime
|
|
WORKDIR /app
|
|
ENV NODE_ENV=production
|
|
RUN addgroup --system --gid 1001 nodejs && adduser --system --uid 1001 nextjs
|
|
COPY --from=build /app/.next/standalone ./
|
|
COPY --from=build /app/.next/static ./.next/static
|
|
# Copy public directory if it exists (may not exist in all setups)
|
|
COPY --from=build /app/public* ./public/
|
|
# Create data directory with correct ownership for SQLite
|
|
RUN mkdir -p .data && chown nextjs:nodejs .data
|
|
RUN apt-get update && apt-get install -y curl --no-install-recommends && rm -rf /var/lib/apt/lists/*
|
|
USER nextjs
|
|
EXPOSE 3000
|
|
ENV PORT=3000
|
|
ENV HOSTNAME=0.0.0.0
|
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
|
CMD curl -f http://localhost:3000/login || exit 1
|
|
CMD ["node", "server.js"]
|