Aggiunti Dockerfile multi-stage, .dockerignore e docker-compose.yml per deployment containerizzato (con healthcheck, volumi persistenti, limiti risorse). Script di build per Linux/Mac e Windows. In Program.cs aggiunto endpoint /health e health checks per orchestrazione. Documentazione estesa: guide Unraid, quickstart Docker, workflow Git/DevOps, best practices su sicurezza, backup, monitoring. Progetto ora pronto per deploy e gestione professionale in ambienti Docker/Unraid.
9.6 KiB
9.6 KiB
?? DEPLOYMENT GUIDE - Unraid + Gitea + Docker
Guida completa per deployare TradingBot su Unraid usando Gitea come sistema di controllo versione.
?? PREREQUISITI
Su Unraid
- ? Docker installato (Community Applications)
- ? Gitea installato e configurato
- ? Accesso SSH abilitato
- ? Portainer installato (opzionale ma consigliato)
Sul PC di Sviluppo
- ? Git installato
- ? Accesso al server Unraid
- ? Repository Gitea configurato
?? STEP 1: Configurazione Gitea
1.1 Crea Repository su Gitea
# Accedi a Gitea (esempio)
http://192.168.30.23:3000
# Crea nuovo repository
Nome: TradingBot
Descrizione: Automated Crypto Trading Bot
Privato: ? (consigliato)
1.2 Configura Git Remote (già fatto)
cd /path/to/TradingBot
# Verifica remote (dovresti già averlo)
git remote -v
# Output:
# origin https://192.168.30.23/Alby96/Encelado (fetch)
# origin https://192.168.30.23/Alby96/Encelado (push)
# Se non configurato:
git remote add origin https://192.168.30.23/Alby96/Encelado
1.3 Push del Codice
# Commit delle modifiche Docker
git add Dockerfile docker-compose.yml .dockerignore
git add build-docker.sh build-docker.bat
git add UNRAID_DEPLOYMENT.md
git commit -m "Add Docker support and Unraid deployment"
# Push su Gitea
git push origin main
?? STEP 2: Deployment su Unraid
Metodo A: Via Portainer (CONSIGLIATO)
2.1 Accedi a Portainer
http://[UNRAID-IP]:9000
2.2 Crea Stack
- Stacks ? Add stack
- Name:
tradingbot - Build method:
Git Repository - Repository URL:
https://192.168.30.23/Alby96/Encelado - Repository reference:
refs/heads/main - Compose path:
TradingBot/docker-compose.yml - Authentication:
- Username:
Alby96 - Personal access token: (crea su Gitea)
- Username:
2.3 Environment Variables (opzionali)
TZ=Europe/Rome
ASPNETCORE_ENVIRONMENT=Production
2.4 Deploy
Click Deploy the stack
Metodo B: Via SSH + Docker Compose
2.1 Connettiti a Unraid via SSH
ssh root@[UNRAID-IP]
2.2 Crea Directory Progetto
# Vai nella directory appropriata
cd /mnt/user/appdata/
# Crea directory per TradingBot
mkdir -p tradingbot
cd tradingbot
2.3 Clone Repository da Gitea
# Clone del repository
git clone https://192.168.30.23/Alby96/Encelado.git .
# Entra nella directory del progetto
cd TradingBot
2.4 Build e Run
# Build immagine Docker
docker-compose build
# Avvia container
docker-compose up -d
# Verifica logs
docker-compose logs -f
Metodo C: Via Unraid Docker Template
2.1 Crea Template Personalizzato
Crea file: /boot/config/plugins/dockerMan/templates-user/my-TradingBot.xml
<?xml version="1.0"?>
<Container version="2">
<Name>TradingBot</Name>
<Repository>tradingbot:latest</Repository>
<Registry>https://192.168.30.23:5000/</Registry>
<Network>bridge</Network>
<MyIP/>
<Shell>sh</Shell>
<Privileged>false</Privileged>
<Support>https://192.168.30.23/Alby96/Encelado</Support>
<Project>https://192.168.30.23/Alby96/Encelado</Project>
<Overview>Automated Crypto Trading Bot con strategie personalizzabili</Overview>
<Category>Tools:</Category>
<WebUI>http://[IP]:[PORT:8080]</WebUI>
<TemplateURL/>
<Icon>https://raw.githubusercontent.com/docker-library/docs/master/dotnet/logo.png</Icon>
<ExtraParams/>
<PostArgs/>
<CPUset/>
<DateInstalled>1234567890</DateInstalled>
<DonateText/>
<DonateLink/>
<Requires/>
<Config Name="WebUI Port" Target="8080" Default="8080" Mode="tcp" Description="Port per accedere alla WebUI" Type="Port" Display="always" Required="true" Mask="false">8080</Config>
<Config Name="Data Volume" Target="/app/data" Default="/mnt/user/appdata/tradingbot/data" Mode="rw" Description="Volume per dati persistenti" Type="Path" Display="always" Required="true" Mask="false">/mnt/user/appdata/tradingbot/data</Config>
<Config Name="Timezone" Target="TZ" Default="Europe/Rome" Mode="" Description="Timezone" Type="Variable" Display="always" Required="false" Mask="false">Europe/Rome</Config>
</Container>
2.2 Usa Template da Unraid UI
- Docker ? Add Container
- Select:
TradingBot - Configure ports and volumes
- Apply
?? STEP 3: Aggiornamenti Automatici
3.1 Setup Webhook su Gitea (opzionale)
Su Gitea:
Settings ? Webhooks ? Add Webhook
Payload URL: http://[UNRAID-IP]:9000/api/webhooks/[webhook-id]
Content type: application/json
Events: Push events
Su Portainer:
Stacks ? tradingbot ? Webhooks ? Create webhook
Copia URL generato
3.2 Script di Aggiornamento Manuale
#!/bin/bash
# update-tradingbot.sh
cd /mnt/user/appdata/tradingbot/TradingBot
# Pull latest changes
git pull origin main
# Rebuild
docker-compose down
docker-compose build
docker-compose up -d
echo "? TradingBot aggiornato!"
Salva come: /root/scripts/update-tradingbot.sh
chmod +x /root/scripts/update-tradingbot.sh
?? STEP 4: Monitoraggio e Gestione
4.1 Verifica Status Container
# Via SSH
docker ps | grep tradingbot
# Logs
docker logs tradingbot -f
# Stats
docker stats tradingbot
4.2 Accesso WebUI
http://[UNRAID-IP]:8080
4.3 Health Check
curl http://[UNRAID-IP]:8080/health
?? STEP 5: Configurazione Avanzata
5.1 Reverse Proxy (opzionale)
Se usi Nginx Proxy Manager o Traefik:
docker-compose.yml aggiornato:
services:
tradingbot:
# ... altre configurazioni
labels:
- "traefik.enable=true"
- "traefik.http.routers.tradingbot.rule=Host(`trading.tuodominio.com`)"
- "traefik.http.services.tradingbot.loadbalancer.server.port=8080"
networks:
- traefik_proxy
- tradingbot-network
networks:
traefik_proxy:
external: true
5.2 Backup Automatico
Script backup: /root/scripts/backup-tradingbot.sh
#!/bin/bash
BACKUP_DIR="/mnt/user/backups/tradingbot"
DATE=$(date +%Y%m%d_%H%M%S)
mkdir -p $BACKUP_DIR
# Backup volume dati
docker run --rm \
-v tradingbot_tradingbot-data:/data \
-v $BACKUP_DIR:/backup \
alpine tar czf /backup/tradingbot-data-$DATE.tar.gz -C /data .
echo "? Backup completato: tradingbot-data-$DATE.tar.gz"
# Mantieni solo ultimi 7 backup
find $BACKUP_DIR -name "tradingbot-data-*.tar.gz" -mtime +7 -delete
Aggiungi a crontab:
crontab -e
# Backup giornaliero alle 3 AM
0 3 * * * /root/scripts/backup-tradingbot.sh
?? TROUBLESHOOTING
Container non si avvia
# Check logs
docker logs tradingbot
# Check network
docker network ls
docker network inspect tradingbot_tradingbot-network
# Rebuild da zero
docker-compose down -v
docker-compose build --no-cache
docker-compose up -d
Problemi di permessi
# Fix ownership
docker exec tradingbot chown -R tradingbot:tradingbot /app/data
Porta già in uso
# Trova processo che usa porta 8080
netstat -tulpn | grep 8080
# Cambia porta in docker-compose.yml
ports:
- "8081:8080" # Usa 8081 invece
Out of Memory
Aumenta limits in docker-compose.yml:
deploy:
resources:
limits:
memory: 2G # Da 1G a 2G
?? STEP 6: Registry Privato (opzionale)
6.1 Setup Docker Registry su Unraid
docker run -d \
-p 5000:5000 \
--restart=always \
--name registry \
-v /mnt/user/appdata/registry:/var/lib/registry \
registry:2
6.2 Build e Push
# Tag image
docker tag tradingbot:latest 192.168.30.23:5000/tradingbot:latest
# Push to registry
docker push 192.168.30.23:5000/tradingbot:latest
6.3 Deploy da Registry
# docker-compose.yml
services:
tradingbot:
image: 192.168.30.23:5000/tradingbot:latest
# ... resto configurazione
?? SECURITY BEST PRACTICES
1. Non esporre porte pubblicamente
# Usa solo rete interna Unraid
# Accesso via VPN o Wireguard
2. SSL/TLS
# Usa reverse proxy con certificati SSL
# Let's Encrypt via Nginx Proxy Manager
3. Credenziali
# Non committare secrets in Git
# Usa Docker secrets o environment variables
4. Firewall
# Limita accesso solo a IP fidati
# Configura in Unraid Settings ? Network
?? MONITORING
Grafana + Prometheus (opzionale)
# monitoring-stack.yml
version: '3.8'
services:
prometheus:
image: prom/prometheus
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
ports:
- "9090:9090"
grafana:
image: grafana/grafana
ports:
- "3001:3000"
volumes:
- grafana-data:/var/lib/grafana
volumes:
grafana-data:
?? CHECKLIST DEPLOYMENT
Pre-Deployment
- Codice committed su Gitea
- Dockerfile testato localmente
- docker-compose.yml configurato
- .dockerignore presente
- Environment variables definite
Deployment
- Repository clonato su Unraid
- Docker image built
- Container avviato correttamente
- WebUI accessibile
- Health check passing
Post-Deployment
- Logs verificati (no errori)
- Dati persistono dopo restart
- Backup configurato
- Monitoring attivo
- Documentazione aggiornata
?? COMANDI UTILI
# Build
./build-docker.sh [tag]
# Start
docker-compose up -d
# Stop
docker-compose down
# Logs
docker-compose logs -f
# Restart
docker-compose restart
# Update
git pull && docker-compose up -d --build
# Clean
docker-compose down -v
docker system prune -a
?? RISORSE
- Unraid Docs: https://docs.unraid.net/
- Docker Docs: https://docs.docker.com/
- Gitea Docs: https://docs.gitea.io/
- Portainer Docs: https://docs.portainer.io/
?? Deployment completato! Il tuo TradingBot è ora in produzione su Unraid!