diff --git a/frontend/.dockerignore b/frontend/.dockerignore new file mode 100644 index 0000000..f353a64 --- /dev/null +++ b/frontend/.dockerignore @@ -0,0 +1,11 @@ +node_modules +npm-debug.log +build +.git +.gitignore +README.md +.env +.env.local +.env.development.local +.env.test.local +.env.production.local \ No newline at end of file diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..cab0f74 --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,31 @@ +# Build stage +FROM node:18-alpine as build + +WORKDIR /app + +# Copy package files +COPY package*.json ./ + +# Install dependencies +RUN npm ci + +# Copy source code +COPY . . + +# Build the app +RUN npm run build + +# Production stage +FROM nginx:alpine + +# Copy built assets from build stage +COPY --from=build /app/build /usr/share/nginx/html + +# Copy nginx configuration +COPY nginx.conf /etc/nginx/conf.d/default.conf + +# Expose port 80 +EXPOSE 80 + +# Start nginx +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/frontend/Dockerfile.dev b/frontend/Dockerfile.dev new file mode 100644 index 0000000..a43e677 --- /dev/null +++ b/frontend/Dockerfile.dev @@ -0,0 +1,18 @@ +FROM node:18-alpine + +WORKDIR /app + +# Copy package files +COPY package*.json ./ + +# Install dependencies +RUN npm install + +# Copy source code +COPY . . + +# Expose port 3000 for development server +EXPOSE 3000 + +# Start development server +CMD ["npm", "start"] \ No newline at end of file diff --git a/frontend/docker-compose.yml b/frontend/docker-compose.yml new file mode 100644 index 0000000..ab60bf2 --- /dev/null +++ b/frontend/docker-compose.yml @@ -0,0 +1,42 @@ +version: '3.8' + +services: + frontend: + build: + context: . + dockerfile: Dockerfile + ports: + - "80:80" + env_file: + - .env + environment: + - NODE_ENV=production + # Add your environment variables here + # - REACT_APP_API_URL=http://api.example.com + restart: unless-stopped + networks: + - app-network + + # Development service with hot reloading + frontend-dev: + build: + context: . + dockerfile: Dockerfile.dev + ports: + - "3000:3000" + volumes: + - .:/app + - /app/node_modules + env_file: + - .env + environment: + - NODE_ENV=development + # Add your development environment variables here + # - REACT_APP_API_URL=http://localhost:8000 + command: npm start + networks: + - app-network + +networks: + app-network: + driver: bridge \ No newline at end of file diff --git a/frontend/nginx.conf b/frontend/nginx.conf new file mode 100644 index 0000000..b6a7d58 --- /dev/null +++ b/frontend/nginx.conf @@ -0,0 +1,25 @@ +server { + listen 80; + server_name localhost; + + location / { + root /usr/share/nginx/html; + index index.html; + try_files $uri $uri/ /index.html; + } + + # Cache static assets + location /static/ { + root /usr/share/nginx/html; + expires 1y; + add_header Cache-Control "public, no-transform"; + } + + # Enable gzip compression + gzip on; + gzip_vary on; + gzip_min_length 10240; + gzip_proxied expired no-cache no-store private auth; + gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml application/javascript; + gzip_disable "MSIE [1-6]\."; +} \ No newline at end of file