rivisto completamente il deploy
This commit is contained in:
8 files changed
+481
-87
No files matched your search
+63
-17
@@ -1,32 +1,76 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
# Java Web Application
|
||||
app:
|
||||
image: your-java-app:latest
|
||||
container_name: java-app
|
||||
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
|
||||
- SERVER_PORT=8080
|
||||
- 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:
|
||||
# - "8080:8080" # Non esporre direttamente, usa nginx
|
||||
volumes:
|
||||
- app-data:/app/data
|
||||
# - 127.0.0.1:8080:8080
|
||||
depends_on:
|
||||
postgresql:
|
||||
condition: service_healthy
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:8080/actuator/health"]
|
||||
# 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: 3
|
||||
start_period: 40s
|
||||
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:
|
||||
image: nginx:alpine
|
||||
# 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"
|
||||
@@ -39,7 +83,7 @@ services:
|
||||
networks:
|
||||
- app-network
|
||||
depends_on:
|
||||
- app
|
||||
- blog
|
||||
healthcheck:
|
||||
test: ["CMD", "nginx", "-t"]
|
||||
interval: 30s
|
||||
@@ -48,7 +92,9 @@ services:
|
||||
|
||||
# Certbot per Let's Encrypt - Auto Renewal
|
||||
certbot:
|
||||
image: certbot/certbot:latest
|
||||
# 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
|
||||
@@ -65,7 +111,7 @@ networks:
|
||||
driver: bridge
|
||||
|
||||
volumes:
|
||||
app-data:
|
||||
postgresql-data:
|
||||
certbot-webroot:
|
||||
certbot-certs:
|
||||
certbot-lib:
|
||||
|
||||
Reference in new issue
Block a user