-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_and_push.ps1
More file actions
46 lines (39 loc) · 1.38 KB
/
build_and_push.ps1
File metadata and controls
46 lines (39 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# ...existing code...
param(
[string]$ImageName = 'markz0r/atlassian-powerkit',
[string]$Version = $(Get-Date -Format 'yyyy.MM.dd.HHmm'),
[switch]$Push,
[switch]$Latest,
[switch]$TestRun,
[switch]$MultiArch # requires buildx configured
)
$ErrorActionPreference = 'Stop'
Write-Host "Building image for: $ImageName Version: $Version"
$tags = @("${ImageName}:$Version")
if ($Latest) { $tags += "$ImageName:latest" }
# Build args (add if you need)
$buildArgs = @()
# Choose build command
if ($MultiArch) {
if (-not (docker buildx ls 2>$null)) { throw 'docker buildx not configured.' }
$tagArgs = $tags | ForEach-Object { "--tag $_" } | Out-String
$cmd = "docker buildx build --platform linux/amd64,linux/arm64 $tagArgs --progress plain ."
if ($Push) { $cmd += ' --push' } else { $cmd += ' --load' }
Write-Host $cmd
Invoke-Expression $cmd
} else {
foreach ($t in $tags) {
docker build -t $t @buildArgs .
}
if ($Push) {
Write-Host 'Pushing tags...'
foreach ($t in $tags) { docker push $t }
}
}
if ($TestRun) {
Write-Host 'Test importing module inside container...'
$testTag = $tags[0]
docker run --rm $testTag pwsh -NoLogo -Command "Import-Module /app/AtlassianPowerKit.psd1; 'Module Loaded OK'; Get-Command AtlassianPowerKit | Out-Null"
}
Write-Host 'Done. Tags built:'
$tags | ForEach-Object { Write-Host " $_" }