From b9c5ab69e62ed6f3b7ef839b8f4885f7a2b72f18 Mon Sep 17 00:00:00 2001 From: Mohammed Al-yaseen Date: Sun, 23 Nov 2025 18:00:22 +0300 Subject: [PATCH] update docker files --- Dockerfile | 29 +++++++++++++++++++---------- Dockerfile.prod | 33 +++++++++++++++++++++++++++++++++ docker-compose.prod.yml | 26 ++++++++++++++++++++++++++ docker-compose.yml | 29 +++++++++++++++++++++++++++++ 4 files changed, 107 insertions(+), 10 deletions(-) create mode 100644 Dockerfile.prod create mode 100644 docker-compose.prod.yml create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile index f0e637a..ad87107 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,28 @@ -FROM node:20-alpine AS builder +# Use Node.js 20 Alpine as base image for smaller size +FROM node:20-alpine +# Set working directory WORKDIR /app +# Install dependencies for node-gyp and other native modules +RUN apk add --no-cache python3 make g++ + +# Copy package files COPY package.json yarn.lock ./ -RUN corepack enable && yarn install --frozen-lockfile +# Install dependencies +RUN yarn install --frozen-lockfile + +# Copy source code COPY . . -RUN yarn build -FROM nginx:1.27-alpine +# Expose port 3000 (default React dev server port) +EXPOSE 3000 -RUN rm -rf /usr/share/nginx/html/* -COPY --from=builder /app/dist /usr/share/nginx/html - -EXPOSE 80 - -CMD ["nginx", "-g", "daemon off;"] +# Set environment variables for development +ENV NODE_ENV=development +ENV CHOKIDAR_USEPOLLING=true +ENV WATCHPACK_POLLING=true +# Start the development server +CMD ["yarn", "dev"] \ No newline at end of file diff --git a/Dockerfile.prod b/Dockerfile.prod new file mode 100644 index 0000000..a75ed5f --- /dev/null +++ b/Dockerfile.prod @@ -0,0 +1,33 @@ +# Multi-stage build for production +# Stage 1: Build the React application +FROM node:20-alpine AS build + +# Set working directory +WORKDIR /app + +# Copy package files +COPY package.json yarn.lock ./ + +# Install dependencies +RUN yarn install --frozen-lockfile + +# Copy source code +COPY . . + +# Build the application for production +RUN yarn build + +# Stage 2: Serve with nginx +FROM nginx:alpine + +# Copy custom nginx configuration +COPY nginx.conf /etc/nginx/nginx.conf + +# Copy built application from build stage +COPY --from=build /app/build /usr/share/nginx/html + +# Expose port 80 +EXPOSE 80 + +# Start nginx +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml new file mode 100644 index 0000000..9dd9643 --- /dev/null +++ b/docker-compose.prod.yml @@ -0,0 +1,26 @@ +version: '3.8' + +services: + dashboard-app-prod: + build: + context: . + dockerfile: Dockerfile.prod + ports: + - '3009:80' + environment: + - NODE_ENV=production + env_file: + - .env.prod + restart: unless-stopped + networks: + - dashboard-network + healthcheck: + test: ['CMD', 'curl', '-f', 'http://localhost/health'] + interval: 30s + timeout: 10s + retries: 3 + start_period: 40s + +networks: + dashboard-network: + driver: bridge diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0884e1f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,29 @@ +version: '3.8' + +services: + dashboard-app-dev: + build: + context: . + dockerfile: Dockerfile + ports: + - '3008:3000' + volumes: + # Mount source code for hot reloading + - .:/app + # Exclude node_modules to use container's version + - /app/node_modules + environment: + - NODE_ENV=development + - CHOKIDAR_USEPOLLING=true + - WATCHPACK_POLLING=true + - REACT_APP_API_URL=${REACT_APP_API_URL:-https://amazon.fascano.com} + env_file: + - .env.develop + stdin_open: true + tty: true + networks: + - dashboard-network + +networks: + dashboard-network: + driver: bridge