From 840210e1aa45434333dd466e1acf6409d3084eb1 Mon Sep 17 00:00:00 2001 From: nwhco Date: Sun, 8 Dec 2024 19:16:38 +0100 Subject: [PATCH] refactor: production build code --- .env | 7 +++++++ .gitignore | 2 +- Dockerfile | 44 ++++++++++++++++++++++++++------------------ package.json | 4 ++-- src/config/index.ts | 8 +++++--- 5 files changed, 41 insertions(+), 24 deletions(-) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 0000000..6eff044 --- /dev/null +++ b/.env @@ -0,0 +1,7 @@ + +NEXT_PUBLIC_DEFAULT_LANGUAGE=en +NEXT_PUBLIC_AVAILABLE_LANGUAGES=en +NEXT_PUBLIC_ENABLE_MULTI_LANG=true +NODE_ENV=production +NEXT_PUBLIC_REST_API_ENDPOINT=https://mesbahi.nwhco.ir/api +NEXT_PUBLIC_SITE_URL=https://mesbahi.nwhco.ir:3000 diff --git a/.gitignore b/.gitignore index 40e16aa..69da2f7 100644 --- a/.gitignore +++ b/.gitignore @@ -25,7 +25,7 @@ yarn-debug.log* yarn-error.log* # local env files -.env +# .env .env.local .env.development.local .env.test.local diff --git a/Dockerfile b/Dockerfile index 63b3de3..4076b89 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,40 +1,48 @@ # Base image -FROM node:18-alpine +FROM node:18.20.5 # Set working directory WORKDIR /usr/src/app -# Copy package.json -COPY package.json ./ +# Copy package.json and package-lock.json (if exists) +COPY package.json ./ +RUN apt-get update && apt-get install -y build-essential +RUN rm -rf .next -# Install dependencies (using npm) +# Install dependencies RUN npm install --legacy-peer-deps +# RUN npm ci # Copy the rest of the application code - COPY . . -COPY .env ./ +# Set environment variables ENV NEXT_PUBLIC_DEFAULT_LANGUAGE=en -ENV NEXT_PUBLIC_AVAILABLE_LANGUAGES=en,fr,de +ENV NEXT_PUBLIC_AVAILABLE_LANGUAGES=en ENV NEXT_PUBLIC_ENABLE_MULTI_LANG=true +ENV NODE_ENV=production +ENV NEXT_PUBLIC_REST_API_ENDPOINT=https://mesbahi.nwhco.ir/api +ENV NEXT_PUBLIC_SITE_URL=https://mesbahi.nwhco.ir +ENV USE_MOCK_DATA=false +ENV USE_MOCK_DATA=true +# Verify environment variables (برای دیباگ) +# RUN echo "NEXT_PUBLIC_DEFAULT_LANGUAGE=${NEXT_PUBLIC_DEFAULT_LANGUAGE}" && \ + # echo "NEXT_PUBLIC_AVAILABLE_LANGUAGES=${NEXT_PUBLIC_AVAILABLE_LANGUAGES}" && \ + # echo "NEXT_PUBLIC_ENABLE_MULTI_LANG=${NEXT_PUBLIC_ENABLE_MULTI_LANG}" # Modify tsconfig.json to ignore type errors (optional) -RUN sed -i 's/"noEmitOnError": true/"noEmitOnError": false/' tsconfig.json && \ - sed -i 's/"strict": true/"strict": false/' tsconfig.json && \ - sed -i 's/"skipLibCheck": false/"skipLibCheck": true/' tsconfig.json - -RUN sed -i '/eslint:/a \ \ ignoreDuringBuilds: true,' next.config.js && \ - sed -i '/typescript:/a \ \ ignoreBuildErrors: true,' next.config.js - - -# Build the Next.js application -# RUN npm run build +# RUN sed -i 's/"noEmitOnError": true/"noEmitOnError": false/' tsconfig.json && \ +# sed -i 's/"strict": true/"strict": false/' tsconfig.json && \ +# sed -i 's/"skipLibCheck": false/"skipLibCheck": true/' tsconfig.json -RUN mkdir -p .next && echo "dummy-build-id" > .next/BUILD_ID +# # Modify next.config.js to ignore linting and type errors +# RUN sed -i '/eslint:/a \ \ ignoreDuringBuilds: true,' next.config.js && \ +# sed -i '/typescript:/a \ \ ignoreBuildErrors: true,' next.config.js +# Build the Next.js application with verbose logging +RUN npm run build --verbose # Expose the port the app runs on EXPOSE 3000 diff --git a/package.json b/package.json index f63cd24..cfa7d54 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,9 @@ "version": "6.6.0", "private": true, "scripts": { - "dev": "next dev -p 3002", + "dev": "next dev -p 3000", "build": "next build", - "start": "next start -p 3002", + "start": "next start -p 3000", "lint": "next lint" }, "dependencies": { diff --git a/src/config/index.ts b/src/config/index.ts index 23d4b26..b51af3d 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -1,4 +1,4 @@ -import invariant from 'tiny-invariant'; +const invariant = require('tiny-invariant'); invariant( process.env.NEXT_PUBLIC_DEFAULT_LANGUAGE, @@ -12,7 +12,7 @@ if (process.env.NEXT_PUBLIC_ENABLE_MULTI_LANG === 'true') { ); } -export const Config = { +const Config = { broadcastDriver: process.env.NEXT_PUBLIC_API_BROADCAST_DRIVER ?? 'log', pusherEnable: process.env.NEXT_PUBLIC_PUSHER_ENABLED ?? 'false', defaultLanguage: process.env.NEXT_PUBLIC_DEFAULT_LANGUAGE ?? 'en', @@ -21,8 +21,10 @@ export const Config = { : [], enableMultiLang: process.env.NEXT_PUBLIC_ENABLE_MULTI_LANG === 'true', rtlLanguages: ['ar', 'fa', 'he'], - getDirection: (language: string | undefined) => { + getDirection: (language) => { if (!language) return 'ltr'; return Config.rtlLanguages.includes(language) ? 'rtl' : 'ltr'; }, }; + +module.exports = { Config };