-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathbuild-images.ps1
83 lines (65 loc) · 2.39 KB
/
build-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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
Param (
[Parameter(HelpMessage = "Topology. XP1 or XP0")]
[ValidateSet("xp0", "xp1")]
[string]$Topology = "xp0"
,
[Parameter(HelpMessage = "Set Docker Compose services to build. Passed to the docker compose build command.")]
[string[]]$Services
,
[Parameter(HelpMessage = "Set whether to build images in parallel ")]
[switch]$Parallel
,
[Parameter(HelpMessage = "Skips pulling the base images used by the dockerfiles.")]
[switch]$SkipPull
,
[Parameter(HelpMessage = "Skips building the solution image.")]
[switch]$SkipSolution
,
[Parameter(HelpMessage = "Runs in the context of a CI pipeline.")]
[switch]$CI
)
$dockerComposeBaseCommand = "docker compose"
function Invoke-BuildSolutionAssets {
# Build the solution images
$dockerComposeCommand = $dockerComposeBaseCommand
$dockerComposeCommand += " -f docker-compose.build.solution.yml build"
if ($Parallel) {
$dockerComposeCommand += " --parallel"
}
Write-Host "Executing $dockerComposeCommand"
& ([scriptblock]::create($dockerComposeCommand))
$LASTEXITCODE -ne 0 | Where-Object { $_ } | ForEach-Object { throw "Failed." }
$dockerComposeCommand = $dockerComposeBaseCommand
$dockerComposeCommand += " --env-file .env"
$dockerComposeCommand += " -f docker/docker-compose.copy.solution.yml build"
if ($Parallel) {
$dockerComposeCommand += " --parallel"
}
Write-Host "Executing $dockerComposeCommand"
& ([scriptblock]::create($dockerComposeCommand))
$LASTEXITCODE -ne 0 | Where-Object { $_ } | ForEach-Object { throw "Failed." }
}
if (-not $SkipPull) {
# Pulling the base images as a separate step because "docker compose build --pull" fails with the "lighthouse-solution" image which is never pushed to the Docker registry.
if ($CI) {
.\pull-build-images.ps1 -Topology $Topology -CI
} else {
.\pull-build-images.ps1 -Topology $Topology
}
}
if ($null -eq $Services) {
$Services = @()
}
if (-not $SkipSolution) {
Invoke-BuildSolutionAssets
}
$fileSuffix = $(if ("$Topology" -eq "xp0") { "" } else { "-xp1" })
# Build the service images
$dockerComposeCommand = $dockerComposeBaseCommand
$dockerComposeCommand += " -f docker-compose$($fileSuffix).yml -f docker-compose$fileSuffix.build.yml build"
if ($Parallel) {
$dockerComposeCommand += " --parallel"
}
$dockerComposeCommand += " $Services"
Write-Host "Executing $dockerComposeCommand"
& ([scriptblock]::create($dockerComposeCommand))