59 lines
1.8 KiB
PowerShell
59 lines
1.8 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
Builds the tcp-echo Docker image and pushes it to the Gitea registry.
|
|
.EXAMPLE
|
|
.\build-push.ps1 -Tag 1.0.0
|
|
.\build-push.ps1 -Tag 1.0.0 -AlsoLatest
|
|
#>
|
|
[CmdletBinding()]
|
|
param(
|
|
[Parameter(Mandatory = $true, Position = 0)]
|
|
[ValidatePattern('^[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}$')]
|
|
[string]$Tag,
|
|
|
|
# Also tag and push the image as :latest
|
|
[switch]$AlsoLatest
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
$Registry = 'gitea.eitczech.com'
|
|
$Repo = "$Registry/public/tcp-echo-server"
|
|
$Image = "${Repo}:$Tag"
|
|
$Root = $PSScriptRoot
|
|
|
|
function Invoke-Checked {
|
|
param([string[]]$Cmd)
|
|
Write-Host "> $($Cmd -join ' ')" -ForegroundColor Cyan
|
|
& $Cmd[0] $Cmd[1..($Cmd.Length - 1)]
|
|
if ($LASTEXITCODE -ne 0) { throw "Command failed with exit code ${LASTEXITCODE}: $($Cmd -join ' ')" }
|
|
}
|
|
|
|
# Metadata baked into OCI labels (shown on the Gitea package page)
|
|
$Revision = 'unknown'
|
|
if (Get-Command git -ErrorAction SilentlyContinue) {
|
|
$r = (& git -C $Root rev-parse --short HEAD 2>$null)
|
|
if ($LASTEXITCODE -eq 0 -and $r) { $Revision = $r.Trim() }
|
|
}
|
|
$Created = (Get-Date).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ')
|
|
|
|
Write-Host "Building $Image (revision $Revision)" -ForegroundColor Green
|
|
Invoke-Checked @('docker', 'build', '--pull',
|
|
'--build-arg', "VERSION=$Tag",
|
|
'--build-arg', "REVISION=$Revision",
|
|
'--build-arg', "CREATED=$Created",
|
|
'-t', $Image, $Root)
|
|
|
|
if ($AlsoLatest) {
|
|
Invoke-Checked @('docker', 'tag', $Image, "${Repo}:latest")
|
|
}
|
|
|
|
Write-Host "Pushing $Image" -ForegroundColor Green
|
|
Invoke-Checked @('docker', 'push', $Image)
|
|
|
|
if ($AlsoLatest) {
|
|
Invoke-Checked @('docker', 'push', "${Repo}:latest")
|
|
}
|
|
|
|
Write-Host "Done: $Image" -ForegroundColor Green
|
|
Write-Host "Deploy with: kubectl -n tcp-echo set image deploy/tcp-echo-a deploy/tcp-echo-b tcp-echo=$Image"
|