mirror of
https://github.com/margrop/wrong-notebook.git
synced 2026-12-02 19:09:32 +08:00
95 lines
3.3 KiB
Docker
95 lines
3.3 KiB
Docker
FROM node:22-alpine AS base
|
|
|
|
# Install dependencies only when needed
|
|
FROM base AS deps
|
|
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
|
|
RUN apk add --no-cache libc6-compat
|
|
WORKDIR /app
|
|
|
|
# Install dependencies based on the preferred package manager
|
|
COPY package.json package-lock.json ./
|
|
RUN npm ci
|
|
|
|
# Rebuild the source code only when needed
|
|
FROM base AS builder
|
|
WORKDIR /app
|
|
COPY --from=deps /app/node_modules ./node_modules
|
|
COPY . .
|
|
|
|
# Install OpenSSL for Prisma
|
|
RUN apk add --no-cache openssl
|
|
|
|
# Generate Prisma Client and Seed Database
|
|
# We temporarily set DATABASE_URL to a local file for the build process to generate the file
|
|
ENV DATABASE_URL="file:/app/prisma/dev.db"
|
|
|
|
# Pre-compile runtime scripts FIRST (needed for tag seeding)
|
|
RUN npx tsc scripts/rebuild-system-tags.ts --outDir dist-scripts --esModuleInterop --resolveJsonModule --skipLibCheck --module commonjs --target ES2020
|
|
|
|
# Initialize database: generate client, run migrations, seed admin user, seed system tags
|
|
RUN npx prisma generate \
|
|
&& npx prisma migrate deploy \
|
|
&& npx prisma db seed \
|
|
&& node ./dist-scripts/scripts/rebuild-system-tags.js
|
|
|
|
# Next.js collects completely anonymous telemetry data about general usage.
|
|
# Learn more here: https://nextjs.org/telemetry
|
|
# Uncomment the following line in case you want to disable telemetry during the build.
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
|
|
RUN npm run build
|
|
|
|
# Production image, copy all the files and run next
|
|
FROM base AS runner
|
|
WORKDIR /app
|
|
|
|
ENV NODE_ENV=production
|
|
# Uncomment the following line in case you want to disable telemetry during runtime.
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
|
|
# Install dependencies and create user
|
|
RUN apk add --no-cache su-exec openssl \
|
|
&& addgroup --system --gid 1001 nodejs \
|
|
&& adduser --system --uid 1001 nextjs
|
|
|
|
# Copy Prisma CLI and engine files from builder
|
|
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/.prisma ./node_modules/.prisma
|
|
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/prisma ./node_modules/prisma
|
|
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/@prisma ./node_modules/@prisma
|
|
|
|
COPY --from=builder /app/public ./public
|
|
|
|
# Automatically leverage output traces to reduce image size
|
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
|
|
|
# Copy Prisma schema and migrations for runtime usage if needed (e.g. for migrations)
|
|
COPY --from=builder --chown=nextjs:nodejs /app/prisma ./prisma
|
|
|
|
# Copy config directory for runtime
|
|
COPY --from=builder --chown=nextjs:nodejs /app/config ./config
|
|
|
|
# Copy pre-compiled runtime scripts
|
|
COPY --from=builder --chown=nextjs:nodejs /app/dist-scripts ./dist-scripts
|
|
|
|
# Create data directory for SQLite persistence
|
|
RUN mkdir -p /app/data && chown -R nextjs:nodejs /app/data
|
|
|
|
# Copy entrypoint script
|
|
COPY --chown=nextjs:nodejs --chmod=755 docker-entrypoint.sh ./
|
|
|
|
EXPOSE 3000
|
|
|
|
ENV PORT=3000
|
|
# set hostname to localhost
|
|
ENV HOSTNAME="0.0.0.0"
|
|
|
|
# Environment variables
|
|
# Point to the persistent data location
|
|
ENV DATABASE_URL="file:/app/data/dev.db"
|
|
ENV AUTH_TRUST_HOST=true
|
|
|
|
# Use entrypoint script to handle DB initialization
|
|
ENTRYPOINT ["./docker-entrypoint.sh"]
|
|
CMD ["node", "server.js"]
|