-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.ps1
More file actions
executable file
·92 lines (80 loc) · 2.97 KB
/
Copy pathstart.ps1
File metadata and controls
executable file
·92 lines (80 loc) · 2.97 KB
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
84
85
86
87
88
89
90
91
92
# composer-wrapper: 2
Set-StrictMode -Version Latest
$composerSelfImage = if ($env:COMPOSER_SELF_IMAGE) { $env:COMPOSER_SELF_IMAGE } else { "debeski/composer:latest" }
# Pull the deployer image before launching composer from that same image.
if ($args.Count -eq 2 -and $args[0] -eq "self" -and $args[1] -eq "update") {
# `docker image inspect` first: `docker run` on a missing image pulls it,
# silently, since the progress goes to the stderr this used to discard.
Write-Host "=== Current Composer Version ==="
docker image inspect $composerSelfImage 2>&1 | Out-Null
if ($LASTEXITCODE -eq 0) {
$currentVersion = docker run --rm --entrypoint cat $composerSelfImage /app/VERSION
Write-Host " $currentVersion"
} else {
Write-Host " (not present locally)"
}
Write-Host ""
Write-Host "Pulling latest composer image..."
docker pull $composerSelfImage
Write-Host ""
Write-Host "=== Installed Version ==="
docker run --rm --entrypoint cat $composerSelfImage /app/VERSION
exit 0
}
if ($PSScriptRoot) {
$projectRoot = $PSScriptRoot
} else {
$projectRoot = (Get-Location).Path
}
$projectRoot = (Resolve-Path $projectRoot).Path
if ($projectRoot -match '^([A-Za-z]):\\(.*)$') {
$drive = $matches[1].ToLower()
$tail = ($matches[2] -replace '\\', '/')
$containerRoot = "/host_mnt/$drive/$tail"
} else {
throw "Unsupported Windows path format: $projectRoot"
}
$secretArgs = @()
foreach ($candidate in @(".env", "secrets/.env", ".secrets/.env")) {
$secretPath = Join-Path $projectRoot $candidate
if (-not (Test-Path -LiteralPath $secretPath -PathType Leaf)) {
continue
}
$secretKeys = @(
Get-Content -LiteralPath $secretPath | ForEach-Object {
if ($_ -match '^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=') { $matches[1] }
}
)
if ($secretKeys.Count -eq 0) {
throw "Secrets file contains no environment values: $secretPath"
}
$secretArgs = @(
"--env-file", $secretPath,
"-e", "COMPOSER_INHERITED_SECRET_KEYS=$($secretKeys -join ',')"
)
break
}
# Announce the first-run download instead of letting `docker run` pull an
# unnamed image while the command appears to hang.
docker image inspect $composerSelfImage 2>&1 | Out-Null
if ($LASTEXITCODE -ne 0) {
Write-Host "Composer image not installed locally — fetching $composerSelfImage..."
docker pull $composerSelfImage
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
Write-Host ""
}
# Attach stdin unconditionally, so a pipe reaches the container instead of the
# container getting no stdin at all. Allocate a TTY only when there is one;
# `-t` on a redirected stream fails.
$ttyFlags = @("-i")
if (-not [Console]::IsInputRedirected -and -not [Console]::IsOutputRedirected) {
$ttyFlags += "-t"
}
$dockerArgs = @("run") + $ttyFlags + @("--rm") + $secretArgs + @(
"-v", "${projectRoot}:${containerRoot}",
"-w", $containerRoot,
"-v", "/var/run/docker.sock:/var/run/docker.sock",
$composerSelfImage
) + $args
& docker @dockerArgs
exit $LASTEXITCODE