From 3d48aa0aac9c4a841bceee767b9a07f7e2ee841b Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Thu, 27 Feb 2025 22:41:14 +0100 Subject: [PATCH] Add docker build for deployment --- .dockerignore | 3 +++ Dockerfile | 47 +++++++++++++++++++++++++++++++++++++++++++++++ next.config.ts | 2 +- 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..932f6d7 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +node_modules +.next/ +next-env.d.ts diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fd69d6f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,47 @@ +# syntax=docker.io/docker/dockerfile:1 +FROM node:22 AS base + +# Install dependencies only when needed +FROM base AS deps +WORKDIR /app + +COPY package.json pnpm-lock.yaml* ./ +RUN corepack enable pnpm && pnpm i --frozen-lockfile + +# 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 corepack enable pnpm && pnpm 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 + +# 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 +COPY --chown=nextjs:nodejs schedule.json . + +USER nextjs + +EXPOSE 3000 + +ENV PORT=3000 + +# server.js is created by next build from the standalone output +# https://nextjs.org/docs/pages/api-reference/config/next-config-js/output +ENV HOSTNAME="0.0.0.0" +CMD ["node", "server.js"] diff --git a/next.config.ts b/next.config.ts index 7921f35..398b0d5 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,7 +1,7 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { - /* config options here */ + output: "standalone", }; export default nextConfig;