commit f116aa82b123514c522a053357121611d8a80f92 Author: zeb Date: Sat Nov 14 22:07:23 2026 -0800 agent-builds: initial pipeline (scan & publish upstream rmmagent tags) diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml new file mode 100644 index 0000000..c35e03c --- /dev/null +++ b/.gitea/workflows/build.yml @@ -0,0 +1,129 @@ +name: build-agent +# Builds the TacticalRMM agent (github.com/amidaware/rmmagent) and publishes the +# binaries into this public repo under dist//. The TRMM update shim 302s +# agents to the raw file URLs; agents fetch them anonymously. +# +# Every trigger runs the same idempotent "scan & publish" job: +# - hourly cron : picks up a new upstream release automatically +# - workflow_dispatch : manual run from the Gitea UI +# - push to 'publish' : on-demand check (git push origin main:publish) +# +# A version already tagged in this repo is never rebuilt (idempotent). +# Only the newest upstream semver tag is ever auto-published; the TRMM server +# always tells agents to fetch the newest version, so older ones are not served. + +on: + push: + branches: [publish] + schedule: + - cron: '17 * * * *' + workflow_dispatch: + +jobs: + build: + runs-on: agentbuilds + permissions: + contents: write + steps: + - name: Scan, build, publish + shell: sh + run: | + set -eu + API="https://git.izebra.net" + REPO="izebra_projects/agent-builds" + UP="https://github.com/amidaware/rmmagent" + TOK="$(cat /data/releases-token)" + # token via git's env config, not argv (house pattern) + authgit() { GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=http.extraHeader \ + GIT_CONFIG_VALUE_0="Authorization: token ***" git "$@"; } + W="$(mktemp -d /tmp/agentbuilds.XXXXXX)" + trap 'st=$(cat /tmp/agentbuilds-status 2>/dev/null); [ -n "$st" ] || echo failed > /tmp/agentbuilds-status; rm -rf "$W"' EXIT + rm -f /tmp/agentbuilds-status /tmp/agentbuilds-published + + # --- newest upstream semver tag --- + VER="$(git ls-remote --tags "$UP" | awk '{print $2}' \ + | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+' | sort -uV | tail -1 || true)" + if [ -z "$VER" ]; then + echo "noop" > /tmp/agentbuilds-status + echo "no upstream version found; nothing to do" + exit 0 + fi + echo "newest upstream version: $VER" + + # --- idempotency: already published here? --- + if authgit ls-remote --tags "$API/$REPO.git" | grep -qE "refs/tags/${VER}\$"; then + echo "noop" > /tmp/agentbuilds-status + echo "$VER already published (tag present) - nothing to do" + exit 0 + fi + + # --- build every target (CGO off: pure cross-compile, no qemu) --- + mkdir -p "$W/dist" + git clone --quiet --depth 1 --branch "$VER" "$UP" "$W/src" + ( + cd "$W/src" + for t in linux/amd64 linux/arm64 linux/arm linux/386 \ + darwin/amd64 darwin/arm64 windows/amd64 windows/386; do + GOOS="${t%%/*}"; GOARCH="${t##*/}" + EXE=""; [ "$GOOS" = "windows" ] && EXE=".exe" + echo "=== go build $GOOS/$GOARCH ===" + CGO_ENABLED=0 GOOS="$GOOS" GOARCH="$GOARCH" \ + go build -ldflags "-s -w" \ + -o "$W/dist/tacticalagent-$VER-$GOOS-$GOARCH$EXE" . + done + ) + ( cd "$W/dist" && sha256sum tacticalagent-* > SHA256SUMS ) + + # --- publish into this repo (public; agents fetch the raw URLs) --- + authgit clone --quiet "$API/$REPO.git" "$W/repo" + cd "$W/repo" + git config user.name "agent-builds" + git config user.email "agent-builds@izebra.net" + mkdir -p "dist/$VER" + cp "$W/dist"/tacticalagent-* "dist/$VER"/ + cp "$W/dist/SHA256SUMS" "dist/$VER/" + { + echo "# agent-builds: published versions (the tag is the git ref used in raw URLs)" + [ -f dist/INDEX ] && grep -v '^#' dist/INDEX + printf '%s %s\n' "$VER" "$(date -u +%Y-%m-%dT%H:%M:%SZ)" + } > dist/INDEX + git add -A + git commit -m "publish $VER (built from upstream amidaware/rmmagent at that tag)" + git tag "$VER" + authgit push origin main + authgit push origin "$VER" + + # --- verify exactly what agents will do: anonymous raw fetch --- + for f in "$W/dist"/tacticalagent-*; do + n="$(basename "$f")" + code="$(curl -s -o /dev/null -w '%{http_code}' "$API/$REPO/raw/branch/$VER/dist/$VER/$n")" + if [ "$code" != "200" ]; then + echo "RAW FETCH FAILED: $n -> HTTP $code" + exit 1 + fi + done + echo "published" > /tmp/agentbuilds-status + echo "$VER" > /tmp/agentbuilds-published + echo "PUBLISHED $VER: $(ls "$W/dist" | grep -c '^tacticalagent-') binaries + SHA256SUMS; raw URLs verified 200" + + - name: Announce + shell: sh + run: | + if [ -f /tmp/agentbuilds-published ]; then + VER="$(cat /tmp/agentbuilds-published)" + curl -s -m 5 "http://10.2.1.10/izebra" \ + -H "X-Title: agent-builds: $VER published" \ + -H 'X-Priority: 3' -H 'X-Tag: rocket' \ + --data "Published TacticalRMM agent $VER (8 targets) to git.izebra.net/izebra_projects/agent-builds. RMM2 LATEST_AGENT_VER is 2.12.0; bump it to $VER when the rollout is ready." || true + fi + + - name: Alert + shell: sh + run: | + st="$(cat /tmp/agentbuilds-status 2>/dev/null || echo failed)" + if [ "$st" = "failed" ]; then + curl -s -m 5 "http://10.2.1.10/izebra" \ + -H 'X-Title: agent-builds pipeline FAILED' \ + -H 'X-Priority: 4' -H 'X-Tag: red_circle' \ + --data "Build/publish job failed on git.izebra.net/izebra_projects/agent-builds - check the run log (runner: agentbuilds on DKR4)." || true + fi diff --git a/README.md b/README.md new file mode 100644 index 0000000..42edeef --- /dev/null +++ b/README.md @@ -0,0 +1,66 @@ +# agent-builds + +Self-service distribution of [TacticalRMM agent](https://github.com/amidaware/rmmagent) +binaries, built on every tag of the upstream project and published here. + +This exists because upstream has never published the Linux/macOS release assets, +so TRMM's built-in "Update agent" 404s for Linux and macOS. The RMM2 sponsorship +shim now 302s agent update fetches for `plat=linux|darwin` to the raw file URLs +in this repo. The repo is public on purpose: agents follow the 302 anonymously. + +## Fetch URL format (what the shim 302s to) + +``` +https://git.izebra.net/izebra_projects/agent-builds/raw/branch/v{ver}/dist/v{ver}/tacticalagent-v{ver}-{plat}-{arch} +``` + +- `ver` = `X.Y.Z` (the git tag, without leading `v` in the version field) +- `plat` = `linux` | `darwin` +- `arch` = `amd64` | `arm64` | `arm` | `386` +- No auth. Windows is untouched (still served from the upstream GitHub release). + +## What is built + +8 targets per version, `CGO_ENABLED=0`, `-ldflags "-s -w"` (no qemu needed — +Go cross-compiles natively): + +| OS | archs | +|---------|--------------------| +| linux | amd64 arm64 arm 386 | +| darwin | amd64 arm64 | +| windows | amd64 386 | + +Each `dist/v{ver}/` also contains `SHA256SUMS` for the binaries. The agent does +not verify checksums (upstream behavior); the file is for humans and future tooling. + +## Triggers (all run the same idempotent scan & publish job) + +| trigger | effect | +|-------------------|---------------------------------------------------| +| hourly cron `:17` | newest upstream semver tag not yet tagged here is built + published | +| UI "Run workflow" | same scan, on demand | +| push to `publish` branch | same scan, on demand: `git push origin main:publish` | + +A version already tagged in this repo is never rebuilt. Only the **newest** +upstream tag is ever auto-published: the TRMM server always tells agents to +fetch the newest version, so older versions are never requested. + +## Rolling a new version out to the fleet + +Publishing here is not enough by itself. The RMM2 server constant +`LATEST_AGENT_VER` (`/rmm/api/tacticalrmm/tacticalrmm/local_settings.py`, +currently `2.12.0`) must be bumped to the new version and the API restarted — +that constant is what `get_agent_url()` serves to agents. Until the bump, +agents keep fetching `2.12.0` (which this repo serves fine). + +## Runner + +The build job runs on the `agentbuilds` act_runner (container `agentbuilds-runner`, +image `agentbuilds-runner:0.1` = act_runner 0.2.13 + Go 1.24 + git/curl/jq/bash) +on DKR4. Runner stack: `~/agentbuilds-runner/` (compose, config, token files). + +## Upstream + +`github.com/amidaware/rmmagent` — the agent is Go, `go 1.20`, root package +`main`. The binary self-reports the version hard-coded in `main.go` at the +pinned tag, so a build of tag `vX` always reports `X` (verified per tag).