svalavuo 2 дней назад
Родитель
Сommit
550c01fbc7
3 измененных файлов с 28 добавлено и 3 удалено
  1. 14 1
      docker-compose.yml
  2. 3 0
      frontend/Dockerfile
  3. 11 2
      frontend/nginx.conf

+ 14 - 1
docker-compose.yml

@@ -31,6 +31,12 @@ services:
     networks:
       - inventory-network
     restart: unless-stopped
+    healthcheck:
+      test: ["CMD", "curl", "-f", "http://localhost/api/company.php"]
+      interval: 30s
+      timeout: 10s
+      retries: 3
+      start_period: 40s
 
   # Frontend Vue.js Service
   frontend:
@@ -43,10 +49,17 @@ services:
     environment:
       - VUE_APP_API_URL=${VUE_APP_API_URL:-http://localhost:8080}
     depends_on:
-      - backend
+      backend:
+        condition: service_healthy
     networks:
       - inventory-network
     restart: unless-stopped
+    healthcheck:
+      test: ["CMD", "curl", "-f", "http://localhost/"]
+      interval: 30s
+      timeout: 10s
+      retries: 3
+      start_period: 30s
 
   # Redis Cache Service (Optional)
   redis:

+ 3 - 0
frontend/Dockerfile

@@ -19,6 +19,9 @@ RUN npm run build
 # Production stage
 FROM nginx:alpine
 
+# Install curl for health checks
+RUN apk add --no-cache curl
+
 # Copy built application
 COPY --from=build /app/dist /usr/share/nginx/html
 

+ 11 - 2
frontend/nginx.conf

@@ -15,14 +15,23 @@ server {
         try_files $uri $uri/ /index.html;
     }
 
-    # API proxy to backend
+    # API proxy to backend with service discovery
     location /api/ {
-        proxy_pass http://backend:80;
+        # Use resolver for Docker DNS
+        resolver 127.0.0.11 valid=30s;
+        set $backend_endpoint http://backend:80;
+        proxy_pass $backend_endpoint;
         proxy_set_header Host $host;
         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;
         
+        # Error handling for backend service
+        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
+        proxy_connect_timeout 5s;
+        proxy_send_timeout 10s;
+        proxy_read_timeout 10s;
+        
         # Handle CORS headers
         add_header Access-Control-Allow-Origin "*" always;
         add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS" always;