51 lines
1.1 KiB
PowerShell
51 lines
1.1 KiB
PowerShell
param(
|
|
[string]$Version = "",
|
|
[string]$Image = "docker.pchuan.top/cdxs",
|
|
[string]$Dockerfile = "Dockerfile",
|
|
[string]$Platform = "linux/amd64",
|
|
[switch]$NoCache
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$repoRoot = Resolve-Path (Join-Path $PSScriptRoot "..")
|
|
Set-Location $repoRoot
|
|
|
|
if (-not $Version) {
|
|
$cargoToml = Get-Content -Raw -Path "Cargo.toml"
|
|
if ($cargoToml -notmatch '(?m)^version\s*=\s*"([^"]+)"') {
|
|
throw "Cannot read package version from Cargo.toml"
|
|
}
|
|
$Version = $Matches[1]
|
|
}
|
|
|
|
$versionTag = "${Image}:${Version}"
|
|
$latestTag = "${Image}:latest"
|
|
|
|
Write-Host "Building and pushing Docker image for $Platform"
|
|
Write-Host "Tags:"
|
|
Write-Host " $versionTag"
|
|
Write-Host " $latestTag"
|
|
|
|
$buildArgs = @(
|
|
"buildx", "build",
|
|
"--platform", $Platform,
|
|
"-f", $Dockerfile,
|
|
"-t", $versionTag,
|
|
"-t", $latestTag,
|
|
"--push"
|
|
)
|
|
|
|
if ($NoCache) {
|
|
$buildArgs += "--no-cache"
|
|
}
|
|
|
|
$buildArgs += "."
|
|
|
|
docker @buildArgs
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "Docker buildx push failed"
|
|
}
|
|
|
|
Write-Host "Pushed $versionTag and $latestTag"
|