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.
6.2 KiB
6.2 KiB
?? WORKFLOW: Sviluppo ? Gitea ? Unraid
Flusso di Lavoro Completo
PC Sviluppo ? Git Commit ? Gitea Push ? Unraid Pull ? Docker Deploy
?? STEP BY STEP
1. Sviluppo Locale (PC)
# Lavora sul codice
code .
# Test locale
dotnet run
# Oppure
docker-compose up
# Verifica funzionamento
http://localhost:8080
2. Commit e Push su Gitea
# Status modifiche
git status
# Stage files
git add .
# Commit
git commit -m "Feature: Descrizione modifiche"
# Push su Gitea
git push origin main
3. Deploy su Unraid
Opzione A: Automatico (Portainer Webhook)
Setup iniziale (una volta):
1. Portainer ? Stacks ? tradingbot ? Webhooks
2. Create webhook
3. Copy URL
4. Gitea ? Settings ? Webhooks ? Add Webhook
5. Paste URL
6. Trigger: Push events
7. Save
Uso: Ogni push su Gitea ? Auto-deploy su Unraid!
Opzione B: Manuale (SSH)
# SSH su Unraid
ssh root@[UNRAID-IP]
# Vai nella directory
cd /mnt/user/appdata/tradingbot/TradingBot
# Pull modifiche
git pull origin main
# Rebuild e restart
docker-compose down
docker-compose build
docker-compose up -d
Opzione C: Script Automatico
Crea /root/scripts/deploy-tradingbot.sh:
#!/bin/bash
cd /mnt/user/appdata/tradingbot/TradingBot
echo "?? Pulling latest changes..."
git pull origin main
if [ $? -eq 0 ]; then
echo "?? Rebuilding container..."
docker-compose down
docker-compose build
docker-compose up -d
echo "? Deployment completed!"
else
echo "? Git pull failed!"
exit 1
fi
Usa:
chmod +x /root/scripts/deploy-tradingbot.sh
/root/scripts/deploy-tradingbot.sh
?? WORKFLOW GIORNALIERO
Mattina - Modifiche
# PC
git pull origin main # Sync
code . # Sviluppa
dotnet run # Test
Pomeriggio - Deploy
# PC
git add .
git commit -m "Daily improvements"
git push origin main
# Unraid (se non auto-deploy)
ssh root@unraid
/root/scripts/deploy-tradingbot.sh
Sera - Monitoring
# Check logs
docker logs tradingbot -f
# Check stats
docker stats tradingbot
# Backup (opzionale)
/root/scripts/backup-tradingbot.sh
?? BRANCHING STRATEGY
Main Branch (Production)
# Solo codice stabile e testato
git checkout main
git pull origin main
Development Branch
# Crea branch per nuove feature
git checkout -b feature/nome-feature
# Sviluppa e testa
# ...
# Merge in main quando pronto
git checkout main
git merge feature/nome-feature
git push origin main
Hotfix
# Per fix urgenti
git checkout -b hotfix/descrizione
# Fix
git checkout main
git merge hotfix/descrizione
git push origin main
?? RELEASE VERSIONING
Tagging
# Tag versione
git tag -a v1.0.0 -m "Release v1.0.0"
git push origin v1.0.0
# Build con tag
docker build -t tradingbot:v1.0.0 .
docker tag tradingbot:v1.0.0 tradingbot:latest
Rollback
# Lista tags
git tag -l
# Checkout versione precedente
git checkout v0.9.0
# Deploy versione specifica
docker-compose down
docker-compose build
docker-compose up -d
?? BEST PRACTICES
1. Non Committare Secrets
# .gitignore già configurato per:
appsettings.Development.json
*.env
*.key
2. Test Prima di Push
# Sempre test locale prima
dotnet build
dotnet test # Se hai tests
docker-compose up # Test container
3. Commit Messages Descrittivi
# ? Buoni
git commit -m "Fix: Sidebar toggle button not working"
git commit -m "Feature: Add Docker support"
git commit -m "Docs: Update deployment guide"
# ? Cattivi
git commit -m "fix"
git commit -m "update"
git commit -m "changes"
4. Pull Prima di Push
# Sempre sync prima
git pull origin main
# Risolvi conflitti se presenti
git push origin main
?? TROUBLESHOOTING
Conflitto Git
# Pull con conflitti
git pull origin main
# Risolvi manualmente i file in conflitto
# Cerca <<<<<<< HEAD
# Dopo risolto
git add .
git commit -m "Resolve merge conflicts"
git push origin main
Push Rifiutato
# Se remote è avanti
git pull --rebase origin main
git push origin main
Reset Completo (ATTENZIONE!)
# Solo in caso di emergenza
git fetch origin
git reset --hard origin/main
?? MONITORING WORKFLOW
Check Health
# Local
curl http://localhost:8080/health
# Unraid
curl http://[UNRAID-IP]:8080/health
View Logs
# Real-time
docker logs -f tradingbot
# Last 100 lines
docker logs --tail 100 tradingbot
# Since timestamp
docker logs --since 2024-12-12T10:00:00 tradingbot
Resource Usage
# Stats
docker stats tradingbot
# Processes
docker top tradingbot
?? CHECKLIST COMPLETO
Pre-Development
- Git repository synced (
git pull) - Branch corretto (
git branch) - Dependencies updated (
dotnet restore)
Development
- Codice scritto e testato
- Build successful (
dotnet build) - Test locale OK (
dotnet run) - Docker test OK (
docker-compose up)
Pre-Commit
- Codice formattato
- No secrets committati
- .gitignore aggiornato
- README aggiornato se necessario
Commit & Push
git statusverificato- Commit message descrittivo
- Push successful
- Verifica su Gitea web UI
Deployment
- Pull su Unraid OK
- Docker build successful
- Container running
- Health check passing
- WebUI accessibile
Post-Deployment
- Logs verificati
- Nessun errore critico
- Funzionalità testate
- Performance OK
?? MAINTENANCE
Giornaliero
- Check logs per errori
- Verifica health endpoint
- Monitor resource usage
Settimanale
- Git pull updates
- Review commits
- Check disk space
Mensile
- Full backup
- Review performance metrics
- Update dependencies
- Security audit
?? COMANDI RAPIDI
# Development
git status
git add .
git commit -m "message"
git push origin main
# Local Test
dotnet run
docker-compose up -d
# Unraid Deploy
ssh root@unraid "/root/scripts/deploy-tradingbot.sh"
# Check Status
docker ps | grep tradingbot
docker logs tradingbot --tail 50
# Restart
docker restart tradingbot
# Update
git pull && docker-compose up -d --build
?? Workflow pronto! Sviluppo ? Gitea ? Unraid automatizzato!