From 8dddc88717c059a36d50724199569f285df155af Mon Sep 17 00:00:00 2001 From: Tyler Allen Date: Fri, 13 Jun 2025 13:40:55 +0000 Subject: [PATCH 1/3] Containerfile for production builds --- .gitignore | 1 + Containerfile | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 Containerfile diff --git a/.gitignore b/.gitignore index 9fb0fe3e6..7b698b20a 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ .DS_Store *.pem .vscode +.idea # debug npm-debug.log* diff --git a/Containerfile b/Containerfile new file mode 100644 index 000000000..dac8a320f --- /dev/null +++ b/Containerfile @@ -0,0 +1,41 @@ +FROM docker.io/node:24-slim AS base + +# Install dependencies only when needed +FROM base AS deps +# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. +RUN apk add --no-cache libc6-compat +WORKDIR /app + +# Install dependencies based on the preferred package manager +COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc* ./ +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 . . +RUN corepack enable pnpm && pnpm run build + +# Production image, copy all the files and run next +FROM base AS runner +WORKDIR /app +# Set all env variables here +ENV PORT=3000 +ENV HOSTNAME="0.0.0.0" +ENV NODE_ENV=production +ENV NEXT_TELEMETRY_DISABLED=1 +# Remove this in the case of kubernetes, probably +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs +# Automatically leverage output traces to reduce image size +# https://nextjs.org/docs/advanced-features/output-file-tracing +COPY --from=builder /app/public ./public +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static +USER nextjs +EXPOSE 3000 +# server.js is created by next build from the standalone output +# https://nextjs.org/docs/pages/api-reference/config/next-config-js/output +CMD ["node", "server.js"] From 54ef6c032aa6895a5c6692bfb4afbb019ac13bcf Mon Sep 17 00:00:00 2001 From: Tyler Allen Date: Fri, 13 Jun 2025 13:43:45 +0000 Subject: [PATCH 2/3] readme to talk about deployment --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 3281d4830..9794f56ce 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,12 @@ pnpm install pnpm dev ``` +## Running For Production + +Check out the Next.js documentation on options for running this. +https://nextjs.org/docs/pages/getting-started/deploying +Alternatively, use the provided [Containerfile](Containerfile). + ## Database (Optional) Create a `.env.local` file with your `POSTGRES_URL` environment variable to store redirects. From 3e379f2c9124938d4b624d81b32e059dbb08f3c4 Mon Sep 17 00:00:00 2001 From: Tyler Allen Date: Fri, 13 Jun 2025 14:57:34 +0000 Subject: [PATCH 3/3] optimized build --- Containerfile | 8 ++------ next.config.ts | 6 ++++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Containerfile b/Containerfile index dac8a320f..403971c29 100644 --- a/Containerfile +++ b/Containerfile @@ -2,12 +2,8 @@ FROM docker.io/node:24-slim AS base # Install dependencies only when needed FROM base AS deps -# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. -RUN apk add --no-cache libc6-compat WORKDIR /app - -# Install dependencies based on the preferred package manager -COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc* ./ +COPY package.json package-lock.json* pnpm-lock.yaml* .npmrc* ./ RUN corepack enable pnpm && pnpm i --frozen-lockfile @@ -18,6 +14,7 @@ COPY --from=deps /app/node_modules ./node_modules COPY . . RUN corepack enable pnpm && pnpm run build + # Production image, copy all the files and run next FROM base AS runner WORKDIR /app @@ -31,7 +28,6 @@ RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs # Automatically leverage output traces to reduce image size # https://nextjs.org/docs/advanced-features/output-file-tracing -COPY --from=builder /app/public ./public COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static USER nextjs diff --git a/next.config.ts b/next.config.ts index e7f947421..e4e6b7e75 100644 --- a/next.config.ts +++ b/next.config.ts @@ -29,9 +29,11 @@ const nextConfig: NextConfig = { // the `experimental.mdxRs` flag. experimental: { mdxRs: true - } + }, + + output: 'standalone' }; const withMDX = createMDX({}); -export default withMDX(nextConfig); +export default withMDX(nextConfig); \ No newline at end of file