Aggiunge proxy edge con pagina di cortesia e rilascio a downtime minimo.

NPM punta a nginx locale su :3000 che resta attivo durante il restart Rails; nuovo script release_production.sh esegue migrate, build e deploy in ordine.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-13 09:31:36 +02:00
parent 208664848e
commit 949a0a01fb
6 changed files with 316 additions and 21 deletions

View File

@@ -52,9 +52,7 @@ services:
context: ../backend
dockerfile: Dockerfile
restart: unless-stopped
command: >
bash -c "bundle exec rails db:prepare &&
bundle exec rails server -b 0.0.0.0 -p 3000 -e production"
command: bundle exec rails server -b 0.0.0.0 -p 3000 -e production
environment:
RAILS_ENV: production
DATABASE_URL: postgresql://postgres:${POSTGRES_PASSWORD}@postgres:5432/matchlivetv
@@ -117,8 +115,6 @@ services:
OPS_SIDEKIQ_STALE_SECS: ${OPS_SIDEKIQ_STALE_SECS:-300}
OPS_LOG_SUBSCRIBER: ${OPS_LOG_SUBSCRIBER:-false}
SENTRY_DSN: ${SENTRY_DSN:-}
ports:
- "3000:3000" # Solo LAN — NPM proxy HTTPS
depends_on:
postgres:
condition: service_healthy
@@ -139,6 +135,20 @@ services:
retries: 10
start_period: 90s
edge:
image: nginx:alpine
restart: unless-stopped
ports:
- "3000:80" # Solo LAN — NPM proxy HTTPS (pagina cortesia se Rails è in restart)
volumes:
- ./nginx-edge/nginx.conf:/etc/nginx/nginx.conf:ro
- ./nginx-edge/maintenance.html:/usr/share/nginx/maintenance/index.html:ro
healthcheck:
test: ["CMD", "wget", "-q", "--spider", "http://127.0.0.1:80/edge-health"]
interval: 15s
timeout: 5s
retries: 3
sidekiq:
build:
context: ../backend

View File

@@ -0,0 +1,102 @@
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="refresh" content="15">
<meta name="robots" content="noindex, nofollow">
<title>Aggiornamento in corso — Match Live TV</title>
<style>
:root {
color-scheme: dark;
--bg: #0f1115;
--card: #1a1d24;
--text: #f2f4f8;
--muted: #9aa3b2;
--accent: #e53935;
--accent-soft: rgba(229, 57, 53, 0.15);
}
* { box-sizing: border-box; }
body {
margin: 0;
min-height: 100vh;
display: grid;
place-items: center;
font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
background:
radial-gradient(circle at top, rgba(229, 57, 53, 0.12), transparent 42%),
var(--bg);
color: var(--text);
padding: 24px;
}
.card {
width: min(520px, 100%);
background: var(--card);
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 16px;
padding: 32px 28px;
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
text-align: center;
}
.badge {
display: inline-block;
padding: 6px 12px;
border-radius: 999px;
background: var(--accent-soft);
color: #ffb4b0;
font-size: 0.8rem;
font-weight: 600;
letter-spacing: 0.02em;
margin-bottom: 18px;
}
h1 {
margin: 0 0 12px;
font-size: 1.6rem;
line-height: 1.25;
}
p {
margin: 0 0 14px;
color: var(--muted);
line-height: 1.55;
}
.spinner {
width: 42px;
height: 42px;
margin: 22px auto 8px;
border: 3px solid rgba(255, 255, 255, 0.12);
border-top-color: var(--accent);
border-radius: 50%;
animation: spin 0.9s linear infinite;
}
.brand {
margin-top: 22px;
font-size: 0.95rem;
font-weight: 700;
letter-spacing: 0.04em;
text-transform: uppercase;
color: #fff;
}
.hint {
margin-top: 10px;
font-size: 0.82rem;
color: #6f7888;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
</style>
</head>
<body>
<main class="card" role="main" aria-live="polite">
<div class="badge">Manutenzione rapida</div>
<h1>Stiamo aggiornando la piattaforma</h1>
<p>
Il servizio torna online tra pochi secondi. Le dirette RTMP e i replay già pubblicati
non sono interessati da questo aggiornamento.
</p>
<div class="spinner" aria-hidden="true"></div>
<p class="hint">Questa pagina si aggiorna automaticamente.</p>
<div class="brand">Match Live TV</div>
</main>
</body>
</html>

View File

@@ -0,0 +1,85 @@
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
# DNS Docker: risolve di nuovo l'IP di rails dopo ogni recreate container.
resolver 127.0.0.11 valid=5s ipv6=off;
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
server_name _;
client_max_body_size 20M;
set $rails_backend rails:3000;
location = /edge-health {
access_log off;
add_header Content-Type text/plain;
return 200 "ok\n";
}
# Health check ops: pass-through senza pagina di cortesia.
location = /up {
proxy_pass http://$rails_backend;
proxy_connect_timeout 2s;
proxy_read_timeout 10s;
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;
}
location = /up/deep {
proxy_pass http://$rails_backend;
proxy_connect_timeout 2s;
proxy_read_timeout 30s;
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;
}
location /cable {
proxy_pass http://$rails_backend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
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_read_timeout 86400;
proxy_connect_timeout 2s;
error_page 502 503 504 = @maintenance;
}
location / {
proxy_pass http://$rails_backend;
proxy_connect_timeout 2s;
proxy_read_timeout 120s;
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_page 502 503 504 = @maintenance;
}
location @maintenance {
internal;
root /usr/share/nginx/maintenance;
try_files /index.html =503;
add_header Retry-After 15 always;
add_header Cache-Control "no-store" always;
}
}
}