Aggiornamento staging: Controllo di versione container #13

Merged
Alessio merged 5 commits from development into staging 2026-03-22 16:25:15 +01:00
4 changed files with 55 additions and 6 deletions
Showing only changes of commit c15e6c9065 - Show all commits
+9 -1
View File
@@ -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
+33 -1
View File
@@ -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
View File
@@ -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
View File
@@ -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