diff --git a/Dockerfile b/Dockerfile index db7bd09..817989d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,50 @@ -FROM node:18-alpine3.17 +FROM node:18-alpine AS base +# Install dependencies only when needed +FROM base AS deps WORKDIR /app -COPY ./ /app -RUN npm install +# 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 . . + +ENV NEXT_TELEMETRY_DISABLED 1 +RUN npx prisma generate RUN npm run build +# Production image, copy all the files and run next +FROM base AS runner +WORKDIR /app + +ENV NODE_ENV production +ENV NEXT_TELEMETRY_DISABLED 1 + +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 +# https://nextjs.org/docs/advanced-features/output-file-tracing +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static + +USER nextjs + EXPOSE 3000 -CMD npx prisma migrate deploy && npm run start +ENV PORT 3000 +# set hostname to localhost +ENV HOSTNAME "0.0.0.0" + +CMD npx prisma migrate deploy && node server.js diff --git a/docker-compose.yml b/docker-compose.yml index 26b1a1e..498aea2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,11 +18,10 @@ services: mylinks: restart: always container_name: MyLinks - image: sonny93/my-links:latest - # build: - # context: . + build: + context: . ports: - - 127.0.0.1:5000:3000 + - 127.0.0.1:3000:3000 env_file: - .env # depends_on: diff --git a/next.config.js b/next.config.js index 85cc5d9..0628de1 100644 --- a/next.config.js +++ b/next.config.js @@ -19,6 +19,7 @@ const config = { experimental: { webpackBuildWorker: true, }, + output: "standalone", }; module.exports = config;