-
Notifications
You must be signed in to change notification settings - Fork 0
/
Build-DockerCache.ps1
36 lines (25 loc) · 1017 Bytes
/
Build-DockerCache.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
param(
[PSObject]
[Parameter(Mandatory)]
$Config
)
function Get-DockerImage([psobject] $image, [string] $dir) {
Write-Host "Pulling $($image.repository)`:$($image.tag)"
& docker pull "$($image.repository)`:$($image.tag)"
$output = Join-path $dir "$($image.name)-$($image.tag).tar"
Write-Host "Saving $($image.repository)`:$($image.tag) to $dir as $output"
& docker save "$($image.repository)`:$($image.tag)" -o $output
if ($($image.clear)) {
Write-Host "Clearing image $($image.repository)`:$($image.tag)"
& docker rmi "$($image.repository)`:$($image.tag)"
}
}
Write-Host "Generating Docker image cache..." -ForegroundColor Blue
if (Test-Path $Config.target) {
Remove-Item $Config.target -Recurse -Force
}
New-Item $Config.target -ItemType Directory -Force
$Config.data | ForEach-Object {
Get-DockerImage $_ $Config.target
}
Write-Host "Docker image cache successfully generated!" -ForegroundColor Green