-
Notifications
You must be signed in to change notification settings - Fork 198
Expand file tree
/
Copy pathrun-lgtm.ps1
More file actions
executable file
·117 lines (100 loc) · 3.39 KB
/
Copy pathrun-lgtm.ps1
File metadata and controls
executable file
·117 lines (100 loc) · 3.39 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env pwsh
param (
[Parameter(Mandatory = $false, Position = 0)] [string] $ReleaseTag = "latest",
[Parameter(Mandatory = $false, Position = 1)] [boolean] $UseLocalImage = $false,
[Parameter(Mandatory = $false)] [switch] $DryRun
)
$supportedContainerRuntime = 'podman', 'docker'
$containers = 'grafana', 'prometheus', 'loki'
$image = "docker.io/grafana/otel-lgtm:${ReleaseTag}"
# prefilled pwd var to avoid repeated calls in build string.moved to top init section or logic
$path = (Get-Location).Path
$containerCommand = $supportedContainerRuntime | ForEach-Object {
(Get-Command $_ -ErrorAction SilentlyContinue).Source
} | Select-Object -first 1
if ($null -eq $containerCommand) {
Write-Error "Unable to find a suitable container runtime such as Docker or Podman. Exiting."
return
}
$containers | ForEach-Object {
$null = New-Item -ItemType Directory -Path "$path/container/$_" -Force
}
if (-Not (Test-Path -Path ".env")) {
New-Item -ItemType File -Path ".env" -Force | Out-Null
}
if ($UseLocalImage) {
if ($containerCommand -eq 'podman') {
$image = "localhost/grafana/otel-lgtm:${ReleaseTag}"
}
else {
$image = "grafana/otel-lgtm:${ReleaseTag}"
}
}
else {
$image = "docker.io/grafana/otel-lgtm:${ReleaseTag}"
if (-Not $DryRun) {
& $containerCommand image pull $image
}
}
# Check if OBI is enabled (from environment or .env file)
$obiFlags = @()
$obiEnabled = $env:ENABLE_OBI -eq 'true'
if (-Not $obiEnabled -and (Test-Path -Path ".env")) {
$obiEnabled = (Get-Content ".env" | Select-String -Pattern '^ENABLE_OBI=true$' -Quiet)
}
if ($obiEnabled) {
Write-Output "OBI eBPF auto-instrumentation enabled. Adding --pid=host --privileged flags."
$obiFlags = @('--pid=host', '--privileged')
# Forward OBI-specific env vars into the container (they are not in .env by default).
# General OTLP vars (OTEL_EXPORTER_OTLP_ENDPOINT, etc.) are forwarded via --env-file .env.
$obiFlags += '-e', 'ENABLE_OBI=true'
Get-ChildItem env: |
Where-Object { $_.Name -match '^(OBI_TARGET|OTEL_EBPF_|ENABLE_LOGS_OBI)' } |
ForEach-Object {
$obiFlags += '-e', "$($_.Name)=$($_.Value)"
}
}
# Allocate TTY only if stdin is interactive
$ttyFlag = @()
if ([Environment]::UserInteractive -and -not [Console]::IsInputRedirected) {
$ttyFlag = @('-t', '-i')
}
$runCommand = @(
'container', 'run'
'--name', 'lgtm'
'--init'
)
# Append OBI-related flags (if any) so each flag is a separate argument
if ($obiFlags.Count -gt 0) {
$runCommand += $obiFlags
}
# Append the remaining fixed arguments
$runCommand += @(
'-p', '3000:3000'
'-p', '3200:3200'
'-p', '4040:4040'
'-p', '4317:4317'
'-p', '4318:4318'
'-p', '9090:9090'
'-e', "CONTAINER_RUNTIME=$(Split-Path -Leaf $containerCommand)"
'-e', "OTEL_COLLECTOR_DEBUG_EXPORTER=$($env:OTEL_COLLECTOR_DEBUG_EXPORTER)"
'--rm'
)
$runCommand += $ttyFlag
$runCommand += @(
'-v', "${path}/container/grafana:/data/grafana"
'-v', "${path}/container/prometheus:/data/prometheus"
'-v', "${path}/container/loki:/data/loki"
'-e', "GF_PATHS_DATA=/data/grafana"
'--env-file', '.env'
${image}
)
if ($DryRun) {
Write-Output "runtime=$(Split-Path -Leaf $containerCommand)"
Write-Output "image=$image"
foreach ($arg in $runCommand) {
Write-Output "arg=$arg"
}
return
}
& $containerCommand @runCommand