f1f75d59ac
Senza questo flag il target GenerateVersionJson nel .csproj veniva eseguito dentro il container Docker Windows dove: - Non esiste .git (fatal: not a git repository) - version.json copiato da COPY e' read-only o protetto → MSB3491: Access to the path '...\wwwroot\version.json' is denied Il Dockerfile Linux aveva gia /p:ContinuousIntegrationBuild=true. La condizione nel .csproj e': Condition="'' != 'true' AND '' != 'true'" quindi con il flag il target viene saltato e version.json usa quello generato dal workflow prima del docker build.
60 lines
2.3 KiB
Docker
60 lines
2.3 KiB
Docker
# Dockerfile per Windows
|
|
# Multi-stage build per ottimizzare le dimensioni dell'immagine finale
|
|
|
|
# Stage 1: Build
|
|
FROM mcr.microsoft.com/dotnet/sdk:9.0-nanoserver-ltsc2022 AS build
|
|
# Versione calcolata da MinVer sul runner CI/CD e passata come build-arg
|
|
ARG APP_VERSION=0.0.0-alpha.0
|
|
WORKDIR /s
|
|
|
|
# Copia i file di progetto e ripristina le dipendenze con nomi originali
|
|
COPY ["Data_Coupler/Data_Coupler.csproj", "Data_Coupler/"]
|
|
COPY ["DataConnection/DataConnection.csproj", "DataConnection/"]
|
|
COPY ["CredentialManager/CredentialManager.csproj", "CredentialManager/"]
|
|
COPY ["Components/Components.csproj", "Components/"]
|
|
COPY ["nuget.config", "./"]
|
|
|
|
# Ripristina le dipendenze per tutti i progetti con package cache ultra-corto
|
|
RUN dotnet restore "Data_Coupler/Data_Coupler.csproj" --runtime win-x64 --disable-parallel --packages /p
|
|
|
|
# Copia tutto il codice sorgente
|
|
COPY ["Data_Coupler/", "Data_Coupler/"]
|
|
COPY ["DataConnection/", "DataConnection/"]
|
|
COPY ["CredentialManager/", "CredentialManager/"]
|
|
COPY ["Components/", "Components/"]
|
|
|
|
# Build del progetto principale con output path corto
|
|
WORKDIR "/s/Data_Coupler"
|
|
RUN dotnet build "Data_Coupler.csproj" -c Release -o /o --no-restore /p:ContinuousIntegrationBuild=true /p:MinVerVersionOverride=%APP_VERSION%
|
|
|
|
# Stage 2: Publish
|
|
FROM build AS publish
|
|
# Necessario ridichiarare ARG dopo FROM in multi-stage build
|
|
ARG APP_VERSION=0.0.0-alpha.0
|
|
RUN dotnet publish "Data_Coupler.csproj" -c Release -o /p --no-restore -r win-x64 --self-contained false /p:ContinuousIntegrationBuild=true /p:MinVerVersionOverride=%APP_VERSION%
|
|
|
|
# Stage 3: Runtime
|
|
FROM mcr.microsoft.com/dotnet/aspnet:9.0-nanoserver-ltsc2022 AS final
|
|
WORKDIR /app
|
|
|
|
# Crea la directory per il database
|
|
RUN mkdir C:\ProgramData\Data_Coupler
|
|
|
|
# Copia i file pubblicati
|
|
COPY --from=publish /p .
|
|
|
|
# Configura le variabili d'ambiente
|
|
ENV ASPNETCORE_URLS=http://+:7550
|
|
ENV DOTNET_RUNNING_IN_CONTAINER=true
|
|
ENV ASPNETCORE_ENVIRONMENT=Production
|
|
|
|
# Espone la porta dell'applicazione
|
|
EXPOSE 7550
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
|
CMD powershell -Command "try { $response = Invoke-WebRequest -Uri http://localhost:7550/health -UseBasicParsing -TimeoutSec 5; if ($response.StatusCode -eq 200) { exit 0 } else { exit 1 } } catch { exit 1 }"
|
|
|
|
# Punto di ingresso
|
|
ENTRYPOINT ["dotnet", "Data_Coupler.dll"]
|