Files

118 lines
4.5 KiB
YAML
Raw Permalink Normal View History

2025-11-30 10:13:52 +01:00
services:
2026-10-07 21:59:49 +02:00
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}"
2025-11-30 10:13:52 +01:00
restart: unless-stopped
networks:
- app-network
environment:
2026-10-07 21:59:49 +02:00
- _JAVA_OPTIONS=-Xmx512m -Xms256m
2025-11-30 10:13:52 +01:00
- SPRING_PROFILES_ACTIVE=prod
2026-10-07 21:59:49 +02:00
- 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:
2025-11-30 10:13:52 +01:00
# ports:
2026-10-07 21:59:49 +02:00
# - 127.0.0.1:8080:8080
depends_on:
postgresql:
condition: service_healthy
2025-11-30 10:13:52 +01:00
healthcheck:
2026-10-07 21:59:49 +02:00
# 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"]
2025-11-30 10:13:52 +01:00
interval: 30s
timeout: 10s
2026-10-07 21:59:49 +02:00
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.
2025-11-30 10:13:52 +01:00
# Nginx Reverse Proxy
nginx:
2026-10-07 21:59:49 +02:00
# 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
2025-11-30 10:13:52 +01:00
container_name: nginx-proxy
restart: unless-stopped
2026-10-07 21:59:49 +02:00
# 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;'"
2025-11-30 10:13:52 +01:00
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:
2026-10-07 21:59:49 +02:00
- blog
2025-11-30 10:13:52 +01:00
healthcheck:
test: ["CMD", "nginx", "-t"]
interval: 30s
timeout: 10s
retries: 3
2025-11-30 11:50:11 +01:00
# Certbot per Let's Encrypt - Auto Renewal
2025-11-30 10:13:52 +01:00
certbot:
2026-10-07 21:59:49 +02:00
# 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
2025-11-30 10:13:52 +01:00
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
2025-11-30 11:50:11 +01:00
- ./certbot-entrypoint.sh:/entrypoint.sh:ro
entrypoint: /entrypoint.sh
2025-11-30 10:13:52 +01:00
networks:
- app-network
networks:
app-network:
driver: bridge
volumes:
2026-10-07 21:59:49 +02:00
postgresql-data:
2025-11-30 10:13:52 +01:00
certbot-webroot:
certbot-certs:
certbot-lib:
certbot-logs: