Files
Encelado/TradingBot/Dockerfile
Alberto Balbo b2f04b6600 Supporto Docker/Unraid: build, healthcheck, docs
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.
2025-12-12 23:40:34 +01:00

55 lines
1.3 KiB
Docker

# 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
# Crea utente non-root per sicurezza
RUN useradd -m -u 1000 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
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1
# Entry point
ENTRYPOINT ["dotnet", "TradingBot.dll"]