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

@ -6,19 +6,16 @@ FROM node:18-alpine AS builder
# Set working directory
WORKDIR /app
# Copy only package files first (for caching)
# Copy package files
COPY package*.json ./
# Install dependencies efficiently
# --legacy-peer-deps fixes Angular peer conflicts
# --no-audit and --no-fund speed up installation
# Install dependencies
RUN npm ci --legacy-peer-deps --no-audit --no-fund
# Copy source code (after dependencies cached)
# Copy source code
COPY . .
# Build the Angular app in production mode
# Disable analytics + progress bar to reduce overhead
# Build Angular app for production
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
# Copy built Angular files from builder
# Copy built files from builder stage
COPY --from=builder /app/dist/fuse-angular /usr/share/nginx/html
# Angular-friendly Nginx config
RUN echo 'server { \
listen 80; \
server_name localhost; \
root /usr/share/nginx/html; \
index index.html; \
location / { \
try_files $uri $uri/ /index.html; \
} \
location /api/ { \
proxy_pass http://backend:5000/; \
} \
}' > /etc/nginx/conf.d/default.conf
# Create custom Nginx configuration
COPY <<'EOF' /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html;
# Enable gzip compression
gzip on;
gzip_types text/css application/javascript application/json image/svg+xml;
gzip_comp_level 6;
# 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
# Run Nginx in foreground
CMD ["nginx", "-g", "daemon off;"]
CMD ["nginx", "-g", "daemon off;"]