POC : Observability infrastructure managment
sope README.md
10 kB · 343 lines
Markdown
at main

sope #

Deploy an observability hub / satellites stack with Nix (dockerTools), Rust, and Docker Compose.

  • Hub: Grafana + Loki + Tempo + Prometheus (remote_write) + Caddy (Bearer auth)
  • Satellite: Grafana Alloy + cAdvisor (node/container metrics, Docker logs, local OTLP) push to the hub
  • Hardening: no privileged, Docker socket read-only, cap_drop: ALL, read_only, no-new-privileges (UID 0 only so named Docker volumes stay writable)

Prerequisites #

Architecture mismatch (crash-loop exit 255) #

If containers restart with exec format error, images were built for the wrong CPU (e.g. arm64 from Apple Silicon loaded on an x86_64 VPS). sope deploy probes uname -m and builds packages.x86_64-linux.images or packages.aarch64-linux.images (separate Docker Nix store per arch). Redeploy without --skip-build.

Operator machine (where you run sope) #

Need Why
Nix (flakes) Build dockerTools images (sope build)
Docker + Compose v2 Load images locally, then docker save them for transfer
OpenSSH client (ssh, plus tar) All remote work goes through SSH
SSH key in the agent / default identity sope uses BatchMode=yes — no password / interactive prompt

Check once:

ssh -o BatchMode=yes deploy@hub.example.com 'docker compose version && id'

On macOS, image builds run inside a nixos/nix container (dockerTools targets Linux); local Docker is still required. Force arch with sope build --arch amd64.

How sope reaches the servers #

sope never opens its own agent or API on the nodes. From the operator machine it:

  1. SSH as user@host from [hub] / each [[satellites]] (BatchMode=yes, IPQoS=none)
  2. Uploads Nix .tar.gz images over ssh + cat (no scp — macOS OpenSSH often fails with Result too large) into a staging dir {path}.next-<pid> — not into the live path
  3. Pipes tar → ssh … tar -xf configs into that same stage
  4. Atomic activate: docker load from stage → rename stage → {path} → docker compose up -d. On failure: delete the stage, restore {path}.prev if the stack already existed, and remove loaded images on a first-time deploy that never went live

sope ui uses the same SSH path; it only binds a local web UI (127.0.0.1).

There is no reverse tunnel, no sope daemon on the servers, and no need for the nodes to SSH back to you.

On each hub / satellite host #

Need Detail
SSH server reachable from the operator Port 22 (or your ~/.ssh/config / ProxyJump)
Account = user in sope.toml Default deploy — not necessarily root
Write to path e.g. /opt/sope/hub or /opt/sope/sat (mkdir -p + extract)
Docker Engine docker load, run containers
Compose v2 plugin docker compose (not legacy docker-compose)
Permission to talk to Docker Typically membership in group docker (or root)

Suggested bootstrap on a fresh Linux box:

# as root once
useradd -m -s /bin/bash -G docker deploy
mkdir -p /opt/sope && chown deploy:deploy /opt/sope
# install Docker Engine + compose plugin, then:
# put the operator's public key in ~deploy/.ssh/authorized_keys

Firewall / routing (runtime, not SSH):

  • Hub: expose ingest ports used by satellites — by default 9090 (Prometheus remote_write), 3100 (Loki), 4317/4318 (OTLP) via Caddy, plus Grafana (3000 unless rebound).
  • Satellites → hub: outbound TCP to those hub ports; satellites do not need inbound SSH from the hub.
  • OTLP on a satellite: published only on 127.0.0.1 (apps on that machine).

Install with Nix #

Repo: tangled.org/primica.tngl.sh/sope
Flakes required (experimental-features = nix-command flakes).

One-shot (no install) #

nix run 'git+https://tangled.org/primica.tngl.sh/sope' -- --help
nix run 'git+https://tangled.org/primica.tngl.sh/sope' -- status

Tarball (lockable HTTP flake):

nix run 'https://tangled.org/primica.tngl.sh/sope/archive/main.tar.gz' -- --help

Install into your profile #

nix profile install 'git+https://tangled.org/primica.tngl.sh/sope'
sope --help
man sope
man 5 sope.toml

Update later:

nix profile upgrade sope
# or reinstall:
nix profile remove sope
nix profile install 'git+https://tangled.org/primica.tngl.sh/sope'

As a flake input (NixOS / Home Manager) #

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    sope.url = "git+https://tangled.org/primica.tngl.sh/sope";
    # optional: sope.inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = { nixpkgs, sope, ... }: {
    nixosConfigurations.box = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        ({ pkgs, ... }: {
          nixpkgs.overlays = [ sope.overlays.default ];
          environment.systemPackages = [ pkgs.sope ];
        })
      ];
    };
  };
}

Without overlay:

({ pkgs, ... }: {
  environment.systemPackages = [
    sope.packages.${pkgs.system}.default
  ];
})

Home Manager:

({ pkgs, ... }: {
  home.packages = [ sope.packages.${pkgs.system}.default ];
})

From a local checkout #

nix run . -- --help
nix profile install .
nix build .#sope

Configuration (sope.toml) #

cp sope.toml.example sope.toml

The file has one hub and as many satellites as [[satellites]] blocks.

Section Role
[hub] SSH host + hub paths/ports
[auth] Shared Bearer token (all satellites → hub)
[grafana] Grafana admin
[[satellites]] One block per machine (unique name)

Hub + satellite on the same server #

Point a [[satellites]] host at the same value as [hub].host, keep a different path (defaults /opt/sope/hub vs /opt/sope/sat are fine).

[hub]
host = "obs.example.com"
path = "/opt/sope/hub"

[[satellites]]
name = "local"
host = "obs.example.com"
path = "/opt/sope/sat"

sope then:

  • pushes Alloy to 127.0.0.1 (local Caddy)
  • publishes satellite OTLP on 127.0.0.1:14317 / :14318 (hub keeps :4317 / :4318)

Multiple satellites #

Repeat the [[satellites]] block (double brackets = TOML array entry):

[hub]
host = "hub.example.com"
user = "deploy"
path = "/opt/sope/hub"

[auth]
token = "a-long-secret"

[grafana]
admin_user = "admin"
admin_password = "change-me"

[[satellites]]
name = "node-a"
host = "node-a.example.com"
user = "deploy"
path = "/opt/sope/sat"

[[satellites]]
name = "node-b"
host = "node-b.example.com"
user = "deploy"
path = "/opt/sope/sat"

[[satellites]]
name = "gpu-1"
host = "10.0.0.42"
user = "deploy"
# path optional → /opt/sope/sat
  • name is the id passed to sope deploy satellite --name … (need not be the hostname).
  • sope deploy (no args) deploys the hub then every [[satellites]].
  • Single node: sope deploy satellite --name gpu-1.

Field details: man 5 sope.toml (after Nix install) or sope.toml.example.

Usage #

sope build
sope render --out .sope          # preview artefacts
sope plan                        # dry-run vs remote
sope deploy                      # only needed changes
sope deploy --full               # force atomic redeploy
sope deploy hub
sope deploy satellite --name node-b --skip-build
sope status
sope status satellite --name node-a
sope ui                          # local UI http://127.0.0.1:8743
sope destroy all --yes           # teardown: down -v + images + rm path

Changing e.g. grafana.admin_password → sope plan lists hub docker-compose.yml + grafana/grafana.ini; sope deploy syncs those files and runs compose up -d (no image rebuild).

State is stored in sope.state.json next to sope.toml (like Terraform). Plan compares the desired render to that file. Use --refresh to re-read remotes into the state first.

Via Cargo / Nix:

cargo run -- deploy
nix run . -- deploy

Manual pages #

Page Content
man sope Overview
man sope-build Build images
man sope-render Generate artefacts
man sope-deploy SSH deploy
man sope-status Compose status
man sope-ui Local web UI (Topcoat)
man sope-destroy Remote teardown with no leftover traces
man 5 sope.toml Config format (multi-satellite)

With the Nix package (nix build .#sope / nix profile install .):

man sope
man 5 sope.toml

Locally without install: man ./man/sope.1 or man ./man/sope.toml.5.

Architecture #

satellite (Alloy + cAdvisor) --Bearer--> hub:9090  Prometheus remote_write
                             --Bearer--> hub:3100  Loki push
                             --Bearer--> hub:4317  Tempo OTLP
                                              |
                                         Grafana :3000

Hub backends are not exposed directly: Caddy terminates Bearer auth.

On a satellite, OTLP is published only on 127.0.0.1; cAdvisor has no public port (scraped by Alloy).

Nix images #

Flake attribute Docker image
.#prometheus sope/prometheus
.#loki sope/loki
.#tempo sope/tempo
.#grafana sope/grafana
.#alloy sope/alloy
.#cadvisor sope/cadvisor
.#caddy sope/caddy
.#images linkFarm of all tar.gz

Web UI (sope ui) #

Local admin console (Topcoat):

  • Compose status (hub / satellites) over SSH
  • start / stop / restart Compose (separate from deploy)
  • Nix build with live logs (/build)
  • structured editing of sope.toml (/settings, .bak backup)
  • deploy hub / satellite / all
  • destroy hub / satellite / all (confirmation required)

Listens on 127.0.0.1:8743 by default (--bind / --port). No auth — keep it on localhost.

Destroy (sope destroy) #

Remote teardown with no leftover sope traces:

  1. docker compose down -v --remove-orphans
  2. rm -rf the remote path
  3. docker image rm deployed sope/* images

all destroys satellites then the hub. CLI: --yes required. UI: confirm checkbox.

sope ui
# or: just ui

Development #

nix develop
cargo run -- --help