diff --git a/.dockerignore b/.dockerignore index 0d09073..dd02b1b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,7 +1,8 @@ -node_modules -.next +.env Dockerfile .dockerignore -.env -.env.local -.env.development.local \ No newline at end of file +node_modules +npm-debug.log +README.md +.next +.git \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index b8657de..2a8ce11 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,40 +1,59 @@ -# 1. Install dependencies only when needed -FROM node:18-alpine AS deps +##### DEPENDENCIES + +FROM --platform=linux/amd64 node:20-alpine AS deps +RUN apk add --no-cache libc6-compat openssl WORKDIR /app -# Install Prisma Client (important for runtime) -COPY package.json package-lock.json ./ -RUN npm ci +# Install Prisma Client - remove if not using Prisma -# 2. Build the app with Prisma & Next.js -FROM node:18-alpine AS builder +COPY prisma ./ + +# Install dependencies based on the preferred package manager + +COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml\* ./ + +RUN \ + if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ + elif [ -f package-lock.json ]; then npm ci; \ + elif [ -f pnpm-lock.yaml ]; then npm install -g pnpm && pnpm i; \ + else echo "Lockfile not found." && exit 1; \ + fi + +##### BUILDER + +FROM --platform=linux/amd64 node:20-alpine AS builder +ARG DATABASE_URL +ARG NEXT_PUBLIC_CLIENTVAR WORKDIR /app - -COPY . . COPY --from=deps /app/node_modules ./node_modules +COPY . . -# Generate Prisma client -RUN npx prisma generate +# ENV NEXT_TELEMETRY_DISABLED 1 -# Build the app -RUN npm run build +RUN \ + if [ -f yarn.lock ]; then SKIP_ENV_VALIDATION=1 yarn build; \ + elif [ -f package-lock.json ]; then SKIP_ENV_VALIDATION=1 npm run build; \ + elif [ -f pnpm-lock.yaml ]; then npm install -g pnpm && SKIP_ENV_VALIDATION=1 pnpm run build; \ + else echo "Lockfile not found." && exit 1; \ + fi -# 3. Final image -FROM node:18-alpine AS runner +##### RUNNER + +FROM --platform=linux/amd64 gcr.io/distroless/nodejs20-debian12 AS runner WORKDIR /app -ENV NODE_ENV=production +ENV NODE_ENV production -# Copy the built app + node_modules +# ENV NEXT_TELEMETRY_DISABLED 1 + +COPY --from=builder /app/next.config.js ./ COPY --from=builder /app/public ./public -COPY --from=builder /app/.next ./.next -COPY --from=builder /app/node_modules ./node_modules COPY --from=builder /app/package.json ./package.json -COPY --from=builder /app/prisma ./prisma -# Include the Prisma client -RUN npx prisma generate +COPY --from=builder /app/.next/standalone ./ +COPY --from=builder /app/.next/static ./.next/static -# Expose port and run EXPOSE 3000 -CMD ["npm", "start"] +ENV PORT 3000 + +CMD ["server.js"] \ No newline at end of file diff --git a/next.config.js b/next.config.js index 4f12fea..858e97e 100644 --- a/next.config.js +++ b/next.config.js @@ -8,6 +8,7 @@ const nextConfig = { reactStrictMode: true, eslint: { ignoreDuringBuilds: true, + output: "standalone", }, images: { remotePatterns: [ @@ -21,4 +22,5 @@ const nextConfig = { }, }; + export default nextConfig;