-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun.ps1
83 lines (70 loc) · 2.25 KB
/
run.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(Position = 0)]
[System.String]$paramService = "all",
[Parameter(Position = 1)]
[ValidateSet('down', 'up', 'build', 'recreate', 'clean-build')]
[System.String]$paramCommand = 'up'
)
$endpoints = $(
"Server"
)
$backends = $(
);
$clean = 0
$command = "up -d"
if ($paramCommand.Equals('recreate')) {
$command = "up -dV";
} elseif ($paramCommand.Equals('down')) {
$command = "down";
} elseif ($paramCommand.Equals('build')) {
$command = 'build';
} elseif ($paramCommand.Equals('clean-build')) {
$command = 'build --no-cache';
}
$services = $();
if ($paramService.Equals("base")) {
$services = $("base");
}
elseif ($paramService.Equals("all")) {
$services = $backends + $endpoints;
}
else {
$services = @($paramService);
}
$summaries = @{};
Foreach ($service in $services) {
if ($service.Equals("base")) {
$composeFileParams = "-f base/docker-compose.yml -f base/docker-compose.override.yml"
} else {
$dockerComposeDirectory = "";
if ($backends -contains $service) {
$dockerComposeDirectory = "domains/$service";
} elseif ($endpoints -contains $service) {
$dockerComposeDirectory = "endpoints/$service";
}
$composeFileParams = "-f $dockerComposeDirectory/docker-compose.yml -f $dockerComposeDirectory/docker-compose.override.yml"
}
if ($paramCommand.Equals('build')) {
$cmd = "docker-compose -p hive $composeFileParams $command";
} else {
if ($clean.Equals(1)) {
$cmd = "docker-compose -p hive $composeFileParams rm -s -f";
Write-Output "Executing: $cmd";
Invoke-Expression $cmd;
$cmd = "docker-compose -p hive $composeFileParams pull";
Write-Output "Executing: $cmd";
Invoke-Expression $cmd;
}
$cmd = "docker-compose -p hive $composeFileParams $command";
}
Write-Output "Executing: $cmd";
Invoke-Expression $cmd;
$summaries[$service] = $LASTEXITCODE -eq 0;
}
Foreach ($service in $summaries.keys) {
if($summaries[$service]) {
Write-Host "$paramCommand of $service succeeded" -ForegroundColor Green;
} else {
Write-Host "$paramCommand of $service failed" -ForegroundColor Red;
}
}