-
Notifications
You must be signed in to change notification settings - Fork 109
/
sync-docker-images.ps1
37 lines (29 loc) · 978 Bytes
/
sync-docker-images.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
35
36
37
param(
[string] $ImageListPath,
[string] $SourceRegistry = '',
[string] $TargetRegistry = ''
)
$images = (Get-Content $imageListPath)
Write-Output "Loaded image list. Image count: $($images.Length)."
Write-Output "Pulling images. Source registry: $SourceRegistry"
foreach ($tag in $images) {
Write-Output "** Pulling tag: $tag"
$sourceTag = $tag
if ($SourceRegistry.Length -gt 0) {
$sourceTag = "$($SourceRegistry)/$($tag)"
}
& docker $config image pull $sourceTag
if ($sourceTag -ne $tag) {
& docker $config image pull $tag
& docker $config image rm $sourceTag
}
}
if ($TargetRegistry.Length -gt 0) {
Write-Output "Pushing images. Target registry: $TargetRegistry."
foreach ($tag in $images) {
Write-Output "** Pushing tag: $tag"
$targetTag = "$($TargetRegistry)/$($tag)"
& docker $config image tag $tag $targetTag
& docker $config image push $targetTag
}
}