Initial commit: monorepo Match Live TV.
Rails API, app Flutter, infrastruttura Docker/MediaMTX, sito marketing e documentazione di deploy. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
7
infra/.env.example
Normal file
7
infra/.env.example
Normal file
@@ -0,0 +1,7 @@
|
||||
POSTGRES_PASSWORD=matchlivetv_dev
|
||||
SECRET_KEY_BASE=change_me_to_a_long_random_string_in_production
|
||||
MEDIAMTX_WEBHOOK_SECRET=mediamtx_webhook_dev_secret
|
||||
JWT_SECRET=matchlivetv_jwt_dev_secret_change_in_prod
|
||||
YOUTUBE_CLIENT_ID=
|
||||
YOUTUBE_CLIENT_SECRET=
|
||||
YOUTUBE_REDIRECT_URI=http://localhost:3000/api/v1/youtube/callback
|
||||
30
infra/.env.production.example
Normal file
30
infra/.env.production.example
Normal file
@@ -0,0 +1,30 @@
|
||||
# Copia come .env sul server: cp .env.production.example .env
|
||||
# Genera secret: openssl rand -hex 32
|
||||
|
||||
POSTGRES_PASSWORD=CHANGE_ME_STRONG_PASSWORD
|
||||
SECRET_KEY_BASE=CHANGE_ME_openssl_rand_hex_64
|
||||
JWT_SECRET=CHANGE_ME_openssl_rand_hex_32
|
||||
MEDIAMTX_WEBHOOK_SECRET=CHANGE_ME_openssl_rand_hex_32
|
||||
|
||||
# RTMP pubblico per telefoni (IP WAN o DDNS + porta 1935)
|
||||
MEDIAMTX_RTMP_URL=rtmp://YOUR_PUBLIC_IP_OR_DOMAIN:1935
|
||||
|
||||
# Dominio pubblico (Nginx Proxy Manager → Rails :3000)
|
||||
APP_PUBLIC_URL=https://matchlivetv.yourdomain.com
|
||||
HLS_PUBLIC_URL=https://matchlivetv.yourdomain.com/hls
|
||||
|
||||
CORS_ORIGINS=https://matchlivetv.yourdomain.com
|
||||
ALLOWED_HOSTS=matchlivetv.yourdomain.com,192.168.1.146
|
||||
YOUTUBE_REDIRECT_URI=https://matchlivetv.yourdomain.com/api/v1/youtube/callback
|
||||
|
||||
# YouTube OAuth (opzionale)
|
||||
YOUTUBE_CLIENT_ID=
|
||||
YOUTUBE_CLIENT_SECRET=
|
||||
|
||||
# Stripe (abbonamento Premium squadra)
|
||||
STRIPE_SECRET_KEY=
|
||||
STRIPE_WEBHOOK_SECRET=
|
||||
STRIPE_PREMIUM_LIGHT_PRICE_ID=
|
||||
STRIPE_PREMIUM_FULL_PRICE_ID=
|
||||
|
||||
RAILS_LOG_LEVEL=info
|
||||
117
infra/docker-compose.prod.yml
Normal file
117
infra/docker-compose.prod.yml
Normal file
@@ -0,0 +1,117 @@
|
||||
# Produzione — Match Live TV
|
||||
# Uso: docker compose -f docker-compose.prod.yml --env-file .env up -d --build
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16-alpine
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
POSTGRES_DB: matchlivetv
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
redis:
|
||||
image: redis:7-alpine
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 5
|
||||
|
||||
mediamtx:
|
||||
image: bluenviron/mediamtx:latest
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "1935:1935" # RTMP ingest (telefoni) — esporre su router
|
||||
- "8888:8888" # HLS playback (opzionale)
|
||||
volumes:
|
||||
- ./mediamtx.yml:/mediamtx.yml:ro
|
||||
- ./slates:/slates:ro
|
||||
- recordings:/recordings
|
||||
command: /mediamtx.yml
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "-q", "--spider", "http://127.0.0.1:9997/v3/config/global/get"]
|
||||
interval: 15s
|
||||
timeout: 5s
|
||||
retries: 3
|
||||
|
||||
rails:
|
||||
build:
|
||||
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"
|
||||
environment:
|
||||
RAILS_ENV: production
|
||||
DATABASE_URL: postgresql://postgres:${POSTGRES_PASSWORD}@postgres:5432/matchlivetv
|
||||
REDIS_URL: redis://redis:6379/0
|
||||
MEDIAMTX_API_URL: http://mediamtx:9997
|
||||
MEDIAMTX_RTMP_URL: ${MEDIAMTX_RTMP_URL:-rtmp://mediamtx:1935}
|
||||
MEDIAMTX_WEBHOOK_SECRET: ${MEDIAMTX_WEBHOOK_SECRET}
|
||||
RAILS_WEBHOOK_URL: http://rails:3000
|
||||
SECRET_KEY_BASE: ${SECRET_KEY_BASE}
|
||||
JWT_SECRET: ${JWT_SECRET}
|
||||
CORS_ORIGINS: ${CORS_ORIGINS:-*}
|
||||
ALLOWED_HOSTS: ${ALLOWED_HOSTS:-*}
|
||||
YOUTUBE_CLIENT_ID: ${YOUTUBE_CLIENT_ID:-}
|
||||
YOUTUBE_CLIENT_SECRET: ${YOUTUBE_CLIENT_SECRET:-}
|
||||
YOUTUBE_REDIRECT_URI: ${YOUTUBE_REDIRECT_URI:-}
|
||||
HLS_PUBLIC_URL: ${HLS_PUBLIC_URL:-http://localhost:8888}
|
||||
APP_PUBLIC_URL: ${APP_PUBLIC_URL:-http://localhost:3000}
|
||||
RAILS_LOG_TO_STDOUT: "true"
|
||||
RAILS_LOG_LEVEL: ${RAILS_LOG_LEVEL:-info}
|
||||
ports:
|
||||
- "3000:3000" # Solo LAN — NPM proxy HTTPS
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
mediamtx:
|
||||
condition: service_started
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://127.0.0.1:3000/up"]
|
||||
interval: 15s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
start_period: 90s
|
||||
|
||||
sidekiq:
|
||||
build:
|
||||
context: ../backend
|
||||
dockerfile: Dockerfile
|
||||
restart: unless-stopped
|
||||
command: bundle exec sidekiq -C config/sidekiq.yml -e production
|
||||
environment:
|
||||
RAILS_ENV: production
|
||||
DATABASE_URL: postgresql://postgres:${POSTGRES_PASSWORD}@postgres:5432/matchlivetv
|
||||
REDIS_URL: redis://redis:6379/0
|
||||
MEDIAMTX_API_URL: http://mediamtx:9997
|
||||
MEDIAMTX_WEBHOOK_SECRET: ${MEDIAMTX_WEBHOOK_SECRET}
|
||||
RAILS_WEBHOOK_URL: http://rails:3000
|
||||
SECRET_KEY_BASE: ${SECRET_KEY_BASE}
|
||||
JWT_SECRET: ${JWT_SECRET}
|
||||
YOUTUBE_CLIENT_ID: ${YOUTUBE_CLIENT_ID:-}
|
||||
YOUTUBE_CLIENT_SECRET: ${YOUTUBE_CLIENT_SECRET:-}
|
||||
HLS_PUBLIC_URL: ${HLS_PUBLIC_URL:-http://localhost:8888}
|
||||
APP_PUBLIC_URL: ${APP_PUBLIC_URL:-http://localhost:3000}
|
||||
depends_on:
|
||||
rails:
|
||||
condition: service_healthy
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
redis_data:
|
||||
recordings:
|
||||
119
infra/docker-compose.yml
Normal file
119
infra/docker-compose.yml
Normal file
@@ -0,0 +1,119 @@
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16-alpine
|
||||
environment:
|
||||
POSTGRES_DB: matchlivetv
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-matchlivetv_dev}
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
ports:
|
||||
- "5432:5432"
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
redis:
|
||||
image: redis:7-alpine
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
ports:
|
||||
- "6379:6379"
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 5
|
||||
|
||||
mediamtx:
|
||||
image: bluenviron/mediamtx:latest
|
||||
ports:
|
||||
- "1935:1935"
|
||||
- "8554:8554"
|
||||
- "8888:8888"
|
||||
- "9997:9997"
|
||||
volumes:
|
||||
- ./mediamtx.yml:/mediamtx.yml:ro
|
||||
- ./slates:/slates:ro
|
||||
- recordings:/recordings
|
||||
command: /mediamtx.yml
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "-q", "--spider", "http://localhost:9997/v3/config/global/get"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 3
|
||||
|
||||
rails:
|
||||
build:
|
||||
context: ../backend
|
||||
dockerfile: Dockerfile
|
||||
command: bash -c "bundle exec rails db:prepare db:seed && bundle exec rails server -b 0.0.0.0 -p 3000"
|
||||
environment:
|
||||
RAILS_ENV: development
|
||||
DATABASE_URL: postgresql://postgres:${POSTGRES_PASSWORD:-matchlivetv_dev}@postgres:5432/matchlivetv
|
||||
REDIS_URL: redis://redis:6379/0
|
||||
MEDIAMTX_API_URL: http://mediamtx:9997
|
||||
MEDIAMTX_RTMP_URL: rtmp://mediamtx:1935
|
||||
MEDIAMTX_WEBHOOK_SECRET: ${MEDIAMTX_WEBHOOK_SECRET:-mediamtx_webhook_dev_secret}
|
||||
RAILS_WEBHOOK_URL: http://rails:3000
|
||||
SECRET_KEY_BASE: ${SECRET_KEY_BASE:-dev_secret_key_base_change_me_32chars_min}
|
||||
JWT_SECRET: ${JWT_SECRET:-matchlivetv_jwt_dev_secret}
|
||||
YOUTUBE_CLIENT_ID: ${YOUTUBE_CLIENT_ID:-}
|
||||
YOUTUBE_CLIENT_SECRET: ${YOUTUBE_CLIENT_SECRET:-}
|
||||
YOUTUBE_REDIRECT_URI: ${YOUTUBE_REDIRECT_URI:-http://localhost:3000/api/v1/youtube/callback}
|
||||
RAILS_LOG_TO_STDOUT: "true"
|
||||
ports:
|
||||
- "3000:3000"
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
mediamtx:
|
||||
condition: service_started
|
||||
volumes:
|
||||
- ../backend:/app
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:3000/up"]
|
||||
interval: 15s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
start_period: 60s
|
||||
|
||||
sidekiq:
|
||||
build:
|
||||
context: ../backend
|
||||
dockerfile: Dockerfile
|
||||
command: bundle exec sidekiq -C config/sidekiq.yml
|
||||
environment:
|
||||
RAILS_ENV: development
|
||||
DATABASE_URL: postgresql://postgres:${POSTGRES_PASSWORD:-matchlivetv_dev}@postgres:5432/matchlivetv
|
||||
REDIS_URL: redis://redis:6379/0
|
||||
MEDIAMTX_API_URL: http://mediamtx:9997
|
||||
MEDIAMTX_WEBHOOK_SECRET: ${MEDIAMTX_WEBHOOK_SECRET:-mediamtx_webhook_dev_secret}
|
||||
RAILS_WEBHOOK_URL: http://rails:3000
|
||||
SECRET_KEY_BASE: ${SECRET_KEY_BASE:-dev_secret_key_base_change_me_32chars_min}
|
||||
JWT_SECRET: ${JWT_SECRET:-matchlivetv_jwt_dev_secret}
|
||||
YOUTUBE_CLIENT_ID: ${YOUTUBE_CLIENT_ID:-}
|
||||
YOUTUBE_CLIENT_SECRET: ${YOUTUBE_CLIENT_SECRET:-}
|
||||
depends_on:
|
||||
rails:
|
||||
condition: service_healthy
|
||||
volumes:
|
||||
- ../backend:/app
|
||||
|
||||
nginx:
|
||||
image: nginx:alpine
|
||||
ports:
|
||||
- "8080:80"
|
||||
volumes:
|
||||
- ./nginx.conf:/etc/nginx/nginx.conf:ro
|
||||
depends_on:
|
||||
- rails
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
redis_data:
|
||||
recordings:
|
||||
45
infra/mediamtx.yml
Normal file
45
infra/mediamtx.yml
Normal file
@@ -0,0 +1,45 @@
|
||||
# MediaMTX configuration for Match Live TV
|
||||
# Docs: https://mediamtx.org/docs/references/configuration-file
|
||||
|
||||
logLevel: info
|
||||
|
||||
# Allow API from Docker network (Rails container)
|
||||
authInternalUsers:
|
||||
- user: any
|
||||
pass:
|
||||
ips: []
|
||||
permissions:
|
||||
- action: api
|
||||
- action: metrics
|
||||
- action: pprof
|
||||
- action: publish
|
||||
- action: read
|
||||
|
||||
api: yes
|
||||
apiAddress: :9997
|
||||
rtmp: yes
|
||||
rtmpAddress: :1935
|
||||
hls: yes
|
||||
hlsAddress: :8888
|
||||
hlsVariant: mpegts
|
||||
|
||||
pathDefaults:
|
||||
source: publisher
|
||||
overridePublisher: yes
|
||||
record: yes
|
||||
recordPath: /recordings/%path/%Y-%m-%d_%H-%M-%S
|
||||
recordSegmentDuration: 60s
|
||||
recordDeleteAfter: 48h
|
||||
|
||||
paths:
|
||||
# Dynamic session paths are created via MediaMTX HTTP API from Rails.
|
||||
# Template for reference (Rails sets alwaysAvailable per path):
|
||||
# match_{uuid}:
|
||||
# alwaysAvailable: true
|
||||
# alwaysAvailableFile: /slates/offline.mp4
|
||||
# alwaysAvailableTracks:
|
||||
# - codec: H264
|
||||
# - codec: MPEG4Audio
|
||||
# sampleRate: 48000
|
||||
# channelCount: 2
|
||||
all_others:
|
||||
34
infra/nginx.conf
Normal file
34
infra/nginx.conf
Normal file
@@ -0,0 +1,34 @@
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
http {
|
||||
upstream rails {
|
||||
server rails:3000;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
|
||||
client_max_body_size 10M;
|
||||
|
||||
location /cable {
|
||||
proxy_pass http://rails;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_read_timeout 86400;
|
||||
}
|
||||
|
||||
location / {
|
||||
proxy_pass http://rails;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
infra/scripts/generate_slate.sh
Executable file
12
infra/scripts/generate_slate.sh
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
# Generate offline slate MP4 for MediaMTX alwaysAvailable
|
||||
set -e
|
||||
OUT_DIR="$(dirname "$0")/../slates"
|
||||
OUT="$OUT_DIR/offline.mp4"
|
||||
mkdir -p "$OUT_DIR"
|
||||
docker run --rm -v "$OUT_DIR:/out" linuxserver/ffmpeg:latest \
|
||||
-f lavfi -i color=c=0x1a1a1a:s=1280x720:r=30 \
|
||||
-f lavfi -i sine=frequency=440:sample_rate=48000 \
|
||||
-t 30 -c:v libx264 -pix_fmt yuv420p -g 30 -preset fast \
|
||||
-c:a aac -b:a 128k -y /out/offline.mp4
|
||||
echo "Created $OUT"
|
||||
11
infra/slates/README.md
Normal file
11
infra/slates/README.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# Slate video (offline)
|
||||
|
||||
Place `offline.mp4` here — H.264 + AAC, 1280x720, 30fps, 48kHz stereo.
|
||||
Must match phone encoder settings for seamless `alwaysAvailable` merge.
|
||||
|
||||
Generate a test slate with ffmpeg:
|
||||
|
||||
```bash
|
||||
ffmpeg -f lavfi -i color=c=0x1a1a1a:s=1280x720:r=30 -f lavfi -i sine=frequency=440:sample_rate=48000 \
|
||||
-t 10 -c:v libx264 -pix_fmt yuv420p -g 30 -c:a aac -b:a 128k offline.mp4
|
||||
```
|
||||
BIN
infra/slates/offline.mp4
Normal file
BIN
infra/slates/offline.mp4
Normal file
Binary file not shown.
Reference in New Issue
Block a user