# ?? 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 ```sh # 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) ```sh 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 ```sh # 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 1. **Stacks** ? **Add stack** 2. **Name**: `tradingbot` 3. **Build method**: `Git Repository` 4. **Repository URL**: `https://192.168.30.23/Alby96/Encelado` 5. **Repository reference**: `refs/heads/main` 6. **Compose path**: `TradingBot/docker-compose.yml` 7. **Authentication**: - Username: `Alby96` - Personal access token: (crea su Gitea) #### 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 ```sh ssh root@[UNRAID-IP] ``` #### 2.2 Crea Directory Progetto ```sh # Vai nella directory appropriata cd /mnt/user/appdata/ # Crea directory per TradingBot mkdir -p tradingbot cd tradingbot ``` #### 2.3 Clone Repository da Gitea ```sh # 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 ```sh # 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 TradingBot tradingbot:latest https://192.168.30.23:5000/ bridge sh false https://192.168.30.23/Alby96/Encelado https://192.168.30.23/Alby96/Encelado Automated Crypto Trading Bot con strategie personalizzabili Tools: http://[IP]:[PORT:8080] https://raw.githubusercontent.com/docker-library/docs/master/dotnet/logo.png 1234567890 8080 /mnt/user/appdata/tradingbot/data Europe/Rome ``` #### 2.2 Usa Template da Unraid UI 1. Docker ? Add Container 2. Select: `TradingBot` 3. Configure ports and volumes 4. 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 ```sh #!/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` ```sh chmod +x /root/scripts/update-tradingbot.sh ``` --- ## ?? STEP 4: Monitoraggio e Gestione ### 4.1 Verifica Status Container ```sh # 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 ```sh 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: ```yaml 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` ```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: ```sh crontab -e # Backup giornaliero alle 3 AM 0 3 * * * /root/scripts/backup-tradingbot.sh ``` --- ## ?? TROUBLESHOOTING ### Container non si avvia ```sh # 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 ```sh # Fix ownership docker exec tradingbot chown -R tradingbot:tradingbot /app/data ``` ### Porta già in uso ```sh # 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: ```yaml deploy: resources: limits: memory: 2G # Da 1G a 2G ``` --- ## ?? STEP 6: Registry Privato (opzionale) ### 6.1 Setup Docker Registry su Unraid ```sh 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 ```sh # 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 ```yaml # docker-compose.yml services: tradingbot: image: 192.168.30.23:5000/tradingbot:latest # ... resto configurazione ``` --- ## ?? SECURITY BEST PRACTICES ### 1. Non esporre porte pubblicamente ```sh # Usa solo rete interna Unraid # Accesso via VPN o Wireguard ``` ### 2. SSL/TLS ```sh # Usa reverse proxy con certificati SSL # Let's Encrypt via Nginx Proxy Manager ``` ### 3. Credenziali ```sh # Non committare secrets in Git # Usa Docker secrets o environment variables ``` ### 4. Firewall ```sh # Limita accesso solo a IP fidati # Configura in Unraid Settings ? Network ``` --- ## ?? MONITORING ### Grafana + Prometheus (opzionale) ```yaml # 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 ```sh # 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!**