[Fix] Passa versione MinVer come build-arg al Docker per evitare errore MINVER1001
Il problema era che MinVer veniva eseguito dentro il container Docker dove la directory .git non esiste, causando il warning MINVER1001 e l'uso di 0.0.0-alpha.0 (poi sostituito dal fallback hardcoded 2.1.0). Soluzione: - La versione viene calcolata sul runner CI/CD (dove git e' disponibile) - Esportata come variabile d'ambiente APP_VERSION via GITHUB_ENV - Passata al Docker build tramite --build-arg APP_VERSION - Nei Dockerfile aggiunto ARG APP_VERSION e /p:MinVerVersionOverride per imporla a MinVer senza che tenti di accedere a git (assente nel container) - ARG ridichiarato dopo ogni FROM in multi-stage build (comportamento Docker)
This commit is contained in:
@@ -72,6 +72,9 @@ jobs:
|
||||
echo "Generated version.json:"
|
||||
cat wwwroot/version.json
|
||||
cd ..
|
||||
|
||||
# Esporta la versione come variabile d'ambiente per il Docker build
|
||||
echo "APP_VERSION=$VERSION" >> "$GITHUB_ENV"
|
||||
shell: bash
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
@@ -138,6 +141,7 @@ jobs:
|
||||
platforms: linux/amd64
|
||||
# Aumenta timeout per registry lenti
|
||||
build-args: |
|
||||
APP_VERSION=${{ env.APP_VERSION }}
|
||||
BUILDKIT_STEP_LOG_MAX_SIZE=50000000
|
||||
provenance: false
|
||||
sbom: false
|
||||
@@ -217,6 +221,10 @@ jobs:
|
||||
Write-Host "Generated version.json:"
|
||||
Get-Content "wwwroot\version.json"
|
||||
cd ..
|
||||
|
||||
# Esporta la versione come variabile d'ambiente per il Docker build
|
||||
"APP_VERSION=$VERSION" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
|
||||
Write-Host "APP_VERSION=$VERSION esportata per Docker build"
|
||||
shell: pwsh
|
||||
|
||||
- name: Debug - Verify files
|
||||
@@ -267,7 +275,7 @@ jobs:
|
||||
)
|
||||
|
||||
echo Building Windows Docker image...
|
||||
docker build -t temp-windows -f Dockerfile.windows .
|
||||
docker build --build-arg APP_VERSION=%APP_VERSION% -t temp-windows -f Dockerfile.windows .
|
||||
if errorlevel 1 (
|
||||
echo Build failed!
|
||||
exit /b 1
|
||||
|
||||
@@ -34,6 +34,23 @@ jobs:
|
||||
with:
|
||||
fetch-depth: 0 # Necessario per MinVer: deve percorrere tutta la storia Git per trovare i tag
|
||||
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: '9.0.x'
|
||||
|
||||
- name: Calcola versione con MinVer
|
||||
run: |
|
||||
git fetch --tags --force
|
||||
VERSION=$(cd Data_Coupler && dotnet msbuild -getProperty:Version -p:ContinuousIntegrationBuild=true 2>/dev/null | tail -1)
|
||||
if [ -z "$VERSION" ] || [ "$VERSION" = "0.0.0-alpha.0" ]; then
|
||||
echo "Warning: MinVer non ha trovato tag. Uso fallback."
|
||||
VERSION="2.3.2-alpha.0.$(git rev-list --count HEAD)"
|
||||
fi
|
||||
echo "Versione calcolata: $VERSION"
|
||||
echo "APP_VERSION=$VERSION" >> "$GITHUB_ENV"
|
||||
shell: bash
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
@@ -77,6 +94,8 @@ jobs:
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
platforms: linux/amd64
|
||||
build-args: |
|
||||
APP_VERSION=${{ env.APP_VERSION }}
|
||||
|
||||
- name: Generate artifact attestation
|
||||
if: github.event_name != 'pull_request'
|
||||
@@ -100,6 +119,19 @@ jobs:
|
||||
with:
|
||||
fetch-depth: 0 # Necessario per MinVer: deve percorrere tutta la storia Git per trovare i tag
|
||||
|
||||
- name: Calcola versione con MinVer
|
||||
run: |
|
||||
git fetch --tags --force
|
||||
$VERSION = (cd Data_Coupler; dotnet msbuild -getProperty:Version -p:ContinuousIntegrationBuild=true 2>$null | Select-Object -Last 1)
|
||||
if ([string]::IsNullOrWhiteSpace($VERSION) -or $VERSION -eq "0.0.0-alpha.0") {
|
||||
Write-Host "Warning: MinVer non ha trovato tag. Uso fallback."
|
||||
$commitCount = git rev-list --count HEAD
|
||||
$VERSION = "2.3.2-alpha.0.$commitCount"
|
||||
}
|
||||
Write-Host "Versione calcolata: $VERSION"
|
||||
"APP_VERSION=$VERSION" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
|
||||
shell: pwsh
|
||||
|
||||
- name: Log in to GitHub Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
@@ -132,7 +164,7 @@ jobs:
|
||||
$imageName = "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}".ToLower()
|
||||
|
||||
# Build with temporary tag
|
||||
docker build -t "${imageName}:temp-windows" -f Dockerfile.windows .
|
||||
docker build --build-arg "APP_VERSION=$env:APP_VERSION" -t "${imageName}:temp-windows" -f Dockerfile.windows .
|
||||
|
||||
# Parse and push all tags
|
||||
$tags = "${{ steps.meta.outputs.tags }}" -split "`n"
|
||||
|
||||
+7
-2
@@ -3,6 +3,8 @@
|
||||
|
||||
# Stage 1: Build
|
||||
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
|
||||
# Versione calcolata da MinVer sul runner CI/CD e passata come build-arg
|
||||
ARG APP_VERSION=0.0.0-alpha.0
|
||||
WORKDIR /src
|
||||
|
||||
# Copia i file di progetto e ripristina le dipendenze
|
||||
@@ -20,15 +22,18 @@ COPY . .
|
||||
|
||||
# Build del progetto principale
|
||||
WORKDIR "/src/Data_Coupler"
|
||||
RUN dotnet build "Data_Coupler.csproj" -c Release -o /app/build /p:ContinuousIntegrationBuild=true
|
||||
RUN dotnet build "Data_Coupler.csproj" -c Release -o /app/build /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 /app/publish \
|
||||
/p:SelfContained=false \
|
||||
/p:PublishTrimmed=false \
|
||||
/p:PublishSingleFile=false \
|
||||
/p:ContinuousIntegrationBuild=true
|
||||
/p:ContinuousIntegrationBuild=true \
|
||||
/p:MinVerVersionOverride=${APP_VERSION}
|
||||
|
||||
# Stage 3: Runtime
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS final
|
||||
|
||||
+6
-2
@@ -3,6 +3,8 @@
|
||||
|
||||
# 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
|
||||
@@ -23,11 +25,13 @@ 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
|
||||
RUN dotnet build "Data_Coupler.csproj" -c Release -o /o --no-restore /p:MinVerVersionOverride=%APP_VERSION%
|
||||
|
||||
# Stage 2: Publish
|
||||
FROM build AS publish
|
||||
RUN dotnet publish "Data_Coupler.csproj" -c Release -o /p --no-restore -r win-x64 --self-contained false
|
||||
# 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:MinVerVersionOverride=%APP_VERSION%
|
||||
|
||||
# Stage 3: Runtime
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:9.0-nanoserver-ltsc2022 AS final
|
||||
|
||||
Reference in New Issue
Block a user