Riorganizzazione deployment, doc e publish automatico

- Spostata tutta la configurazione di deployment in /deployment (docker-compose, unraid-template, guide)
- Aggiunte e aggiornate guide dettagliate: publishing su Gitea, installazione Unraid, struttura progetto
- Migliorato target MSBuild: publish automatico su Gitea Registry da Visual Studio, log dettagliati, condizioni più robuste
- Aggiornato e ampliato .gitignore per escludere build, dati e file locali
- Rimossi file obsoleti dalla root (ora tutto in /deployment)
- Struttura più chiara, zero script esterni, documentazione completa e workflow di deploy semplificato
This commit is contained in:
2025-12-17 23:15:46 +01:00
parent 5532ad2473
commit cc34d2b57f
11 changed files with 2125 additions and 475 deletions

View File

@@ -0,0 +1,274 @@
# ??? Project Structure - TradingBot
Struttura organizzata del progetto TradingBot con separazione chiara tra codice, configurazione e deployment.
---
## ?? Root Directory
```
TradingBot/
??? ?? Components/ # Blazor Components
? ??? ?? Layout/ # Layout components
? ??? ?? Pages/ # Page components
? ??? ?? Shared/ # Shared components
??? ?? deployment/ # ?? Deployment resources
? ??? docker-compose.yml # Docker Compose configuration
? ??? unraid-template.xml # Unraid template
? ??? PUBLISHING_GUIDE.md # Publishing guide
? ??? UNRAID_INSTALL.md # Unraid installation guide
? ??? README.md # Deployment index
??? ?? Models/ # Data models
??? ?? Properties/ # Project properties
? ??? ?? PublishProfiles/ # Visual Studio publish profiles
? ? ??? Docker.pubxml # Docker publish profile
? ? ??? FolderProfile.pubxml # Folder publish profile
? ??? launchSettings.json # Launch configurations
??? ?? Services/ # Business logic services
??? ?? wwwroot/ # Static web assets
? ??? ?? css/ # Stylesheets
? ??? ?? lib/ # Client libraries
??? .dockerignore # Docker ignore patterns
??? .gitignore # Git ignore patterns
??? appsettings.json # Application settings
??? appsettings.Development.json # Development settings
??? Dockerfile # Docker multi-stage build
??? Program.cs # Application entry point
??? README.md # Project documentation
??? TradingBot.csproj # Project file with MSBuild targets
```
---
## ?? Key Directories
### `/Components`
Blazor Server components organizzati per funzionalità:
- **Layout**: `MainLayout.razor`, `NavMenu.razor`, `ReconnectModal.razor`
- **Pages**: `Dashboard.razor`, `Market.razor`, `Portfolio.razor`, `Settings.razor`, `Strategies.razor`
- **Shared**: Componenti riutilizzabili
### `/Services`
Business logic e servizi core:
- `TradingBotService.cs` - Core trading service
- `SimulatedMarketDataService.cs` - Market data provider
- `SimpleMovingAverageStrategy.cs` - Trading strategy
- `SettingsService.cs` - Settings persistence
- `TechnicalAnalysis.cs` - Technical indicators
- Interface definitions
### `/Models`
Data models e DTOs:
- `Trade.cs` - Trade execution model
- `MarketPrice.cs` - Market data snapshot
- `TradingSignal.cs` - Strategy signal
- `PortfolioStatistics.cs` - Portfolio metrics
- `AssetConfiguration.cs` - Asset settings
- Enums (SignalType, TradeType, etc.)
### `/deployment` ??
**Nuova cartella organizzata** con tutti i file di deployment:
#### Guide
- `PUBLISHING_GUIDE.md` - Come pubblicare da Visual Studio
- `UNRAID_INSTALL.md` - Installazione su Unraid
- `README.md` - Indice deployment
#### Configuration
- `docker-compose.yml` - Docker Compose setup
- `unraid-template.xml` - Unraid 1-click install template
### `/Properties`
Visual Studio configuration:
#### PublishProfiles/
- `Docker.pubxml` - Docker container publish profile
- `FolderProfile.pubxml` - Folder-based publish profile
#### Other
- `launchSettings.json` - Debug/run configurations (HTTP, HTTPS, Docker)
### `/wwwroot`
Static web assets:
- `/css` - Custom stylesheets
- `/lib` - Client libraries (Bootstrap, etc.)
- Static files (favicon, etc.)
---
## ?? Configuration Files
### Root Level
| File | Purpose |
|------|---------|
| `TradingBot.csproj` | Project file with MSBuild post-build targets |
| `Dockerfile` | Multi-stage Docker build configuration |
| `Program.cs` | Application startup and service registration |
| `appsettings.json` | Production configuration |
| `appsettings.Development.json` | Development overrides |
| `.dockerignore` | Files excluded from Docker build |
| `.gitignore` | Files excluded from Git |
| `README.md` | Main project documentation |
---
## ?? Deployment Flow
```
Source Code (/) ? Build ? Docker Image ? Gitea Registry ? Unraid
?
Post-Build MSBuild Target
(TradingBot.csproj)
```
### Files Involved
1. **`TradingBot.csproj`**
- Contains `PushToGiteaRegistry` MSBuild target
- Hooks into `AfterTargets="DockerBuildImage"`
- Automatically tags and pushes to Gitea
2. **`Properties/PublishProfiles/Docker.pubxml`**
- Visual Studio publish profile
- Triggers Docker build
- Integrated with MSBuild post-build
3. **`Dockerfile`**
- Multi-stage build (build ? publish ? final)
- Optimized for .NET 10 and Blazor Server
- Creates minimal production image
4. **`deployment/docker-compose.yml`**
- Production deployment configuration
- Uses image from Gitea Registry
- Health checks and resource limits
5. **`deployment/unraid-template.xml`**
- Unraid Docker Manager template
- 1-click installation
- Pre-configured settings
---
## ?? Documentation Structure
```
/
??? README.md # Main project docs
??? deployment/
??? README.md # Deployment index
??? PUBLISHING_GUIDE.md # Publishing workflow
??? UNRAID_INSTALL.md # Unraid installation
```
### Reading Order
1. **[/README.md](../README.md)** - Start here for project overview
2. **[/deployment/PUBLISHING_GUIDE.md](../deployment/PUBLISHING_GUIDE.md)** - Learn how to publish
3. **[/deployment/UNRAID_INSTALL.md](../deployment/UNRAID_INSTALL.md)** - Deploy to Unraid
---
## ?? Development Workflow
### Local Development
```
1. Open solution in Visual Studio
2. F5 to run (uses launchSettings.json ? "TradingBot" profile)
3. Edit code with Hot Reload enabled
4. Test changes at http://localhost:5243
```
### Docker Local Testing
```
1. Switch to "Docker" profile in toolbar dropdown
2. F5 to run in container
3. Test changes at http://localhost:8080
4. Debug with breakpoints (works in container!)
```
### Publishing
```
1. Build ? Configuration Manager ? Release
2. Build ? Publish TradingBot
3. Select "Docker" profile
4. Click "Publish"
5. MSBuild post-build automatically pushes to Gitea
```
---
## ?? Sensitive Files (Not in Git)
These files are in `.gitignore`:
- `obj/` - Build intermediate files
- `bin/` - Build output
- `*.user` - User-specific VS settings
- `data/` - Runtime data (settings, trades)
- `.vs/` - Visual Studio cache
---
## ? Organization Benefits
### Before
```
TradingBot/
??? build-push-dockerhub.sh ? Script esterno
??? push-to-gitea.ps1 ? Script esterno
??? publish-all.ps1 ? Script esterno
??? full-workflow.bat ? Script esterno
??? docker-compose.yml ? Disordinato in root
??? unraid-template.xml ? Disordinato in root
??? ... (altri file misti)
```
### After ?
```
TradingBot/
??? deployment/ ? Tutto organizzato
? ??? docker-compose.yml ? Deployment configs
? ??? unraid-template.xml ? Templates
? ??? PUBLISHING_GUIDE.md ? Documentation
? ??? UNRAID_INSTALL.md ? Documentation
? ??? README.md ? Index
??? TradingBot.csproj ? Post-build integrato
??? (codice sorgente organizzato) ? Struttura chiara
```
**Vantaggi**:
- ? **Zero script esterni** - Tutto in MSBuild
- ? **Organizzazione chiara** - Deployment separato
- ? **Facile navigazione** - Struttura logica
- ? **Manutenibilità** - File raggruppati per scopo
- ? **Visual Studio friendly** - Tutto integrato nell'IDE
---
## ?? Summary
**Struttura pulita e professionale con:**
- ?? Codice organizzato per funzionalità
- ?? Deployment resources in cartella dedicata
- ?? Documentazione completa e accessibile
- ?? MSBuild integration per publishing automatico
- ? Zero dipendenze da script esterni
**Tutto gestibile da Visual Studio!** ??

View File

@@ -1,427 +0,0 @@
# ?? TradingBot - Installazione su Unraid (Senza Portainer)
## ? Installazione Diretta da Gitea Registry
Puoi installare TradingBot direttamente dall'Unraid Docker Manager usando il tuo Gitea Registry!
---
## ?? PREREQUISITI
### 1. Login Gitea Registry su Unraid
SSH su Unraid:
```bash
ssh root@192.168.30.23 # O IP Tailscale
# Login al Gitea Registry
docker login gitea.encke-hake.ts.net
# Username: Alby96
# Password: [Personal Access Token Gitea]
```
**Output atteso**:
```
Login Succeeded ?
```
---
## ?? METODO 1: Template XML (Consigliato)
### Step 1: Copia Template su Unraid
```bash
# Su Unraid
mkdir -p /boot/config/plugins/dockerMan/templates-user
# Scarica template
wget -O /boot/config/plugins/dockerMan/templates-user/TradingBot.xml \
https://gitea.encke-hake.ts.net/Alby96/Encelado/raw/branch/main/TradingBot/unraid-template.xml
```
### Step 2: Installa Container
1. Unraid WebUI ? **Docker** tab
2. Click **Add Container** (in fondo)
3. **Template**: Dropdown ? Seleziona **TradingBot**
4. Configura (opzionale):
- **Port**: `8080` (o cambia se occupata)
- **Data Path**: `/mnt/user/appdata/tradingbot/data`
5. Click **Apply**
Unraid farà:
- ? Pull immagine da Gitea Registry
- ? Crea container
- ? Crea volume per dati
- ? Start automatico
### Step 3: Accedi WebUI
```
http://192.168.30.23:8080
```
Dovresti vedere la Dashboard TradingBot! ??
---
## ?? METODO 2: Installazione Manuale
Se preferisci non usare template:
### Step 1: Unraid Docker Tab
1. **Docker** ? **Add Container**
2. **Name**: `TradingBot`
### Step 2: Configurazione Base
**Repository**:
```
gitea.encke-hake.ts.net/alby96/encelado/tradingbot:latest
```
**Network Type**: `Bridge`
**Console shell command**: `Shell`
### Step 3: Port Mapping
Click **Add another Path, Port, Variable, Label or Device**
**Config Type**: `Port`
- **Name**: WebUI
- **Container Port**: `8080`
- **Host Port**: `8080` (o altra porta libera)
- **Connection Type**: `TCP`
### Step 4: Volume Mapping
Click **Add another Path, Port, Variable, Label or Device**
**Config Type**: `Path`
- **Name**: AppData
- **Container Path**: `/app/data`
- **Host Path**: `/mnt/user/appdata/tradingbot/data`
- **Access Mode**: `Read/Write`
### Step 5: Environment Variables
**ASPNETCORE_ENVIRONMENT**:
- **Name**: `ASPNETCORE_ENVIRONMENT`
- **Value**: `Production`
**ASPNETCORE_URLS**:
- **Name**: `ASPNETCORE_URLS`
- **Value**: `http://+:8080`
### Step 6: Health Check (Opzionale)
**Extra Parameters**:
```
--health-cmd="wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1" --health-interval=30s --health-timeout=3s --health-retries=3 --health-start-period=10s
```
### Step 7: Apply
Click **Apply** in fondo alla pagina.
---
## ?? AGGIORNAMENTO CONTAINER
### Via Unraid Docker Tab
1. **Docker** ? Trova **TradingBot**
2. Click **icona ferma** (stop container)
3. Click **Force Update** (icona update)
4. Click **icona play** (start container)
Unraid farà:
- ? Pull ultima immagine da Gitea
- ? Ricrea container
- ? Mantiene dati (volume persistente)
### Automatico con User Scripts Plugin
Installa **User Scripts** plugin:
1. **Apps** ? Cerca "User Scripts"
2. Installa
Crea script update:
```bash
#!/bin/bash
# Nome: Update TradingBot
# Stop container
docker stop TradingBot
# Remove container
docker rm TradingBot
# Pull latest image
docker pull gitea.encke-hake.ts.net/alby96/encelado/tradingbot:latest
# Recreate container (Unraid fa automaticamente)
# O riavvia manualmente dalla WebUI
echo "Update completato! Riavvia TradingBot dalla Docker tab."
```
Schedula: Ogni settimana o manualmente.
---
## ?? GESTIONE CONTAINER
### Start/Stop/Restart
**Docker tab** ? Container **TradingBot**:
- ?? **Play**: Start
- ?? **Pause**: Pausa (mantiene in memoria)
- ?? **Stop**: Ferma
- ?? **Restart**: Riavvia
### View Logs
**Docker tab** ? Container **TradingBot** ? Click **icona logs**
O via terminal:
```bash
docker logs TradingBot -f
```
### Console Access
**Docker tab** ? Container **TradingBot** ? Click **icona console**
O via terminal:
```bash
docker exec -it TradingBot bash
```
### Statistics
**Docker tab** ? Container **TradingBot** ? Click **icona stats**
Mostra:
- CPU usage
- Memory usage
- Network I/O
- Block I/O
---
## ?? ACCESSO WEBUI
### Locale (Unraid LAN)
```
http://192.168.30.23:8080
```
### Via Tailscale
```
http://unraid.encke-hake.ts.net:8080
```
(Se hai configurato Tailscale su Unraid)
### Reverse Proxy (Opzionale)
Se vuoi accesso HTTPS:
**Nginx Proxy Manager** (tramite Unraid):
```
https://tradingbot.encke-hake.ts.net ? http://192.168.30.23:8080
```
---
## ?? SICUREZZA
### Best Practices
? **Porta non esposta pubblicamente** (solo LAN o Tailscale)
? **Volume dati protetto** (`/mnt/user/appdata/tradingbot/`)
? **Registry privato** (Gitea richiede login)
? **Certificati validi** (Tailscale)
? **User non-root** (già configurato nel Dockerfile)
### Backup Dati
```bash
# Backup manuale
tar -czf tradingbot-backup-$(date +%Y%m%d).tar.gz \
/mnt/user/appdata/tradingbot/data
# Restore
tar -xzf tradingbot-backup-20241212.tar.gz -C /
```
O usa **CA Backup / Restore Appdata** plugin.
---
## ?? TROUBLESHOOTING
### Container Non Si Avvia
**Check logs**:
```bash
docker logs TradingBot
```
**Problemi comuni**:
#### Porta occupata
```
Error: address already in use
```
**Fix**: Cambia porta in configurazione container
#### Pull failed
```
Error: unauthorized: authentication required
```
**Fix**: `docker login gitea.encke-hake.ts.net`
#### Image not found
```
Error: manifest not found
```
**Fix**: Verifica che l'immagine esista su Gitea Packages
### WebUI Non Accessibile
**Checklist**:
- [ ] Container status: **running** (verde)
- [ ] Health check: **healthy**
- [ ] Porta corretta (8080 o custom)
- [ ] Firewall Unraid non blocca
- [ ] Browser su `http://` non `https://`
**Test**:
```bash
curl http://localhost:8080/health
# Deve rispondere: Healthy
```
### Performance Issues
**Check risorse**:
```bash
docker stats TradingBot
```
**Limiti raccomandati**:
- **CPU**: 2 cores max, 0.5 reserved
- **Memory**: 1GB max, 256MB reserved
Configura in **Extra Parameters**:
```
--cpus="2.0" --memory="1g" --memory-reservation="256m"
```
---
## ?? CHECKLIST INSTALLAZIONE
### Pre-Install
- [ ] Unraid aggiornato
- [ ] Docker service attivo
- [ ] Porta 8080 disponibile
- [ ] `docker login gitea.encke-hake.ts.net` successful
### Install
- [ ] Template XML copiato (Metodo 1)
- [ ] O container configurato manualmente (Metodo 2)
- [ ] Container creato
- [ ] Volume dati creato
### Post-Install
- [ ] Container status: running
- [ ] Health check: healthy
- [ ] WebUI accessibile
- [ ] Settings configurati nell'app
---
## ?? VANTAGGI UNRAID NATIVO
? **Zero dipendenze** (no Portainer, no docker-compose)
? **WebUI Unraid integrata** (gestione familiare)
? **Auto-start** (container parte con Unraid)
? **Backup integrato** (con plugin CA)
? **Update semplice** (1 click)
? **Template riutilizzabile** (facile reinstall)
---
## ?? WORKFLOW COMPLETO
### Sviluppo (PC)
```
1. Codice in Visual Studio
2. Build ? Publish (Release)
3. ? Automatico: Push Gitea Registry
4. Commit: git push
```
### Deploy (Unraid)
```
1. Docker tab ? TradingBot ? Stop
2. Force Update
3. Start
4. Done! ?
```
**Tempo totale**: ~2 minuti
---
## ?? RISORSE
### Template XML
```
https://gitea.encke-hake.ts.net/Alby96/Encelado/raw/branch/main/TradingBot/unraid-template.xml
```
### Repository
```
https://gitea.encke-hake.ts.net/Alby96/Encelado
```
### Docker Image
```
gitea.encke-hake.ts.net/alby96/encelado/tradingbot:latest
```
### Support
```
https://gitea.encke-hake.ts.net/Alby96/Encelado/issues
```
---
**?? TradingBot pronto per Unraid senza Portainer!**
**Quick Start**:
```bash
# 1. Login
docker login gitea.encke-hake.ts.net
# 2. Install Template
wget -O /boot/config/plugins/dockerMan/templates-user/TradingBot.xml \
https://gitea.encke-hake.ts.net/Alby96/Encelado/raw/branch/main/TradingBot/unraid-template.xml
# 3. Docker tab ? Add Container ? TradingBot ? Apply
```
**Access**: `http://192.168.30.23:8080` ??