Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ docker build . -t grafana/otel-lgtm
mise build-lgtm
```

> [!TIP]
> If you built your image locally, you can use the `run-lgtm` scripts with
> the parameters `latest true` to run your local image.

## Build and run the example app

> [!TIP]
Expand Down
13 changes: 12 additions & 1 deletion build-lgtm.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
#!/bin/bash

set -euo pipefail

RELEASE=${1:-latest}

docker buildx build -f docker/Dockerfile docker --tag grafana/otel-lgtm:"${RELEASE}"
if command -v docker >/dev/null 2>&1; then
RUNTIME=docker
elif command -v podman >/dev/null 2>&1; then
RUNTIME=podman
else
echo "Unable to find a suitable container runtime such as Docker or Podman. Exiting."
exit 1
fi

$RUNTIME buildx build -f docker/Dockerfile docker --tag grafana/otel-lgtm:"${RELEASE}"
6 changes: 3 additions & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ARG PYROSCOPE_VERSION=v1.15.0
ARG OPENTELEMETRY_COLLECTOR_VERSION=v0.138.0

# hadolint global ignore=DL3059
FROM redhat/ubi9:9.6-1760340943@sha256:dec374e05cc13ebbc0975c9f521f3db6942d27f8ccdf06b180160490eef8bdbc AS builder
FROM docker.io/redhat/ubi9:9.6-1760340943@sha256:dec374e05cc13ebbc0975c9f521f3db6942d27f8ccdf06b180160490eef8bdbc AS builder

RUN mkdir /otel-lgtm

Expand Down Expand Up @@ -57,7 +57,7 @@ COPY download-grafana.sh \
./

# TARGETARCH is automatically detected and set by the Docker daemon during the build process. If the build starts
# on an amd64 architecture, than the TARGETARCH will be set to `amd64`.
# on an amd64 architecture, then the TARGETARCH will be set to `amd64`.
# More details on the variables can be found here: https://docs.docker.com/desktop/extensions-sdk/extensions/multi-arch/
ARG TARGETARCH
ENV TARGETARCH=${TARGETARCH}
Expand All @@ -84,7 +84,7 @@ RUN ./download-otelcol.sh $OPENTELEMETRY_COLLECTOR_VERSION
COPY grafana-datasources.yaml /otel-lgtm/grafana/conf/provisioning/datasources/
COPY grafana-dashboards.yaml /otel-lgtm/grafana/conf/provisioning/dashboards/

FROM redhat/ubi9-micro:9.6-1760515026@sha256:aff810919642215e15c993b9bbc110dbcc446608730ad24499dafd9df7a8f8f4
FROM docker.io/redhat/ubi9-micro:9.6-1760515026@sha256:aff810919642215e15c993b9bbc110dbcc446608730ad24499dafd9df7a8f8f4

RUN mkdir /otel-lgtm
WORKDIR /otel-lgtm
Expand Down
10 changes: 9 additions & 1 deletion run-lgtm.cmd
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
@echo off

powershell -ExecutionPolicy ByPass -NoProfile -Command "& '%~dp0\run-lgtm.ps1'"
set "releasetag=%~1"
set "local=%~2"

if "%releasetag%"=="" set "releasetag=latest"
if "%localimg%"=="" set "localimg=0"
if "%localimg%"=="false" set "localimg=0"
if "%localimg%"=="true" set "localimg=1"

powershell -ExecutionPolicy ByPass -NoProfile -Command "& '%~dp0\run-lgtm.ps1' -ReleaseTag '%releasetag%' -UseLocalImage %localimg%"
exit /b %ERRORLEVEL%
31 changes: 25 additions & 6 deletions run-lgtm.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
$release_tag = "latest"
param (
[Parameter(Mandatory = $false, Position = 0)] [string] $ReleaseTag = "latest",
[Parameter(Mandatory = $false, Position = 1)] [boolean] $UseLocalImage = $false
)

$supportedContainerRuntime = 'podman', 'docker'
$containers = 'grafana', 'prometheus', 'loki'
$image = "docker.io/grafana/otel-lgtm:$release_tag"
$image = "docker.io/grafana/otel-lgtm:${ReleaseTag}"

# prefilled pwd var to avoid repeted calls in build string.moved to top init section or logic
$path = (Get-Location).Path
Expand All @@ -12,18 +15,33 @@ $containerCommand = $supportedContainerRuntime | ForEach-Object {
} | Select-Object -first 1

if ($null -eq $containerCommand) {
Write-Error "Please install Podman or docker"
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
}

& $containerCommand pull $image
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}"
& $containerCommand image pull $image
}

$runCommand = @(
'run'
'container', 'run'
'--name', 'lgtm',
'-p', '3000:3000'
'-p', '4317:4317'
Expand All @@ -34,7 +52,8 @@ $runCommand = @(
'-v', "${path}/container/prometheus:/data/prometheus"
'-v', "${path}/container/loki:/data/loki"
'-e', "GF_PATHS_DATA=/data/grafana"
$image
'--env-file', '.env'
${image}
)

& $containerCommand @runCommand
47 changes: 40 additions & 7 deletions run-lgtm.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,54 @@
#!/bin/bash

set -euo pipefail

RELEASE=${1:-latest}
LOCAL_VOLUME=${PWD}/container
# Only set this to "true" if you built the image with the 'build-lgtm.sh' script
USE_LOCAL_IMAGE=${2:-false}

for dir in grafana prometheus loki; do
test -d "${LOCAL_VOLUME}"/${dir} || mkdir -p "${LOCAL_VOLUME}"/${dir}
done

test -f .env || touch .env

docker pull docker.io/grafana/otel-lgtm:"${RELEASE}"
if command -v docker >/dev/null 2>&1; then
RUNTIME=docker
MOUNT_OPTS=rw
elif command -v podman >/dev/null 2>&1; then
RUNTIME=podman
# Fedora, by default, runs with SELinux on. We require the "z" option for bind mounts.
# See: https://docs.docker.com/engine/storage/bind-mounts/#configure-the-selinux-label
# See: https://docs.podman.io/en/stable/markdown/podman-run.1.html section "Labeling Volume Mounts"
MOUNT_OPTS="rw,z"
else
echo "Unable to find a suitable container runtime such as Docker or Podman. Exiting."
exit 1
fi

touch .env
if [ "$USE_LOCAL_IMAGE" = true ]; then
if [ "$RUNTIME" = "podman" ]; then
# Default address when building with Podman.
IMAGE="localhost/grafana/otel-lgtm:latest"
else
IMAGE="grafana/otel-lgtm:latest"
fi
else
IMAGE="docker.io/grafana/otel-lgtm:${RELEASE}"
$RUNTIME image pull "$IMAGE"
fi

docker run \
$RUNTIME container run \
--name lgtm \
-p 3000:3000 \
-p 4317:4317 \
-p 4318:4318 \
--rm \
-ti \
-v "$PWD"/container/grafana:/data/grafana \
-v "$PWD"/container/prometheus:/data/prometheus \
-v "$PWD"/container/loki:/data/loki \
-v "${LOCAL_VOLUME}"/grafana:/data/grafana:"${MOUNT_OPTS}" \
-v "${LOCAL_VOLUME}"/prometheus:/data/prometheus:"${MOUNT_OPTS}" \
-v "${LOCAL_VOLUME}"/loki:/data/loki:"${MOUNT_OPTS}" \
-e GF_PATHS_DATA=/data/grafana \
--env-file .env \
docker.io/grafana/otel-lgtm:"${RELEASE}"
"$IMAGE"
20 changes: 17 additions & 3 deletions scripts/super-linter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,27 @@ set -euo pipefail

pushd "$(dirname "$0")/.."

docker pull ghcr.io/super-linter/super-linter:latest
if command -v docker >/dev/null 2>&1; then
RUNTIME=docker
MOUNT_OPTS=rw
elif command -v podman >/dev/null 2>&1; then
RUNTIME=podman
# Fedora, by default, runs with SELinux on. We require the "z" option for bind mounts.
# See: https://docs.docker.com/engine/storage/bind-mounts/#configure-the-selinux-label
# See: https://docs.podman.io/en/stable/markdown/podman-run.1.html section "Labeling Volume Mounts"
MOUNT_OPTS="rw,z"
else
echo "Unable to find a suitable container runtime such as Docker or Podman. Exiting."
exit 1
fi

docker run --rm \
$RUNTIME image pull ghcr.io/super-linter/super-linter:latest

$RUNTIME container run --rm \
-e RUN_LOCAL=true \
-e DEFAULT_BRANCH=main \
--env-file ".github/super-linter.env" \
-v "$(pwd)":/tmp/lint \
-v "$(pwd)":/tmp/lint:"${MOUNT_OPTS}" \
ghcr.io/super-linter/super-linter:latest

popd
Loading