services: blog: # Immagine versionata/digest tramite variabile d'ambiente (vedi .env). # Evita :latest in produzione per avere deploy riproducibili. image: "${BLOG_IMAGE:?BLOG_IMAGE non impostata: copia .env.example in .env}" restart: unless-stopped networks: - app-network environment: - _JAVA_OPTIONS=-Xmx512m -Xms256m - SPRING_PROFILES_ACTIVE=prod - MANAGEMENT_PROMETHEUS_METRICS_EXPORT_ENABLED=true - SPRING_DATASOURCE_URL=jdbc:postgresql://postgresql:5432/blog - SPRING_DATASOURCE_USERNAME=blog - SPRING_DATASOURCE_PASSWORD=${POSTGRES_PASSWORD:?POSTGRES_PASSWORD non impostata, vedi .env.example} - SPRING_LIQUIBASE_URL=jdbc:postgresql://postgresql:5432/blog # Non esporre la porta 8080 sull'host: l'app deve essere raggiungibile # solo tramite nginx (TLS/HSTS/header di sicurezza). # Per debug locale, decommenta e usa il binding su loopback: # ports: # - 127.0.0.1:8080:8080 depends_on: postgresql: condition: service_healthy healthcheck: # JHipster espone l'endpoint /management/health. Usiamo wget perché le # immagini JRE slim non sempre includono curl. L'healthcheck serve per # l'ordine di avvio e per lo stato in "docker-compose ps": Docker NON # riavvia un container perché "unhealthy" (restart agisce solo all'uscita # del processo); per il self-healing usa uno strumento come willfarrell/autoheal. test: ["CMD-SHELL", "wget -qO- http://localhost:8080/management/health || exit 1"] interval: 30s timeout: 10s retries: 5 start_period: 60s postgresql: image: postgres:17.11 restart: unless-stopped volumes: - postgresql-data:/var/lib/postgresql/data/ networks: - app-network environment: - POSTGRES_USER=blog # Nome del database esplicito: senza questa riga l'immagine usa POSTGRES_USER # come default. Dichiararlo evita che, cambiando l'utente in futuro, cambi # anche il nome del DB rompendo silenziosamente l'URL JDBC del servizio blog. - POSTGRES_DB=blog # Password letta da .env (non committato). Niente auth "trust" in produzione. - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:?POSTGRES_PASSWORD non impostata, vedi .env.example} healthcheck: # Forza il TCP (-h localhost) e nomina il database per non risultare # "healthy" durante il bootstrap initdb, quando esiste solo il server temporaneo. test: [ 'CMD-SHELL', 'pg_isready -h localhost -U $${POSTGRES_USER} -d $${POSTGRES_USER}' ] interval: 5s timeout: 5s retries: 10 # PostgreSQL è raggiungibile solo tramite la rete interna app-network. # Non pubblicare la porta 5432 sull'host in produzione. # Nginx Reverse Proxy nginx: # Versione pinnata per deploy riproducibili (http2 come direttiva, vedi app.conf). # Branch stabile corrente: la 1.27 mainline e' stata superata ad aprile 2025 e # non riceve piu' fix di sicurezza, quindi usiamo la stable 1.30. image: nginx:1.30-alpine container_name: nginx-proxy restart: unless-stopped # Ricarica periodica per far rileggere a nginx i certificati rinnovati da # certbot: nginx tiene i certificati in memoria e senza un reload servirebbe # un certificato scaduto ~90 giorni dopo la prima emissione. command: sh -c "while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g 'daemon off;'" ports: - "80:80" - "443:443" volumes: - ./nginx/conf.d:/etc/nginx/conf.d:ro - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro - certbot-webroot:/var/www/certbot:ro - certbot-certs:/etc/letsencrypt:ro - certbot-lib:/var/lib/letsencrypt:ro networks: - app-network depends_on: - blog healthcheck: test: ["CMD", "nginx", "-t"] interval: 30s timeout: 10s retries: 3 # Certbot per Let's Encrypt - Auto Renewal certbot: # Pin a una versione precisa (coerente con la policy "no :latest in produzione"): # una release certbot con breaking change romperebbe silenziosamente l'auto-renewal. image: certbot/certbot:v5.4.0 container_name: certbot volumes: - certbot-webroot:/var/www/certbot:rw - certbot-certs:/etc/letsencrypt:rw - certbot-lib:/var/lib/letsencrypt:rw - certbot-logs:/var/log/letsencrypt:rw - ./certbot-entrypoint.sh:/entrypoint.sh:ro entrypoint: /entrypoint.sh networks: - app-network networks: app-network: driver: bridge volumes: postgresql-data: certbot-webroot: certbot-certs: certbot-lib: certbot-logs: