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..403971c29 --- /dev/null +++ b/Containerfile @@ -0,0 +1,37 @@ +FROM docker.io/node:24-slim AS base + +# Install dependencies only when needed +FROM base AS deps +WORKDIR /app +COPY package.json 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 --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"] 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. 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