# Build and push the production web image to Gitea over LAN (fast path). param( [string]$Tag = '', [switch]$SkipHosts, [switch]$SkipBuild ) $ErrorActionPreference = "Stop" . (Join-Path $PSScriptRoot "..\scripts\lib\Deploy-CliResult.ps1") . (Join-Path $PSScriptRoot "..\scripts\lib\Build-ReleaseTag.ps1") $Registry = "gitea.mysuperlab.netcraze.pro" $Image = "$Registry/danilka/gallery-web" $RepoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..\..")).Path function Test-DockerRunning { $prevEap = $ErrorActionPreference $ErrorActionPreference = 'Continue' docker info 2>&1 | Out-Null $ok = $LASTEXITCODE -eq 0 $ErrorActionPreference = $prevEap return $ok } Write-Host "=== Build + LAN push to Gitea ===" -ForegroundColor Cyan if (-not (Test-DockerRunning)) { Write-DeployCliResult -Script 'build-push-lan' -Success $false -Summary 'Docker is not running. Start Docker Desktop and retry.' exit 1 } $meta = Get-BuildMetadata -RepoRoot $RepoRoot $releaseTag = if ($Tag -and $Tag.Trim()) { $Tag.Trim() } else { $meta.ReleaseTag } $meta.ReleaseTag = $releaseTag Write-Host "Release tag: $releaseTag" Write-Host "Build metadata: app_version=$($meta.AppVersion), git_sha=$($meta.GitSha), built_at=$($meta.BuildTimeUtc)" if (-not $SkipBuild) { Write-Host "" Write-Host "Building ${Image}:$releaseTag and ${Image}:latest ..." docker build -f infra/docker/Dockerfile ` --build-arg "APP_VERSION=$($meta.AppVersion)" ` --build-arg "GIT_SHA=$($meta.GitSha)" ` --build-arg "IMAGE_TAG=$releaseTag" ` --build-arg "BUILD_TIME=$($meta.BuildTimeUtc)" ` -t "${Image}:$releaseTag" ` -t "${Image}:latest" ` $RepoRoot if ($LASTEXITCODE -ne 0) { Write-DeployCliResult -Script 'build-push-lan' -Success $false -Summary "Docker build failed with exit code $LASTEXITCODE" exit $LASTEXITCODE } Write-Host "Build complete." -ForegroundColor Green } else { Write-Host "Skipping build (-SkipBuild)." -ForegroundColor Yellow } Write-Host "" if ($SkipBuild) { $pushTags = @('latest') if ($Tag -and $Tag.Trim()) { $pushTags = @($Tag.Trim(), 'latest') | Select-Object -Unique } } else { $pushTags = @($releaseTag, 'latest') | Select-Object -Unique } & "$PSScriptRoot/push-lan.ps1" -Tags $pushTags -SkipHosts:$SkipHosts if ($LASTEXITCODE -ne 0) { Write-DeployCliResult -Script 'build-push-lan' -Success $false -Summary "Docker push failed with exit code $LASTEXITCODE" exit $LASTEXITCODE } $manifestPath = Write-LastDockerRelease -RepoRoot $RepoRoot -Metadata $meta -Image "${Image}:$releaseTag" Write-DeployCliResult -Script 'build-push-lan' -Success $true -Summary 'Docker image built and pushed to Gitea.' -Details @( "Release tag: $releaseTag", "Also pushed as: latest", "Git commit: $($meta.GitSha)", "Built at: $($meta.BuildTimeUtc)", "Manifest: $manifestPath", "TrueNAS: restart gallery-web (pull_policy: always uses latest)." ) exit 0