From 0d904b145c3485200a65551ddfdc5ca089e2c63c Mon Sep 17 00:00:00 2001 From: Ole Magnus Fon Johnsen Date: Mon, 4 Nov 2024 15:38:58 +0100 Subject: [PATCH] Dockerize Nextjs --- apps/web/Dockerfile | 38 +++++++++++++++++++++++++++ apps/web/fly.toml | 30 +++++++++++++++++++++ apps/web/next.config.ts | 2 ++ apps/web/package.json | 2 -- apps/web/src/app/layout.tsx | 5 ---- pnpm-lock.yaml | 52 ------------------------------------- 6 files changed, 70 insertions(+), 59 deletions(-) create mode 100644 apps/web/Dockerfile create mode 100644 apps/web/fly.toml diff --git a/apps/web/Dockerfile b/apps/web/Dockerfile new file mode 100644 index 000000000..98225e37d --- /dev/null +++ b/apps/web/Dockerfile @@ -0,0 +1,38 @@ +FROM node:20.18.0-alpine AS base + +RUN npm install -g turbo@2.0.14 +RUN npm install -g pnpm@9.7.1 + +FROM base AS builder + +RUN apk update +RUN apk add --no-cache libc6-compat + +WORKDIR /app +COPY . . +RUN turbo prune @echo-webkom/web --docker + +FROM base AS installer +RUN apk update +RUN apk add --no-cache libc6-compat +WORKDIR /app + +COPY --from=builder /app/out/json/ . +RUN pnpm install + +COPY --from=builder /app/out/full/ . + +RUN pnpm turbo build --filter=@echo-webkom/web... + +FROM base AS runner +WORKDIR /app + +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs +USER nextjs + +COPY --from=installer --chown=nextjs:nodejs /app/apps/web/.next/standalone ./ +COPY --from=installer --chown=nextjs:nodejs /app/apps/web/.next/static ./apps/web/.next/static +COPY --from=installer --chown=nextjs:nodejs /app/apps/web/public ./apps/web/public + +CMD node apps/web/server.js diff --git a/apps/web/fly.toml b/apps/web/fly.toml new file mode 100644 index 000000000..1eb16a7d4 --- /dev/null +++ b/apps/web/fly.toml @@ -0,0 +1,30 @@ +app = "fly-echo-web" +primary_region = "arn" +kill_signal = "SIGINT" +kill_timeout = 5 + +[[services]] +internal_port = 3000 +processes = [ "app" ] +protocol = "tcp" +auto_stop_machines = "stop" +auto_start_machines = true +min_machines_running = 1 +script_checks = [ ] + + # [services.concurrency] + # hard_limit = 120 + # soft_limit = 100 + # type = "requests" + + [[services.ports]] + handlers = [ "http" ] + port = 80 + force_https = true + + [[services.ports]] + handlers = [ "tls", "http" ] + port = 443 + +[[vm]] + size = "shared-cpu-4x" diff --git a/apps/web/next.config.ts b/apps/web/next.config.ts index d56554e3c..7b025b862 100644 --- a/apps/web/next.config.ts +++ b/apps/web/next.config.ts @@ -1,6 +1,8 @@ import type { NextConfig } from "next"; const config = { + output: "standalone", + transpilePackages: [ "@echo-webkom/db", "@echo-webkom/lib", diff --git a/apps/web/package.json b/apps/web/package.json index 2599ed1fd..4c2549afd 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -37,8 +37,6 @@ "@sanity/image-url": "1.1.0", "@tanstack/react-query": "5.65.1", "@types/remove-markdown": "0.3.4", - "@vercel/analytics": "1.3.2", - "@vercel/speed-insights": "1.0.14", "calendar-link": "2.7.0", "class-variance-authority": "0.7.0", "clsx": "2.1.1", diff --git a/apps/web/src/app/layout.tsx b/apps/web/src/app/layout.tsx index 4eef629c3..8d34a50ca 100644 --- a/apps/web/src/app/layout.tsx +++ b/apps/web/src/app/layout.tsx @@ -11,8 +11,6 @@ import { Unna, VT323, } from "next/font/google"; -import { Analytics } from "@vercel/analytics/react"; -import { SpeedInsights } from "@vercel/speed-insights/next"; import NextTopLoader from "nextjs-toploader"; import { EasterEgg } from "@/components/easter-egg"; @@ -166,9 +164,6 @@ export default function RootLayout({ children }: RootLayoutProps) { - - - {/* */} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cfcc4e071..27a742866 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -224,12 +224,6 @@ importers: '@types/remove-markdown': specifier: 0.3.4 version: 0.3.4 - '@vercel/analytics': - specifier: 1.3.2 - version: 1.3.2(next@15.1.6(@babel/core@7.25.8)(@playwright/test@1.48.2)(react-dom@19.0.0(react@19.0.0))(react@19.0.0))(react@19.0.0) - '@vercel/speed-insights': - specifier: 1.0.14 - version: 1.0.14(next@15.1.6(@babel/core@7.25.8)(@playwright/test@1.48.2)(react-dom@19.0.0(react@19.0.0))(react@19.0.0))(react@19.0.0) calendar-link: specifier: 2.7.0 version: 2.7.0 @@ -4669,40 +4663,6 @@ packages: '@ungap/structured-clone@1.2.0': resolution: {integrity: sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==} - '@vercel/analytics@1.3.2': - resolution: {integrity: sha512-n/Ws7skBbW+fUBMeg+jrT30+GP00jTHvCcL4fuVrShuML0uveEV/4vVUdvqEVnDgXIGfLm0GXW5EID2mCcRXhg==} - peerDependencies: - next: '>= 13' - react: ^18.0 || ^19.0 || ^19.0.0-rc - peerDependenciesMeta: - next: - optional: true - react: - optional: true - - '@vercel/speed-insights@1.0.14': - resolution: {integrity: sha512-env1BkPddz1UaEZwBL4GmfRksMi2LbiYaKuoxMQjfLk83aEh7kkWMukkUhpQVs717NE6nnD+1+KO85GZHOZ4nQ==} - peerDependencies: - '@sveltejs/kit': ^1 || ^2 - next: '>= 13' - react: ^18 || ^19 || ^19.0.0-rc - svelte: '>= 4' - vue: ^3 - vue-router: ^4 - peerDependenciesMeta: - '@sveltejs/kit': - optional: true - next: - optional: true - react: - optional: true - svelte: - optional: true - vue: - optional: true - vue-router: - optional: true - '@vitejs/plugin-react@4.3.3': resolution: {integrity: sha512-NooDe9GpHGqNns1i8XDERg0Vsg5SSYRhRxxyTGogUdkdNt47jal+fbuYi+Yfq6pzRCKXyoPcWisfxE6RIM3GKA==} engines: {node: ^14.18.0 || >=16.0.0} @@ -14060,18 +14020,6 @@ snapshots: '@ungap/structured-clone@1.2.0': {} - '@vercel/analytics@1.3.2(next@15.1.6(@babel/core@7.25.8)(@playwright/test@1.48.2)(react-dom@19.0.0(react@19.0.0))(react@19.0.0))(react@19.0.0)': - dependencies: - server-only: 0.0.1 - optionalDependencies: - next: 15.1.6(@babel/core@7.25.8)(@playwright/test@1.48.2)(react-dom@19.0.0(react@19.0.0))(react@19.0.0) - react: 19.0.0 - - '@vercel/speed-insights@1.0.14(next@15.1.6(@babel/core@7.25.8)(@playwright/test@1.48.2)(react-dom@19.0.0(react@19.0.0))(react@19.0.0))(react@19.0.0)': - optionalDependencies: - next: 15.1.6(@babel/core@7.25.8)(@playwright/test@1.48.2)(react-dom@19.0.0(react@19.0.0))(react@19.0.0) - react: 19.0.0 - '@vitejs/plugin-react@4.3.3(vite@5.4.9(@types/node@20.17.10)(terser@5.37.0))': dependencies: '@babel/core': 7.25.8