From aaecf79c828c9a43df70427c244abc659ce631f4 Mon Sep 17 00:00:00 2001 From: hamed Hosseini Date: Wed, 9 Apr 2025 11:48:48 +0330 Subject: [PATCH] aset Dockerfile --- .dockerignore | 50 +++++++++++++++++++++++++++++++++++++++++ docker-compose.yaml | 11 --------- docker/nginx/nginx.conf | 15 ------------- dockerfile | 33 +++++++++++++++++---------- next.config.js | 9 ++++++++ 5 files changed, 80 insertions(+), 38 deletions(-) create mode 100644 .dockerignore delete mode 100644 docker-compose.yaml delete mode 100644 docker/nginx/nginx.conf create mode 100644 next.config.js diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..2419855 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,50 @@ +# Default Docker ignore +**/.dockerignore +**/Dockerfile +**/docker-compose* + +# Node.js specific +**/node_modules +**/npm-debug.log +**/yarn-debug.log +**/yarn-error.log +**/package-lock.json +**/yarn.lock + +# Next.js specific +**/.next +**/build +**/out +**/.cache + +# Testing +**/__tests__ +**/coverage +**/jest.config.js + +# Environment files +**/.env +**/.env.local +**/.env.development +**/.env.test + +# Version control +**/.git +**/.gitignore +**/.gitmodules + +# IDE specific +**/.vscode +**/.idea +**/*.iml + +# Miscellaneous +**/README.md +**/LICENSE +**/CHANGELOG.md +**/docs +**/notes +**/.DS_Store +**/Thumbs.db +**/tmp +**/dist \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml deleted file mode 100644 index f5a7eed..0000000 --- a/docker-compose.yaml +++ /dev/null @@ -1,11 +0,0 @@ -# docker-compose.yml -version: '3.8' - -services: - react-app: - build: . - ports: - - "3000:80" # Changed host port - environment: - - NODE_ENV=production - restart: unless-stopped \ No newline at end of file diff --git a/docker/nginx/nginx.conf b/docker/nginx/nginx.conf deleted file mode 100644 index 2a58950..0000000 --- a/docker/nginx/nginx.conf +++ /dev/null @@ -1,15 +0,0 @@ -server { - listen 80; - server_name localhost; - - location / { - root /usr/share/nginx/html; - index index.html index.htm; - try_files $uri $uri/ /index.html; - } - - error_page 500 502 503 504 /50x.html; - location = /50x.html { - root /usr/share/nginx/html; - } -} \ No newline at end of file diff --git a/dockerfile b/dockerfile index 75a0fb3..fca153a 100644 --- a/dockerfile +++ b/dockerfile @@ -3,30 +3,39 @@ FROM node:22-alpine AS builder WORKDIR /app -# Install system dependencies (if needed) -RUN apk add --no-cache python3 make g++ +# Install system dependencies for native modules +RUN apk add --no-cache python3 make g++ git # Copy package files COPY package*.json ./ # Install dependencies -RUN npm i --force +RUN npm install --force # Copy source code COPY . . -# Build React app +# Build Next.js application RUN npm run build # Production stage -FROM nginx:1.25-alpine +FROM node:22-alpine AS production -# Copy nginx config -COPY docker/nginx/nginx.conf /etc/nginx/conf.d/default.conf +WORKDIR /app -# Copy build artifacts -COPY --from=builder /app/build /usr/share/nginx/html +# Enable production mode +ENV NODE_ENV production -# Expose and run -EXPOSE 80 -CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file +# Install dependencies for production (curl for health checks) +RUN apk add --no-cache curl + +# Copy built assets from builder +COPY --from=builder /app/.next/standalone ./ +COPY --from=builder /app/.next/static ./.next/static +COPY --from=builder /app/public ./public + +# Expose the Next.js port +EXPOSE 3000 + +# Start the server +CMD ["node", "server.js"] \ No newline at end of file diff --git a/next.config.js b/next.config.js new file mode 100644 index 0000000..b60cc32 --- /dev/null +++ b/next.config.js @@ -0,0 +1,9 @@ +// next.config.js +const nextConfig = { + output: 'standalone', + // Add other configurations below + reactStrictMode: true, + swcMinify: true, + } + + module.exports = nextConfig \ No newline at end of file