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:
59
TradingBot/Dockerfile.original
Normal file
59
TradingBot/Dockerfile.original
Normal 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"]
|
||||
Reference in New Issue
Block a user