From 8ee8dc7e71318d0226dec7fb5ba4799009b9404a Mon Sep 17 00:00:00 2001 From: Alberto Balbo Date: Mon, 15 Dec 2025 15:46:26 +0100 Subject: [PATCH] Refactoring Docker: integrazione con Visual Studio MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- TradingBot/.env.example | 44 ------- TradingBot/.gitignore | 153 ---------------------- TradingBot/Dockerfile | 79 ++++------- TradingBot/Dockerfile.original | 59 +++++++++ TradingBot/Properties/launchSettings.json | 11 ++ TradingBot/TradingBot.csproj | 14 ++ TradingBot/appsettings.Development.json | 8 -- TradingBot/appsettings.Production.json | 20 --- TradingBot/appsettings.json | 16 --- TradingBot/build-docker.bat | 29 ---- TradingBot/build-docker.sh | 49 ------- TradingBot/docker-compose.yml | 43 ------ TradingBot/organize-docs.ps1 | 43 ------ TradingBot/organize-docs.sh | 31 ----- 14 files changed, 109 insertions(+), 490 deletions(-) delete mode 100644 TradingBot/.env.example delete mode 100644 TradingBot/.gitignore create mode 100644 TradingBot/Dockerfile.original delete mode 100644 TradingBot/appsettings.Development.json delete mode 100644 TradingBot/appsettings.Production.json delete mode 100644 TradingBot/appsettings.json delete mode 100644 TradingBot/build-docker.bat delete mode 100644 TradingBot/build-docker.sh delete mode 100644 TradingBot/docker-compose.yml delete mode 100644 TradingBot/organize-docs.ps1 delete mode 100644 TradingBot/organize-docs.sh diff --git a/TradingBot/.env.example b/TradingBot/.env.example deleted file mode 100644 index 24068e4..0000000 --- a/TradingBot/.env.example +++ /dev/null @@ -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 -# diff --git a/TradingBot/.gitignore b/TradingBot/.gitignore deleted file mode 100644 index 5d4afed..0000000 --- a/TradingBot/.gitignore +++ /dev/null @@ -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 diff --git a/TradingBot/Dockerfile b/TradingBot/Dockerfile index af33db7..3e6ba37 100644 --- a/TradingBot/Dockerfile +++ b/TradingBot/Dockerfile @@ -1,59 +1,30 @@ -# Dockerfile per TradingBot - Multi-stage build ottimizzato -# Stage 1: Build -FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build -WORKDIR /src +# 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. -# 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 +# Questa fase viene usata durante l'esecuzione da Visual Studio in modalità rapida (impostazione predefinita per la configurazione di debug) +FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS base +USER $APP_UID 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 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 . - -# 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"] \ No newline at end of file diff --git a/TradingBot/Dockerfile.original b/TradingBot/Dockerfile.original new file mode 100644 index 0000000..af33db7 --- /dev/null +++ b/TradingBot/Dockerfile.original @@ -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"] diff --git a/TradingBot/Properties/launchSettings.json b/TradingBot/Properties/launchSettings.json index f2619e3..cd7b736 100644 --- a/TradingBot/Properties/launchSettings.json +++ b/TradingBot/Properties/launchSettings.json @@ -18,6 +18,17 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } + }, + "Docker": { + "commandName": "Docker", + "launchBrowser": true, + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}", + "environmentVariables": { + "ASPNETCORE_URLS": "http://+:8080", + "ASPNETCORE_ENVIRONMENT": "Production" + }, + "publishAllPorts": true, + "useSSL": false } } } diff --git a/TradingBot/TradingBot.csproj b/TradingBot/TradingBot.csproj index b5f6af0..e0979d5 100644 --- a/TradingBot/TradingBot.csproj +++ b/TradingBot/TradingBot.csproj @@ -5,6 +5,20 @@ enable enable true + + + Linux + . + + + 1.0.0 + 1.0.0.0 + 1.0.0.0 + e903ae67-ff0b-46dc-98a0-05de23186f86 + + + + diff --git a/TradingBot/appsettings.Development.json b/TradingBot/appsettings.Development.json deleted file mode 100644 index 0c208ae..0000000 --- a/TradingBot/appsettings.Development.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - } -} diff --git a/TradingBot/appsettings.Production.json b/TradingBot/appsettings.Production.json deleted file mode 100644 index dd3c4c3..0000000 --- a/TradingBot/appsettings.Production.json +++ /dev/null @@ -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 - } - } -} diff --git a/TradingBot/appsettings.json b/TradingBot/appsettings.json deleted file mode 100644 index 1a1114b..0000000 --- a/TradingBot/appsettings.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - }, - "AllowedHosts": "*", - "Kestrel": { - "Endpoints": { - "Http": { - "Url": "http://0.0.0.0:8080" - } - } - } -} diff --git a/TradingBot/build-docker.bat b/TradingBot/build-docker.bat deleted file mode 100644 index 8eb3b09..0000000 --- a/TradingBot/build-docker.bat +++ /dev/null @@ -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 diff --git a/TradingBot/build-docker.sh b/TradingBot/build-docker.sh deleted file mode 100644 index cdfce17..0000000 --- a/TradingBot/build-docker.sh +++ /dev/null @@ -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}" diff --git a/TradingBot/docker-compose.yml b/TradingBot/docker-compose.yml deleted file mode 100644 index c9ddb35..0000000 --- a/TradingBot/docker-compose.yml +++ /dev/null @@ -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 diff --git a/TradingBot/organize-docs.ps1 b/TradingBot/organize-docs.ps1 deleted file mode 100644 index afe7c01..0000000 --- a/TradingBot/organize-docs.ps1 +++ /dev/null @@ -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" diff --git a/TradingBot/organize-docs.sh b/TradingBot/organize-docs.sh deleted file mode 100644 index 6473873..0000000 --- a/TradingBot/organize-docs.sh +++ /dev/null @@ -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"