Files
cdxs/scripts/publish-docker.ps1
T

49 lines
1.1 KiB
PowerShell

param(
[string]$Registry = "docker.pchuan.top",
[string]$ImageName = "cdxs",
[string]$Tag = "",
[switch]$NoLatest,
[string]$Platform = ""
)
$ErrorActionPreference = "Stop"
$repoRoot = Resolve-Path (Join-Path $PSScriptRoot "..")
Set-Location $repoRoot
if (-not $Tag) {
$cargoToml = Get-Content -Raw -Path "Cargo.toml"
if ($cargoToml -notmatch '(?m)^version\s*=\s*"([^"]+)"') {
throw "Cannot read package version from Cargo.toml"
}
$Tag = $Matches[1]
}
$image = "$Registry/$ImageName"
$versionTag = "${image}:$Tag"
$latestTag = "${image}:latest"
Write-Host "Building $versionTag"
$buildArgs = @("build", "-t", $versionTag)
if (-not $NoLatest) {
$buildArgs += @("-t", $latestTag)
}
if ($Platform) {
$buildArgs += @("--platform", $Platform)
}
$buildArgs += "."
docker @buildArgs
Write-Host "Pushing $versionTag"
docker push $versionTag
if (-not $NoLatest) {
Write-Host "Pushing $latestTag"
docker push $latestTag
}
Write-Host "Published $versionTag"
if (-not $NoLatest) {
Write-Host "Published $latestTag"
}