Files
wfh/Dockerfile

68 lines
1.6 KiB
Docker
Raw Normal View History

2026-03-12 17:09:22 -05:00
FROM node:20-alpine AS base
# Install dependencies only when needed
FROM base AS deps
2026-03-12 23:34:19 -05:00
RUN apk add --no-cache libc6-compat openssl
2026-03-12 17:09:22 -05:00
WORKDIR /app
COPY package.json package-lock.json* ./
RUN npm install
2026-03-12 17:09:22 -05:00
# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Generate Prisma Client (with SQLite)
ENV DATABASE_URL="file:/app/data/dev.db"
RUN npx prisma generate
# Disable telemetry during build
2026-03-12 19:15:56 -05:00
ENV NEXT_TELEMETRY_DISABLED=1
2026-03-12 17:09:22 -05:00
RUN npm run build
# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app
2026-03-12 19:15:56 -05:00
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
2026-03-12 17:09:22 -05:00
ENV DATABASE_URL="file:/app/data/dev.db"
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
COPY --from=builder /app/public ./public
# Set the correct permission for prerender cache
RUN mkdir .next
RUN chown nextjs:nodejs .next
# 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 --from=builder --chown=nextjs:nodejs /app/prisma ./prisma
COPY --from=deps --chown=nextjs:nodejs /app/node_modules ./node_modules
2026-03-12 17:09:22 -05:00
# Create data directory AFTER all copies so permissions are never clobbered
RUN mkdir -p /app/data && chown nextjs:nodejs /app/data && chmod 700 /app/data
2026-03-12 17:09:22 -05:00
USER nextjs
EXPOSE 3000
2026-03-12 19:15:56 -05:00
ENV PORT=3000
2026-03-12 17:09:22 -05:00
# script to run migrations before starting
COPY --chown=nextjs:nodejs <<EOF /app/entrypoint.sh
#!/bin/sh
npx prisma db push --accept-data-loss
node server.js
EOF
RUN chmod +x /app/entrypoint.sh
CMD ["/app/entrypoint.sh"]