-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublish.ps1
34 lines (28 loc) · 1.24 KB
/
publish.ps1
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
#!/usr/bin/env pwsh
Set-StrictMode -Version latest
$ErrorActionPreference = "Stop"
# Get component data and set necessary variables
$component = Get-Content -Path "component.json" | ConvertFrom-Json
$rcImage="$($component.registry)/$($component.name):$($component.version)-$($component.build)-rc"
$latestImage="$($component.registry)/$($component.name):latest"
# Define server name
$pos = $component.registry.IndexOf("/")
$server = ""
if ($pos -gt 0) {
$server = $component.registry.Substring(0, $pos)
}
# Automatically login to server
if ($env:DOCKER_USER -ne $null -and $env:DOCKER_PASS -ne $null) {
docker login $server -u $env:DOCKER_USER -p $env:DOCKER_PASS
}
# Push image to docker registry
docker push $rcImage
# Check image pushed
if ($LastExitCode -ne 0) {
Write-Error "Can't push image '$rcImage' to docker registry. Make sure you use correct credentials in environment DOCKER_USER AND DOCKER_PASS variables or check package.ps1 logs." -ErrorAction Stop
}
docker push $latestImage
# Check image pushed
if ($LastExitCode -ne 0) {
Write-Error "Can't push image '$latestImage' to docker registry. Make sure you use correct credentials in environment DOCKER_USER AND DOCKER_PASS variables or check package.ps1 logs." -ErrorAction Stop
}