Files
portfolio/docker-compose.zero-downtime-fixed.yml
denshooter efda383bd8
Some checks failed
CI/CD Pipeline (Fast) / production (push) Successful in 6m44s
CI/CD Pipeline (Simple & Reliable) / production (push) Has been cancelled
CI/CD Pipeline (Reliable & Simple) / production (push) Has been cancelled
Fix nginx configuration syntax errors
- Move proxy_set_header directives inside location blocks
- Add DNS resolver for dynamic upstream resolution
- Improve fallback configuration in docker-compose
- Add config validation before starting nginx

This should resolve the nginx startup failures.
2025-09-15 23:51:59 +02:00

184 lines
5.4 KiB
YAML

# Zero-Downtime Deployment Configuration (Fixed)
# Uses nginx as load balancer for seamless updates
# Fixed to work in Gitea Actions environment
services:
nginx:
image: nginx:alpine
container_name: portfolio-nginx
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
# Use a more robust path that works in CI/CD environments
- ./nginx-zero-downtime.conf:/etc/nginx/nginx.conf:ro
# Remove default nginx configuration to prevent conflicts
- /etc/nginx/conf.d
networks:
- portfolio_net
depends_on:
- portfolio-app-1
- portfolio-app-2
healthcheck:
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost/health"]
interval: 10s
timeout: 5s
retries: 3
# Fallback: if the config file doesn't exist, create a basic one
command: >
sh -c "
# Remove default nginx configuration files to prevent conflicts
rm -rf /etc/nginx/conf.d/*
# Test the main config first
if nginx -t -c /etc/nginx/nginx.conf 2>/dev/null; then
echo 'Using main nginx configuration'
else
echo 'Main config failed, creating fallback nginx configuration...'
cat > /etc/nginx/nginx.conf << 'EOF'
events {
worker_connections 1024;
}
http {
upstream portfolio_backend {
server portfolio-app-1:3000 max_fails=3 fail_timeout=30s;
server portfolio-app-2:3000 max_fails=3 fail_timeout=30s;
}
server {
listen 80;
server_name _;
location /health {
access_log off;
return 200 'healthy\n';
add_header Content-Type text/plain;
}
location / {
proxy_pass http://portfolio_backend;
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;
proxy_connect_timeout 5s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
}
}
}
EOF
fi
nginx -g 'daemon off;'
"
portfolio-app-1:
image: portfolio-app:latest
container_name: portfolio-app-1
restart: unless-stopped
environment:
- NODE_ENV=${NODE_ENV:-production}
- LOG_LEVEL=${LOG_LEVEL:-info}
- DATABASE_URL=postgresql://portfolio_user:portfolio_pass@postgres:5432/portfolio_db?schema=public
- REDIS_URL=redis://redis:6379
- NEXT_PUBLIC_BASE_URL=${NEXT_PUBLIC_BASE_URL}
- NEXT_PUBLIC_UMAMI_URL=${NEXT_PUBLIC_UMAMI_URL}
- NEXT_PUBLIC_UMAMI_WEBSITE_ID=${NEXT_PUBLIC_UMAMI_WEBSITE_ID}
- MY_EMAIL=${MY_EMAIL}
- MY_INFO_EMAIL=${MY_INFO_EMAIL}
- MY_PASSWORD=${MY_PASSWORD}
- MY_INFO_PASSWORD=${MY_INFO_PASSWORD}
- ADMIN_BASIC_AUTH=${ADMIN_BASIC_AUTH}
volumes:
- portfolio_data:/app/.next/cache
networks:
- portfolio_net
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/api/health"]
interval: 10s
timeout: 5s
retries: 3
start_period: 30s
portfolio-app-2:
image: portfolio-app:latest
container_name: portfolio-app-2
restart: unless-stopped
environment:
- NODE_ENV=${NODE_ENV:-production}
- LOG_LEVEL=${LOG_LEVEL:-info}
- DATABASE_URL=postgresql://portfolio_user:portfolio_pass@postgres:5432/portfolio_db?schema=public
- REDIS_URL=redis://redis:6379
- NEXT_PUBLIC_BASE_URL=${NEXT_PUBLIC_BASE_URL}
- NEXT_PUBLIC_UMAMI_URL=${NEXT_PUBLIC_UMAMI_URL}
- NEXT_PUBLIC_UMAMI_WEBSITE_ID=${NEXT_PUBLIC_UMAMI_WEBSITE_ID}
- MY_EMAIL=${MY_EMAIL}
- MY_INFO_EMAIL=${MY_INFO_EMAIL}
- MY_PASSWORD=${MY_PASSWORD}
- MY_INFO_PASSWORD=${MY_INFO_PASSWORD}
- ADMIN_BASIC_AUTH=${ADMIN_BASIC_AUTH}
volumes:
- portfolio_data:/app/.next/cache
networks:
- portfolio_net
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/api/health"]
interval: 10s
timeout: 5s
retries: 3
start_period: 30s
postgres:
image: postgres:16-alpine
container_name: portfolio-postgres
restart: unless-stopped
environment:
- POSTGRES_DB=portfolio_db
- POSTGRES_USER=portfolio_user
- POSTGRES_PASSWORD=portfolio_pass
volumes:
- postgres_data:/var/lib/postgresql/data
networks:
- portfolio_net
healthcheck:
test: ["CMD-SHELL", "pg_isready -U portfolio_user -d portfolio_db"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
redis:
image: redis:7-alpine
container_name: portfolio-redis
restart: unless-stopped
volumes:
- redis_data:/data
networks:
- portfolio_net
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
volumes:
portfolio_data:
driver: local
postgres_data:
driver: local
redis_data:
driver: local
networks:
portfolio_net:
driver: bridge