This commit is contained in:
Jonas Bengtsson
2026-08-30 11:30:09 +02:00
parent 47714fa7e3
commit c139b30f6f
28 changed files with 2100 additions and 34 deletions
+51
View File
@@ -0,0 +1,51 @@
<#
.SYNOPSIS
Removes stack data: volumes and orphans, optionally build artifacts.
.DESCRIPTION
DANGER: this deletes the TimescaleDB data volume (all telemetry data),
the MQTT log volume, and the Loki volume. Users/groups/sessions stored
in Postgres are deleted with it.
-Volumes remove the named volumes (data loss!)
-All additionally remove images and build cache
#>
[CmdletBinding()]
param(
[switch]$Volumes,
[switch]$All
)
$ErrorActionPreference = "Stop"
$StackRoot = Split-Path -Parent $PSScriptRoot
Set-Location $StackRoot
if ($Volumes) {
Write-Warning "This deletes ALL stored data (telemetry, users, groups, sessions, logs)."
$confirm = Read-Host "Type 'delete' to continue"
if ($confirm -ne "delete") {
Write-Host "Aborted."
exit 0
}
}
Write-Host "Removing stack containers..." -ForegroundColor Cyan
docker compose down --remove-orphans
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
if ($Volumes) {
Write-Host "Removing volumes..." -ForegroundColor Cyan
docker compose down --volumes
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
if ($All) {
Write-Host "Removing images and build cache..." -ForegroundColor Cyan
docker compose down --rmi all
docker image prune -f
docker builder prune -f
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
Write-Host "Done." -ForegroundColor Green
+49
View File
@@ -0,0 +1,49 @@
#!/usr/bin/env bash
# Removes stack data: volumes and orphans, optionally build artifacts.
#
# DANGER: deletes the TimescaleDB data volume (all telemetry data), the
# MQTT log volume, and the Loki volume. Users/groups/sessions stored in
# Postgres are deleted with it.
#
# Usage:
# ./scripts/prune.sh # containers only
# ./scripts/prune.sh --volumes # also delete all data (destructive)
# ./scripts/prune.sh --all # also remove images and build cache
set -euo pipefail
StackRoot="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$StackRoot"
Volumes=0
All=0
for arg in "$@"; do
case "$arg" in
--volumes|-v) Volumes=1 ;;
--all|-a) All=1 ;;
*) echo "Unknown option: $arg" >&2; exit 1 ;;
esac
done
if [ "$Volumes" -eq 1 ]; then
echo "This deletes ALL stored data (telemetry, users, groups, sessions, logs)."
read -r -p "Type 'delete' to continue: " confirm
[ "$confirm" = "delete" ] || { echo "Aborted."; exit 0; }
fi
echo "Removing stack containers..."
docker compose down --remove-orphans
if [ "$Volumes" -eq 1 ]; then
echo "Removing volumes..."
docker compose down --volumes
fi
if [ "$All" -eq 1 ]; then
echo "Removing images and build cache..."
docker compose down --rmi all
docker image prune -f
docker builder prune -f
fi
echo "Done."
+84
View File
@@ -0,0 +1,84 @@
<#
.SYNOPSIS
Starts the mqtt-ingester stack on local Docker.
.DESCRIPTION
Loads .env (values already set in the environment take precedence),
verifies that the certificate files exist, then runs docker compose up
with the requested profiles.
.PARAMETER Profiles
Comma-separated compose profiles to enable (e.g. "telemetry").
.EXAMPLE
.\scripts\start.ps1
.\scripts\start.ps1 -Profiles telemetry
#>
[CmdletBinding()]
param(
[string]$Profiles = ""
)
$ErrorActionPreference = "Stop"
# Stack root = parent of the scripts directory.
$StackRoot = Split-Path -Parent $PSScriptRoot
Set-Location $StackRoot
if (-not (Get-Command docker -ErrorAction SilentlyContinue)) {
Write-Error "docker not found in PATH"
}
# Load .env if present; existing environment variables win.
if (Test-Path ".env") {
Get-Content ".env" | ForEach-Object {
$line = $_.Trim()
if ($line -and -not $line.StartsWith("#")) {
$parts = $line -split "=", 2
if ($parts.Length -eq 2) {
$name = $parts[0].Trim()
if (-not (Test-Path "Env:$name")) {
Set-Item -Path "Env:$name" -Value $parts[1].Trim()
}
}
else {
Write-Warning "Ignoring malformed .env line: $line"
}
}
}
}
# Required certificates (see README).
$requiredCerts = @("ca.crt", "client.crt", "client.key", "server.crt", "server.key")
$missing = @()
foreach ($cert in $requiredCerts) {
if (-not (Test-Path (Join-Path "certs" $cert))) {
$missing += $cert
}
}
if ($missing.Count -gt 0) {
Write-Warning "Missing certificates in certs/: $($missing -join ', ')"
Write-Warning "The API will fail to start. See the 'Certificates' section of README.md."
}
# MQTT_BROKER_HOST must be defined somewhere.
if (-not $env:MQTT_BROKER_HOST) {
Write-Warning "MQTT_BROKER_HOST is not set; mqtt-client will exit with an error."
}
$composeArgs = @("compose", "up", "-d", "--build")
if ($Profiles) {
$composeArgs += @("--profile", $Profiles)
}
Write-Host "Starting stack..." -ForegroundColor Cyan
docker @composeArgs
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
Write-Host ""
Write-Host "Services:" -ForegroundColor Cyan
docker compose ps
Write-Host ""
Write-Host "Web UI: http://localhost:8080 (default login admin/admin)" -ForegroundColor Green
Write-Host "API: https://localhost:8443 (mTLS or session cookie)" -ForegroundColor Green
Write-Host "Logs: docker compose logs -f <service>" -ForegroundColor Gray
+63
View File
@@ -0,0 +1,63 @@
#!/usr/bin/env bash
# Starts the mqtt-ingester stack on local Docker.
#
# Loads .env if present (existing environment variables take precedence),
# warns about missing certificates, then runs docker compose up with the
# requested profiles.
#
# Usage:
# ./scripts/start.sh [profiles...]
# ./scripts/start.sh telemetry
set -euo pipefail
StackRoot="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$StackRoot"
Profiles="${*:-}"
if ! command -v docker >/dev/null 2>&1; then
echo "docker not found in PATH" >&2
exit 1
fi
# Load .env if present; existing environment variables win.
if [ -f .env ]; then
while IFS='=' read -r name value; do
# Skip comments and blank lines.
case "$name" in ''|\#*) continue ;; esac
if [ -z "${!name:-}" ]; then
export "$name=$value"
fi
done < <(grep -v -e '^[[:space:]]*$' -e '^[[:space:]]*#' .env)
fi
# Required certificates (see README).
missing=()
for cert in ca.crt client.crt client.key server.crt server.key; do
[ -f "certs/$cert" ] || missing+=("$cert")
done
if [ ${#missing[@]} -gt 0 ]; then
echo "WARNING: missing certificates in certs/: ${missing[*]}" >&2
echo "WARNING: the API will fail to start. See README.md 'Certificates'." >&2
fi
if [ -z "${MQTT_BROKER_HOST:-}" ]; then
echo "WARNING: MQTT_BROKER_HOST is not set; mqtt-client will exit with an error." >&2
fi
ComposeArgs=(compose up -d --build)
if [ -n "$Profiles" ]; then
ComposeArgs+=(--profile "$Profiles")
fi
echo "Starting stack..."
docker "${ComposeArgs[@]}"
echo
echo "Services:"
docker compose ps
echo
echo "Web UI: http://localhost:8080 (default login admin/admin)"
echo "API: https://localhost:8443 (mTLS or session cookie)"
echo "Logs: docker compose logs -f <service>"
+31
View File
@@ -0,0 +1,31 @@
<#
.SYNOPSIS
Stops the mqtt-ingester stack.
.DESCRIPTION
Stops and removes containers and the default network. Volumes
(timescale-data, mqtt-logs, loki-data) are preserved; use prune.ps1
to remove them.
.PARAMETER Profiles
Comma-separated compose profiles (must match the ones used at start
so the same services are addressed).
#>
[CmdletBinding()]
param(
[string]$Profiles = ""
)
$ErrorActionPreference = "Stop"
$StackRoot = Split-Path -Parent $PSScriptRoot
Set-Location $StackRoot
$composeArgs = @("compose", "down", "--remove-orphans")
if ($Profiles) {
$composeArgs += @("--profile", $Profiles)
}
Write-Host "Stopping stack..." -ForegroundColor Cyan
docker @composeArgs
exit $LASTEXITCODE
+24
View File
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
# Stops the mqtt-ingester stack.
#
# Stops and removes containers and the default network. Volumes
# (timescale-data, mqtt-logs, loki-data) are preserved; use prune.sh to
# remove them.
#
# Usage:
# ./scripts/stop.sh [profiles...]
set -euo pipefail
StackRoot="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$StackRoot"
Profiles="${*:-}"
ComposeArgs=(compose down --remove-orphans)
if [ -n "$Profiles" ]; then
ComposeArgs+=(--profile "$Profiles")
fi
echo "Stopping stack..."
docker "${ComposeArgs[@]}"