From 29e2ba9bd7e755f7dc6289300a7e99575ea73fd8 Mon Sep 17 00:00:00 2001 From: hamedhosseini Date: Mon, 30 Jun 2025 17:13:29 +0330 Subject: [PATCH 1/4] set dockerfile --- docker-compose.yaml | 22 +++++++++++++----- dockerfile | 54 +++++++++++++++++++++++++++++---------------- 2 files changed, 52 insertions(+), 24 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index f5a7eed..99d32bb 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,11 +1,23 @@ # docker-compose.yml -version: '3.8' +version: "3.8" services: - react-app: - build: . + frontend: + build: + context: . + dockerfile: Dockerfile + args: + - NODE_ENV=production + - NEXT_TELEMETRY_DISABLED=1 + - NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} + - NEXT_PUBLIC_CLIENT_ID=${NEXT_PUBLIC_CLIENT_ID} + - NEXT_PUBLIC_CLIENT_SECRET=${NEXT_PUBLIC_CLIENT_SECRET} + restart: unless-stopped + container_name: nobat724-frontend ports: - - "3000:80" # Changed host port + - "3001:3000" environment: - NODE_ENV=production - restart: unless-stopped \ No newline at end of file + - NEXT_TELEMETRY_DISABLED=1 + - NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} + - NEXT_PUBLIC_CLIENT_ID=${NEXT_PUBLIC_CLIENT_ID} \ No newline at end of file diff --git a/dockerfile b/dockerfile index abbe1f5..5b94891 100644 --- a/dockerfile +++ b/dockerfile @@ -1,32 +1,48 @@ -# Build stage -FROM node:22-alpine AS builder +# Dockerfile for Next.js 14 - Optimized for Production +# Use the official Node.js image with Alpine Linux for a smaller footprint +FROM node:22-alpine AS base + +# Set the working directory in the container WORKDIR /app -# Install system dependencies (if needed) -RUN apk add --no-cache python3 make g++ - -# Copy package files +# Copy package.json and package-lock.json (or yarn.lock) COPY package*.json ./ -# Install dependencies -RUN npm npm i --force +# Install dependencies - leveraging Docker cache +RUN npm i --force -# Copy source code +# Copy the rest of the application code COPY . . -# Build React app +# Build the Next.js application RUN npm run build -# Production stage -FROM nginx:1.25-alpine +# Stage 2: Production image - smaller and leaner +FROM node:22-alpine AS runner -# Copy nginx config -COPY docker/nginx/nginx.conf /etc/nginx/conf.d/default.conf +# Set the working directory +WORKDIR /app -# Copy build artifacts -COPY --from=builder /app/build /usr/share/nginx/html +# Set environment variables +ENV NODE_ENV production +ENV NEXT_TELEMETRY_DISABLED 1 -# Expose and run -EXPOSE 80 -CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file +# Add a non-root user for security +RUN addgroup -g 1001 -S nodejs +RUN adduser -S nextjs -u 1001 + +# Copy only the necessary files from the builder stage +COPY --from=base /app/next.config.js ./ +COPY --from=base /app/public ./public +COPY --from=base --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=base --chown=nextjs:nodejs /app/.next/static ./.next/static + +# Change ownership of all copied files to the non-root user +USER nextjs + +# Expose the port Next.js listens on +EXPOSE 3000 + +# Command to start the Next.js server in production mode +CMD ["node", "server.js"] \ No newline at end of file From 95978f325801ff2e63bf9743f154875e91f059e3 Mon Sep 17 00:00:00 2001 From: hamed Date: Tue, 23 Sep 2025 11:27:32 +0330 Subject: [PATCH 2/4] remove docker-compose.yaml file --- docker-compose.yaml | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 docker-compose.yaml diff --git a/docker-compose.yaml b/docker-compose.yaml deleted file mode 100644 index 99d32bb..0000000 --- a/docker-compose.yaml +++ /dev/null @@ -1,23 +0,0 @@ -# docker-compose.yml -version: "3.8" - -services: - frontend: - build: - context: . - dockerfile: Dockerfile - args: - - NODE_ENV=production - - NEXT_TELEMETRY_DISABLED=1 - - NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} - - NEXT_PUBLIC_CLIENT_ID=${NEXT_PUBLIC_CLIENT_ID} - - NEXT_PUBLIC_CLIENT_SECRET=${NEXT_PUBLIC_CLIENT_SECRET} - restart: unless-stopped - container_name: nobat724-frontend - ports: - - "3001:3000" - environment: - - NODE_ENV=production - - NEXT_TELEMETRY_DISABLED=1 - - NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} - - NEXT_PUBLIC_CLIENT_ID=${NEXT_PUBLIC_CLIENT_ID} \ No newline at end of file From e86f23688e06221cf48029aa19c28477d134d40b Mon Sep 17 00:00:00 2001 From: hamed Date: Sun, 28 Sep 2025 14:46:27 +0330 Subject: [PATCH 3/4] docs: update README for environment variable configuration and clarify usage in Next.js docker: modify Dockerfile to set NODE_ENV from environment variable for flexibility --- README.md | 12 +++++++----- dockerfile | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 1312870..22496e2 100644 --- a/README.md +++ b/README.md @@ -55,14 +55,17 @@ Checks the code for linting issues. ## ⚙️ Environment Variables -Create a `.env` file in the root directory with the following variables: +Create a `.env.local` file in the root directory with the following variables: ``` -REACT_APP_API_URL=https://back-dev.clinic-pro.ir -REACT_APP_CLIENT_ID=NWuujdYHjtAtrhrk_zoWB3w0kyf56wRCOaY36MIqvbs -REACT_APP_CLIENT_SECRET=trhrk_zoWB3w0kyf +NEXT_PUBLIC_API_URL=https://back-dev.clinic-pro.ir +NEXT_PUBLIC_CLIENT_ID=NWuujdYHjtAtrhrk_zoWB3w0kyf56wRCOaY36MIqvbs +NEXT_PUBLIC_CLIENT_SECRET=trhrk_zoWB3w0kyf +NODE_ENV=development # or production ``` +**Note:** In Next.js, environment variables that need to be accessible in the browser must be prefixed with `NEXT_PUBLIC_`. Variables without this prefix are only available on the server side. + ## 🌐 Features - ✅ Responsive design using MUI and Tailwind @@ -99,4 +102,3 @@ This project is private or under your preferred license. --- > Developed with ❤️ by the Nobat724 team. - diff --git a/dockerfile b/dockerfile index 5b94891..2f9804a 100644 --- a/dockerfile +++ b/dockerfile @@ -25,7 +25,7 @@ FROM node:22-alpine AS runner WORKDIR /app # Set environment variables -ENV NODE_ENV production +ENV NODE_ENV $NODE_ENV ENV NEXT_TELEMETRY_DISABLED 1 # Add a non-root user for security From 234bcf5aca147d6888867fb0b6a262e7e61c0549 Mon Sep 17 00:00:00 2001 From: hamed Date: Sun, 28 Sep 2025 15:48:17 +0330 Subject: [PATCH 4/4] refactor: remove hardcoded NODE_ENV value from docker-compose.yml --- docker-compose.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 7b540a6..0c1d5fd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,7 +16,6 @@ services: ports: - "${APP_PORT}:3000" environment: - - NODE_ENV=production - NEXT_TELEMETRY_DISABLED=1 - NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} - NEXT_PUBLIC_CLIENT_ID=${NEXT_PUBLIC_CLIENT_ID}