From f585a5e35eca703a4514cf260a1d975ee585b674 Mon Sep 17 00:00:00 2001 From: Darian Date: Thu, 24 Sep 2026 15:05:23 +0330 Subject: [PATCH] Optimize Dockerfile and Next.js configuration for CI/CD efficiency. Implemented caching for npm installs, disabled React Compiler in Docker builds, and adjusted build command to use webpack. Updated GitHub Actions workflow to enhance build process with BuildKit support. --- .github/workflows/deploy.yml | 8 +++++++- Dockerfile | 8 +++++++- next.config.ts | 3 ++- package.json | 2 +- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index fa5726e..c15775d 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -13,6 +13,8 @@ env: NETWORK_NAME: shared_web_network # Public hostname (Nginx Proxy Manager → this container:3000) PUBLIC_HOST: aut.insaight.net + DOCKER_BUILDKIT: "1" + COMPOSE_DOCKER_CLI_BUILD: "1" jobs: deploy: @@ -29,7 +31,11 @@ jobs: || docker network create "$NETWORK_NAME" - name: Build image - run: docker build -t "$IMAGE_NAME" . + run: | + docker build \ + --progress=plain \ + -t "$IMAGE_NAME" \ + . - name: Restart container env: diff --git a/Dockerfile b/Dockerfile index 97b63ef..9d0b4d6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,14 +4,20 @@ FROM node:22-alpine AS deps WORKDIR /app COPY package.json package-lock.json ./ -RUN npm ci +RUN --mount=type=cache,target=/root/.npm \ + npm ci # ---- Builder ---- FROM node:22-alpine AS builder WORKDIR /app ENV NEXT_TELEMETRY_DISABLED=1 +# Skip React Compiler in image builds (big CPU/RAM cost on self-hosted runners) +ENV DISABLE_REACT_COMPILER=1 +# Cap parallelism a bit so Turbopack/webpack don't thrash low-RAM hosts +ENV NODE_OPTIONS=--max-old-space-size=3072 COPY --from=deps /app/node_modules ./node_modules COPY . . +# Explicit webpack: Next 16 default Turbopack often stalls/OOMs in constrained CI RUN npm run build # ---- Runner ---- diff --git a/next.config.ts b/next.config.ts index 5dbab66..7297d1c 100644 --- a/next.config.ts +++ b/next.config.ts @@ -5,7 +5,8 @@ const withNextIntl = createNextIntlPlugin("./src/i18n/request.ts"); const nextConfig: NextConfig = { output: "standalone", - reactCompiler: true, + // Babel React Compiler is heavy in Docker/CI; keep it for local `next dev`. + reactCompiler: process.env.DISABLE_REACT_COMPILER !== "1", experimental: { optimizePackageImports: ["lucide-react"], }, diff --git a/package.json b/package.json index d87821a..deb8f6c 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "private": true, "scripts": { "dev": "next dev", - "build": "next build", + "build": "next build --webpack", "start": "next start", "lint": "eslint" },