feat: docker and compose
This commit is contained in:
67
Dockerfile
Normal file
67
Dockerfile
Normal file
@@ -0,0 +1,67 @@
|
||||
FROM node:20-alpine AS base
|
||||
|
||||
# Install OpenSSL and libc6-compat for Prisma
|
||||
RUN apk add --no-cache openssl3 libc6-compat
|
||||
|
||||
# Install pnpm
|
||||
RUN corepack enable && corepack prepare pnpm@latest --activate
|
||||
|
||||
# Install dependencies only when needed
|
||||
FROM base AS deps
|
||||
WORKDIR /app
|
||||
|
||||
# Copy package files
|
||||
COPY package.json pnpm-lock.yaml ./
|
||||
RUN pnpm install --frozen-lockfile
|
||||
|
||||
# Rebuild the source code only when needed
|
||||
FROM base AS builder
|
||||
WORKDIR /app
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY . .
|
||||
|
||||
# Build args for environment variables needed during build
|
||||
ARG NEXTAUTH_SECRET=dummy-secret-for-build-only
|
||||
ARG NEXTAUTH_URL=http://localhost:3000
|
||||
ARG DATABASE_URL=file:./prisma/dev.db
|
||||
|
||||
# Set environment variables for build
|
||||
ENV NEXTAUTH_SECRET=${NEXTAUTH_SECRET}
|
||||
ENV NEXTAUTH_URL=${NEXTAUTH_URL}
|
||||
ENV DATABASE_URL=${DATABASE_URL}
|
||||
ENV NODE_ENV=production
|
||||
|
||||
# Generate Prisma Client
|
||||
RUN pnpm prisma generate
|
||||
|
||||
# Build Next.js
|
||||
RUN pnpm build
|
||||
|
||||
# Production image, copy all the files and run next
|
||||
FROM base AS runner
|
||||
WORKDIR /app
|
||||
|
||||
ENV NODE_ENV=production
|
||||
ENV DATABASE_URL=file:./prisma/dev.db
|
||||
ENV NEXTAUTH_URL=http://localhost:3000
|
||||
|
||||
RUN addgroup --system --gid 1001 nodejs
|
||||
RUN adduser --system --uid 1001 nextjs
|
||||
|
||||
# Copy necessary files
|
||||
COPY --from=builder /app/public ./public
|
||||
COPY --from=builder /app/.next/standalone ./
|
||||
COPY --from=builder /app/.next/static ./.next/static
|
||||
|
||||
# Copy prisma schema (will be mounted as volume in dev)
|
||||
COPY --from=builder /app/prisma ./prisma
|
||||
|
||||
USER nextjs
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
ENV PORT=3000
|
||||
ENV HOSTNAME="0.0.0.0"
|
||||
|
||||
CMD ["node", "server.js"]
|
||||
|
||||
Reference in New Issue
Block a user