Skip to content

Commit 8b6cc74

Browse files
committed
Reserve the CI environment in PowerShell shutdown
1 parent 3a66d58 commit 8b6cc74

1 file changed

Lines changed: 7 additions & 29 deletions

File tree

docker/stop-environment.ps1

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,9 @@ $environmentName = $null
1010

1111
function Normalize-EnvironmentName {
1212
param([Parameter(Mandatory)][string] $Value)
13-
14-
$normalized = $Value.ToLowerInvariant()
15-
$normalized = [Regex]::Replace($normalized, '[^a-z0-9]+', '-')
16-
$normalized = $normalized.Trim('-')
17-
18-
if ([string]::IsNullOrWhiteSpace($normalized)) {
19-
throw "Environment name '$Value' does not contain any supported characters."
20-
}
21-
22-
if ($normalized.Length -gt $maximumEnvironmentNameLength) {
23-
$normalized = $normalized.Substring(0, $maximumEnvironmentNameLength).TrimEnd('-')
24-
}
25-
13+
$normalized = [Regex]::Replace($Value.ToLowerInvariant(), '[^a-z0-9]+', '-').Trim('-')
14+
if ([string]::IsNullOrWhiteSpace($normalized)) { throw "Environment name '$Value' does not contain any supported characters." }
15+
if ($normalized.Length -gt $maximumEnvironmentNameLength) { $normalized = $normalized.Substring(0, $maximumEnvironmentNameLength).TrimEnd('-') }
2616
return $normalized
2717
}
2818

@@ -38,25 +28,13 @@ foreach ($argument in $args) {
3828
}
3929
}
4030

41-
if ([string]::IsNullOrWhiteSpace($environmentName)) {
42-
$environmentName = Split-Path -Leaf $repositoryRoot
43-
}
44-
31+
if ([string]::IsNullOrWhiteSpace($environmentName)) { $environmentName = Split-Path -Leaf $repositoryRoot }
4532
$normalizedEnvironmentName = Normalize-EnvironmentName $environmentName
46-
$portMode = if ($normalizedEnvironmentName -in @('debug', 'test')) { $normalizedEnvironmentName } else { 'dynamic' }
33+
$portMode = if ($normalizedEnvironmentName -in @('debug', 'test', 'ci')) { $normalizedEnvironmentName } else { 'dynamic' }
4734
$projectName = "$projectPrefix-$normalizedEnvironmentName"
48-
$composeArguments = @(
49-
'compose',
50-
'--project-name', $projectName,
51-
'--file', (Join-Path $scriptDirectory 'docker-compose.yml'),
52-
'--file', (Join-Path $scriptDirectory "docker-compose.$portMode.yml"),
53-
'down'
54-
)
55-
35+
$composeArguments = @('compose', '--project-name', $projectName, '--file', (Join-Path $scriptDirectory 'docker-compose.yml'), '--file', (Join-Path $scriptDirectory "docker-compose.$portMode.yml"), 'down')
5636
if ($removeData) { $composeArguments += '--volumes' }
5737

5838
Write-Host "Stopping '$projectName'..."
5939
& docker @composeArguments
60-
if ($LASTEXITCODE -ne 0) {
61-
throw "Docker Compose failed with exit code $LASTEXITCODE."
62-
}
40+
if ($LASTEXITCODE -ne 0) { throw "Docker Compose failed with exit code $LASTEXITCODE." }

0 commit comments

Comments
 (0)