docker update

This commit is contained in:
2025-10-16 21:31:32 +05:30
parent 6fc27d0897
commit 97de061e60
2 changed files with 75 additions and 27 deletions

View File

@ -14,14 +14,19 @@ services:
- "3307:3306" - "3307:3306"
volumes: volumes:
- mysql_data:/var/lib/mysql - mysql_data:/var/lib/mysql
networks:
- vending-network
healthcheck: healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"] test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-prootpass"]
interval: 10s
timeout: 5s timeout: 5s
retries: 10 retries: 10
start_period: 30s
backend: backend:
build: build:
context: ./Machine-Backend context: ./Machine-Backend
dockerfile: Dockerfile
container_name: vending-backend container_name: vending-backend
env_file: env_file:
- ./Machine-Backend/.env - ./Machine-Backend/.env
@ -29,12 +34,20 @@ services:
- "8087:5000" - "8087:5000"
volumes: volumes:
- ./Machine-Backend:/app - ./Machine-Backend:/app
networks:
- vending-network
depends_on: depends_on:
db: db:
condition: service_healthy condition: service_healthy
restart: always restart: always
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:5000/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
command: > command: >
sh -c "python seed_user.py && gunicorn --bind 0.0.0.0:5000 run:app" sh -c "python seed_user.py && gunicorn --bind 0.0.0.0:5000 --workers 2 --timeout 120 run:app"
frontend: frontend:
build: build:
@ -43,9 +56,23 @@ services:
container_name: vending-frontend container_name: vending-frontend
ports: ports:
- "8086:80" - "8086:80"
networks:
- vending-network
depends_on: depends_on:
- backend backend:
condition: service_healthy
restart: always restart: always
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:80"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
networks:
vending-network:
driver: bridge
volumes: volumes:
mysql_data: mysql_data:
driver: local

View File

@ -6,19 +6,16 @@ FROM node:18-alpine AS builder
# Set working directory # Set working directory
WORKDIR /app WORKDIR /app
# Copy only package files first (for caching) # Copy package files
COPY package*.json ./ COPY package*.json ./
# Install dependencies efficiently # Install dependencies
# --legacy-peer-deps fixes Angular peer conflicts
# --no-audit and --no-fund speed up installation
RUN npm ci --legacy-peer-deps --no-audit --no-fund RUN npm ci --legacy-peer-deps --no-audit --no-fund
# Copy source code (after dependencies cached) # Copy source code
COPY . . COPY . .
# Build the Angular app in production mode # Build Angular app for production
# Disable analytics + progress bar to reduce overhead
RUN npm run build -- --configuration production --no-progress RUN npm run build -- --configuration production --no-progress
# =============================== # ===============================
@ -26,24 +23,48 @@ RUN npm run build -- --configuration production --no-progress
# =============================== # ===============================
FROM nginx:alpine AS production FROM nginx:alpine AS production
# Copy built Angular files from builder # Copy built files from builder stage
COPY --from=builder /app/dist/fuse-angular /usr/share/nginx/html COPY --from=builder /app/dist/fuse-angular /usr/share/nginx/html
# Angular-friendly Nginx config # Create custom Nginx configuration
RUN echo 'server { \ COPY <<'EOF' /etc/nginx/conf.d/default.conf
listen 80; \ server {
server_name localhost; \ listen 80;
root /usr/share/nginx/html; \ server_name localhost;
index index.html; \ root /usr/share/nginx/html;
location / { \ index index.html;
try_files $uri $uri/ /index.html; \
} \ # Enable gzip compression
location /api/ { \ gzip on;
proxy_pass http://backend:5000/; \ gzip_types text/css application/javascript application/json image/svg+xml;
} \ gzip_comp_level 6;
}' > /etc/nginx/conf.d/default.conf
# Angular routing - serve index.html for all routes
location / {
try_files $uri $uri/ /index.html;
}
# Proxy API requests to backend
location /api/ {
proxy_pass http://backend:5000/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Cache static assets
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
}
EOF
EXPOSE 80 EXPOSE 80
# Run Nginx in foreground
CMD ["nginx", "-g", "daemon off;"] CMD ["nginx", "-g", "daemon off;"]