Refactoring Docker: integrazione con Visual Studio

Rimosse configurazioni e script manuali per Docker, build e documentazione. Riscritto il Dockerfile per supportare il flusso di lavoro Visual Studio/.NET 10 con multi-stage build semplificato. Aggiunte impostazioni di pubblicazione Docker in TradingBot.csproj e nuovo profilo "Docker" in launchSettings.json. Eliminati file di configurazione e script non più necessari; aggiunto Dockerfile.original come riferimento legacy. Ottimizzato il progetto per la pubblicazione tramite strumenti Microsoft.
This commit is contained in:
2025-12-15 15:46:26 +01:00
parent d933c7e812
commit 8ee8dc7e71
14 changed files with 109 additions and 490 deletions

View File

@@ -1,44 +0,0 @@
# TradingBot - Docker Environment Variables
# Copia questo file come .env per personalizzare la configurazione Docker
# ==============================================
# DOCKER CONFIGURATION
# ==============================================
# Porta esterna per accesso WebUI
# Modifica se la porta 8080 è già in uso sul tuo sistema
# Default: 8080
EXTERNAL_PORT=8080
# ==============================================
# NOTE IMPORTANTI
# ==============================================
#
# ?? TUTTE LE ALTRE CONFIGURAZIONI DELL'APPLICAZIONE
# SONO GESTIBILI DALL'INTERFACCIA WEB:
#
# - Fuso orario (Timezone)
# - Auto-start del bot
# - Intervallo aggiornamento dati
# - Modalità simulazione
# - Notifiche
# - Log level
# - E tutte le altre impostazioni
#
# Accedi all'interfaccia web su:
# http://localhost:8080 (o la porta configurata)
#
# Vai su ?? Impostazioni per configurare l'applicazione.
#
# Le impostazioni sono salvate automaticamente nel volume Docker
# e persistono tra i restart del container.
#
# ==============================================
# EXAMPLES
# ==============================================
#
# Se la porta 8080 è occupata, usa un'altra:
# EXTERNAL_PORT=8081
#
# Poi accedi su: http://localhost:8081
#

153
TradingBot/.gitignore vendored
View File

@@ -1,153 +0,0 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
# Visual Studio cache/options directory
.vs/
# Visual Studio Code
.vscode/
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace
# ReSharper
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JetBrains Rider
.idea/
*.sln.iml
# NuGet Packages
*.nupkg
*.snupkg
**/packages/*
!**/packages/build/
*.nuget.props
*.nuget.targets
project.lock.json
project.fragment.lock.json
artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# ASP.NET Scaffolding
ScaffoldingReadMe.txt
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.tlog
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
*.trx
*.coverage
*.coveragexml
# Node (if used)
node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# OS
.DS_Store
Thumbs.db
Desktop.ini
# Application specific
appsettings.Development.json
appsettings.local.json
*.db
*.sqlite
*.sqlite3
# Docker
.env
.env.local
docker-compose.override.yml
# Logs
logs/
*.log
# Temporary files
*.tmp
*.temp
*.bak
*.swp
*~
# Data directories
data/
Data/
# Local settings
%LocalAppData%/
# Secrets (NEVER COMMIT!)
*.key
*.pem
secrets.json

View File

@@ -1,59 +1,30 @@
# Dockerfile per TradingBot - Multi-stage build ottimizzato # Vedere https://aka.ms/customizecontainer per informazioni su come personalizzare il contenitore di debug e su come Visual Studio usa questo Dockerfile per compilare le immagini per un debug più rapido.
# Stage 1: Build
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
WORKDIR /src
# Copy csproj e restore dipendenze (layer caching) # Questa fase viene usata durante l'esecuzione da Visual Studio in modalità rapida (impostazione predefinita per la configurazione di debug)
COPY ["TradingBot.csproj", "./"] FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS base
RUN dotnet restore "TradingBot.csproj" USER $APP_UID
# Copy tutto il codice sorgente
COPY . .
# Build in Release mode
RUN dotnet build "TradingBot.csproj" -c Release -o /app/build
# Stage 2: Publish
FROM build AS publish
RUN dotnet publish "TradingBot.csproj" -c Release -o /app/publish /p:UseAppHost=false
# Stage 3: Runtime
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS final
WORKDIR /app WORKDIR /app
# Installa wget per health check (curl non disponibile nell'immagine base)
RUN apt-get update && apt-get install -y wget && rm -rf /var/lib/apt/lists/*
# Crea utente non-root per sicurezza
# Usa UID 1001 invece di 1000 (1000 spesso già in uso nell'immagine base)
RUN groupadd -r -g 1001 tradingbot && \
useradd -r -u 1001 -g tradingbot -m -s /bin/bash tradingbot && \
chown -R tradingbot:tradingbot /app
# Esponi porta
EXPOSE 8080 EXPOSE 8080
EXPOSE 8081
# Copy published app
# Questa fase viene usata per compilare il progetto di servizio
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["TradingBot.csproj", "."]
RUN dotnet restore "./TradingBot.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "./TradingBot.csproj" -c $BUILD_CONFIGURATION -o /app/build
# Questa fase viene usata per pubblicare il progetto di servizio da copiare nella fase finale
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./TradingBot.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
# Questa fase viene usata nell'ambiente di produzione o durante l'esecuzione da Visual Studio in modalità normale (impostazione predefinita quando non si usa la configurazione di debug)
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish . COPY --from=publish /app/publish .
# Crea directory per persistenza dati
RUN mkdir -p /app/data && \
chown -R tradingbot:tradingbot /app/data
# Volume per dati persistenti
VOLUME ["/app/data"]
# Switch a utente non-root
USER tradingbot
# Environment variables
ENV ASPNETCORE_URLS=http://+:8080
ENV ASPNETCORE_ENVIRONMENT=Production
ENV DOTNET_RUNNING_IN_CONTAINER=true
# Health check con wget invece di curl
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1
# Entry point
ENTRYPOINT ["dotnet", "TradingBot.dll"] ENTRYPOINT ["dotnet", "TradingBot.dll"]

View File

@@ -0,0 +1,59 @@
# Dockerfile per TradingBot - Multi-stage build ottimizzato
# Stage 1: Build
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
WORKDIR /src
# Copy csproj e restore dipendenze (layer caching)
COPY ["TradingBot.csproj", "./"]
RUN dotnet restore "TradingBot.csproj"
# Copy tutto il codice sorgente
COPY . .
# Build in Release mode
RUN dotnet build "TradingBot.csproj" -c Release -o /app/build
# Stage 2: Publish
FROM build AS publish
RUN dotnet publish "TradingBot.csproj" -c Release -o /app/publish /p:UseAppHost=false
# Stage 3: Runtime
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS final
WORKDIR /app
# Installa wget per health check (curl non disponibile nell'immagine base)
RUN apt-get update && apt-get install -y wget && rm -rf /var/lib/apt/lists/*
# Crea utente non-root per sicurezza
# Usa UID 1001 invece di 1000 (1000 spesso già in uso nell'immagine base)
RUN groupadd -r -g 1001 tradingbot && \
useradd -r -u 1001 -g tradingbot -m -s /bin/bash tradingbot && \
chown -R tradingbot:tradingbot /app
# Esponi porta
EXPOSE 8080
# Copy published app
COPY --from=publish /app/publish .
# Crea directory per persistenza dati
RUN mkdir -p /app/data && \
chown -R tradingbot:tradingbot /app/data
# Volume per dati persistenti
VOLUME ["/app/data"]
# Switch a utente non-root
USER tradingbot
# Environment variables
ENV ASPNETCORE_URLS=http://+:8080
ENV ASPNETCORE_ENVIRONMENT=Production
ENV DOTNET_RUNNING_IN_CONTAINER=true
# Health check con wget invece di curl
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1
# Entry point
ENTRYPOINT ["dotnet", "TradingBot.dll"]

View File

@@ -18,6 +18,17 @@
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
} }
},
"Docker": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
"environmentVariables": {
"ASPNETCORE_URLS": "http://+:8080",
"ASPNETCORE_ENVIRONMENT": "Production"
},
"publishAllPorts": true,
"useSSL": false
} }
} }
} }

View File

@@ -5,6 +5,20 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<BlazorDisableThrowNavigationException>true</BlazorDisableThrowNavigationException> <BlazorDisableThrowNavigationException>true</BlazorDisableThrowNavigationException>
<!-- Docker Publishing -->
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>.</DockerfileContext>
<!-- Auto-versioning -->
<Version>1.0.0</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
<UserSecretsId>e903ae67-ff0b-46dc-98a0-05de23186f86</UserSecretsId>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.23.0" />
</ItemGroup>
</Project> </Project>

View File

@@ -1,8 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@@ -1,20 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://0.0.0.0:8080"
}
},
"Limits": {
"MaxRequestBodySize": 10485760
}
}
}

View File

@@ -1,16 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://0.0.0.0:8080"
}
}
}
}

View File

@@ -1,29 +0,0 @@
@echo off
REM Script di build Docker per Windows
echo Building TradingBot Docker Image...
SET IMAGE_NAME=tradingbot
SET TAG=%1
IF "%TAG%"=="" SET TAG=latest
echo Building image: %IMAGE_NAME%:%TAG%
docker build -t %IMAGE_NAME%:%TAG% -f Dockerfile .
IF %ERRORLEVEL% NEQ 0 (
echo Build failed!
exit /b %ERRORLEVEL%
)
echo Build completed successfully!
REM Tag come latest se diverso
IF NOT "%TAG%"=="latest" (
echo Tagging as latest...
docker tag %IMAGE_NAME%:%TAG% %IMAGE_NAME%:latest
)
echo Done! Run with: docker-compose up -d
pause

View File

@@ -1,49 +0,0 @@
#!/bin/bash
# Script di build Docker per TradingBot
set -e
echo "?? Building TradingBot Docker Image..."
# Colori per output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Variabili
IMAGE_NAME="tradingbot"
TAG="${1:-latest}"
REGISTRY="${DOCKER_REGISTRY:-}" # Opzionale: tuo registry privato
echo -e "${BLUE}?? Building image: ${IMAGE_NAME}:${TAG}${NC}"
# Build dell'immagine
docker build \
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
--build-arg VCS_REF=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown") \
-t ${IMAGE_NAME}:${TAG} \
-f Dockerfile \
.
echo -e "${GREEN}? Build completato con successo!${NC}"
# Tag con latest
if [ "$TAG" != "latest" ]; then
echo -e "${BLUE}??? Tagging as latest...${NC}"
docker tag ${IMAGE_NAME}:${TAG} ${IMAGE_NAME}:latest
fi
# Mostra info immagine
echo -e "${BLUE}?? Image info:${NC}"
docker images | grep ${IMAGE_NAME} | head -n 2
# Se registry è configurato, push
if [ ! -z "$REGISTRY" ]; then
echo -e "${BLUE}?? Pushing to registry: ${REGISTRY}${NC}"
docker tag ${IMAGE_NAME}:${TAG} ${REGISTRY}/${IMAGE_NAME}:${TAG}
docker push ${REGISTRY}/${IMAGE_NAME}:${TAG}
echo -e "${GREEN}? Pushed to registry!${NC}"
fi
echo -e "${GREEN}?? Done! Run with: docker-compose up -d${NC}"

View File

@@ -1,43 +0,0 @@
version: '3.8'
services:
tradingbot:
container_name: tradingbot
image: tradingbot:latest
build:
context: .
dockerfile: Dockerfile
ports:
- "${EXTERNAL_PORT:-8080}:8080"
volumes:
# Persistenza dati applicazione
- tradingbot-data:/app/data
environment:
# Configurazioni base (non modificabili)
- ASPNETCORE_ENVIRONMENT=Production
- ASPNETCORE_URLS=http://+:8080
restart: unless-stopped
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8080/health"]
interval: 30s
timeout: 3s
retries: 3
start_period: 10s
networks:
- tradingbot-network
deploy:
resources:
limits:
cpus: '2.0'
memory: 1G
reservations:
cpus: '0.5'
memory: 256M
volumes:
tradingbot-data:
driver: local
networks:
tradingbot-network:
driver: bridge

View File

@@ -1,43 +0,0 @@
# ?? Documentation Organization Script
# Run this script to organize all documentation files
$docs = "docs"
# Create directory structure
$directories = @(
"installation",
"architecture",
"deployment",
"configuration",
"trading",
"development",
"troubleshooting",
"verification",
"api"
)
foreach ($dir in $directories) {
New-Item -ItemType Directory -Force -Path "$docs\$dir"
}
# Move files to appropriate directories
Write-Host "Moving documentation files..."
# Deployment docs
Move-Item -Path "DOCKER_QUICKSTART.md" -Destination "$docs\deployment\" -Force
Move-Item -Path "UNRAID_DEPLOYMENT.md" -Destination "$docs\deployment\" -Force
Move-Item -Path "DOCKER_BUILD_TEST.md" -Destination "$docs\deployment\" -Force
# Development docs
Move-Item -Path "GIT_WORKFLOW.md" -Destination "$docs\development\" -Force
Move-Item -Path "COMMIT_CHECKLIST.md" -Destination "$docs\development\" -Force
# Troubleshooting docs
Move-Item -Path "BROWSER_CACHE_GUIDE.md" -Destination "$docs\troubleshooting\" -Force
Move-Item -Path "SIDEBAR_TOGGLE_DEBUG.md" -Destination "$docs\troubleshooting\" -Force
# Verification docs
Move-Item -Path "FINAL_VERIFICATION.md" -Destination "$docs\verification\" -Force
Write-Host "? Documentation organized!"
Write-Host "See docs/README.md for index"

View File

@@ -1,31 +0,0 @@
#!/bin/bash
# Documentation Organization Script
# Run this to organize all documentation files
DOCS="docs"
# Create directory structure
echo "Creating directory structure..."
mkdir -p "$DOCS"/{installation,architecture,deployment,configuration,trading,development,troubleshooting,verification,api}
# Move files to appropriate directories
echo "Moving documentation files..."
# Deployment docs
mv DOCKER_QUICKSTART.md "$DOCS/deployment/" 2>/dev/null
mv UNRAID_DEPLOYMENT.md "$DOCS/deployment/" 2>/dev/null
mv DOCKER_BUILD_TEST.md "$DOCS/deployment/" 2>/dev/null
# Development docs
mv GIT_WORKFLOW.md "$DOCS/development/" 2>/dev/null
mv COMMIT_CHECKLIST.md "$DOCS/development/" 2>/dev/null
# Troubleshooting docs
mv BROWSER_CACHE_GUIDE.md "$DOCS/troubleshooting/" 2>/dev/null
mv SIDEBAR_TOGGLE_DEBUG.md "$DOCS/troubleshooting/" 2>/dev/null
# Verification docs
mv FINAL_VERIFICATION.md "$DOCS/verification/" 2>/dev/null
echo "? Documentation organized!"
echo "See docs/README.md for index"