[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:"
|
echo "Generated version.json:"
|
||||||
cat wwwroot/version.json
|
cat wwwroot/version.json
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
|
# Esporta la versione come variabile d'ambiente per il Docker build
|
||||||
|
echo "APP_VERSION=$VERSION" >> "$GITHUB_ENV"
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
@@ -138,6 +141,7 @@ jobs:
|
|||||||
platforms: linux/amd64
|
platforms: linux/amd64
|
||||||
# Aumenta timeout per registry lenti
|
# Aumenta timeout per registry lenti
|
||||||
build-args: |
|
build-args: |
|
||||||
|
APP_VERSION=${{ env.APP_VERSION }}
|
||||||
BUILDKIT_STEP_LOG_MAX_SIZE=50000000
|
BUILDKIT_STEP_LOG_MAX_SIZE=50000000
|
||||||
provenance: false
|
provenance: false
|
||||||
sbom: false
|
sbom: false
|
||||||
@@ -217,6 +221,10 @@ jobs:
|
|||||||
Write-Host "Generated version.json:"
|
Write-Host "Generated version.json:"
|
||||||
Get-Content "wwwroot\version.json"
|
Get-Content "wwwroot\version.json"
|
||||||
cd ..
|
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
|
shell: pwsh
|
||||||
|
|
||||||
- name: Debug - Verify files
|
- name: Debug - Verify files
|
||||||
@@ -267,7 +275,7 @@ jobs:
|
|||||||
)
|
)
|
||||||
|
|
||||||
echo Building Windows Docker image...
|
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 (
|
if errorlevel 1 (
|
||||||
echo Build failed!
|
echo Build failed!
|
||||||
exit /b 1
|
exit /b 1
|
||||||
|
|||||||
@@ -34,6 +34,23 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
fetch-depth: 0 # Necessario per MinVer: deve percorrere tutta la storia Git per trovare i tag
|
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
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
@@ -77,6 +94,8 @@ jobs:
|
|||||||
cache-from: type=gha
|
cache-from: type=gha
|
||||||
cache-to: type=gha,mode=max
|
cache-to: type=gha,mode=max
|
||||||
platforms: linux/amd64
|
platforms: linux/amd64
|
||||||
|
build-args: |
|
||||||
|
APP_VERSION=${{ env.APP_VERSION }}
|
||||||
|
|
||||||
- name: Generate artifact attestation
|
- name: Generate artifact attestation
|
||||||
if: github.event_name != 'pull_request'
|
if: github.event_name != 'pull_request'
|
||||||
@@ -100,6 +119,19 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
fetch-depth: 0 # Necessario per MinVer: deve percorrere tutta la storia Git per trovare i tag
|
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
|
- name: Log in to GitHub Container Registry
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
@@ -132,7 +164,7 @@ jobs:
|
|||||||
$imageName = "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}".ToLower()
|
$imageName = "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}".ToLower()
|
||||||
|
|
||||||
# Build with temporary tag
|
# 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
|
# Parse and push all tags
|
||||||
$tags = "${{ steps.meta.outputs.tags }}" -split "`n"
|
$tags = "${{ steps.meta.outputs.tags }}" -split "`n"
|
||||||
|
|||||||
+7
-2
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
# Stage 1: Build
|
# Stage 1: Build
|
||||||
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS 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
|
WORKDIR /src
|
||||||
|
|
||||||
# Copia i file di progetto e ripristina le dipendenze
|
# Copia i file di progetto e ripristina le dipendenze
|
||||||
@@ -20,15 +22,18 @@ COPY . .
|
|||||||
|
|
||||||
# Build del progetto principale
|
# Build del progetto principale
|
||||||
WORKDIR "/src/Data_Coupler"
|
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
|
# Stage 2: Publish
|
||||||
FROM build AS 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 \
|
RUN dotnet publish "Data_Coupler.csproj" -c Release -o /app/publish \
|
||||||
/p:SelfContained=false \
|
/p:SelfContained=false \
|
||||||
/p:PublishTrimmed=false \
|
/p:PublishTrimmed=false \
|
||||||
/p:PublishSingleFile=false \
|
/p:PublishSingleFile=false \
|
||||||
/p:ContinuousIntegrationBuild=true
|
/p:ContinuousIntegrationBuild=true \
|
||||||
|
/p:MinVerVersionOverride=${APP_VERSION}
|
||||||
|
|
||||||
# Stage 3: Runtime
|
# Stage 3: Runtime
|
||||||
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS final
|
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS final
|
||||||
|
|||||||
+6
-2
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
# Stage 1: Build
|
# Stage 1: Build
|
||||||
FROM mcr.microsoft.com/dotnet/sdk:9.0-nanoserver-ltsc2022 AS 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
|
WORKDIR /s
|
||||||
|
|
||||||
# Copia i file di progetto e ripristina le dipendenze con nomi originali
|
# 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
|
# Build del progetto principale con output path corto
|
||||||
WORKDIR "/s/Data_Coupler"
|
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
|
# Stage 2: Publish
|
||||||
FROM build AS 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
|
# Stage 3: Runtime
|
||||||
FROM mcr.microsoft.com/dotnet/aspnet:9.0-nanoserver-ltsc2022 AS final
|
FROM mcr.microsoft.com/dotnet/aspnet:9.0-nanoserver-ltsc2022 AS final
|
||||||
|
|||||||
Reference in New Issue
Block a user