feat(agents): one-line install and Compose files for agents
ci / lint (pull_request) Successful in 10m38s
ci / build (pull_request) Successful in 11m3s
ci / image (pull_request) Successful in 4m40s
ci / test (pull_request) Successful in 17m29s

The API serves /install.sh with its public address and agent image
filled in. The POSIX sh script checks for Linux on a supported CPU,
Docker and Compose, writes /opt/uptimesebi/<kind>[-<name>]/compose.yaml
and a .env readable only by its owner, starts the agent and waits until
it is healthy. Options cover status page hosts with Let's Encrypt, the
plain image for manual updates, the Docker socket for checkers and
several agents per host; running it again changes the settings.

The Compose files in deploy/agent are configured through .env alone, so
they also work without the script. Images follow the platform's channel
(latest, beta or edge). CI shellchecks the rendered script.

Closes #130

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-23 19:07:02 +01:00
1 parent a35dadd8f6
commit 0c382f814c
11 files changed
+562 -1

No files matched your search

+15
View File
@@ -14,6 +14,7 @@ import (
"github.com/jackc/pgx/v5"
"github.com/redis/go-redis/v9"
agentdeploy "git.zb-server.de/ZB-Server/uptimesebi/deploy/agent"
"git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi"
"git.zb-server.de/ZB-Server/uptimesebi/internal/buildinfo"
"git.zb-server.de/ZB-Server/uptimesebi/internal/check"
@@ -147,6 +148,20 @@ func (s *Server) agentUpdate(c *gin.Context) {
c.JSON(http.StatusOK, u)
}
// installScript serves the script that installs a checker or status page
// server with Docker Compose, pointed at this platform.
func (s *Server) installScript(c *gin.Context) {
script, err := agentdeploy.Script(agentdeploy.Install{
APIURL: s.cfg.PublicURL, Image: s.cfg.AgentImage, Tag: agentdeploy.Channel(buildinfo.Version),
})
if err != nil {
internalError(c, err)
return
}
c.Header("Cache-Control", "no-store")
c.Data(http.StatusOK, "text/x-shellscript; charset=utf-8", script)
}
func (s *Server) agentJobs(c *gin.Context) {
var req agentapi.JobsRequest
if !bind(c, &req) {
+23
View File
@@ -3,9 +3,11 @@ package api_test
import (
"context"
"errors"
"io"
"log/slog"
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"
@@ -220,6 +222,27 @@ func TestAgentUpdate(t *testing.T) {
}
}
func TestInstallScript(t *testing.T) {
e := newEnvWith(t, func(c *config.API) {
c.PublicURL = "https://uptime.example.com"
c.AgentImage = "mirror.example/acme/uptimesebi"
})
resp, err := e.srv.Client().Get(e.srv.URL + "/install.sh")
if err != nil {
t.Fatal(err)
}
defer func() { _ = resp.Body.Close() }()
body, _ := io.ReadAll(resp.Body)
if resp.StatusCode != http.StatusOK || !strings.HasPrefix(resp.Header.Get("Content-Type"), "text/x-shellscript") {
t.Fatalf("GET /install.sh = %d %s", resp.StatusCode, resp.Header.Get("Content-Type"))
}
for _, want := range []string{"#!/bin/sh", "API_URL='https://uptime.example.com'", "IMAGE='mirror.example/acme/uptimesebi'", "TAG='edge'"} {
if !strings.Contains(string(body), want) {
t.Errorf("the script lacks %q", want)
}
}
}
func (b *browser) orgID() string {
b.t.Helper()
_, me := b.do("GET", "/api/v1/me", nil)
+1
View File
@@ -100,6 +100,7 @@ func (s *Server) Mount(r gin.IRouter) {
g := r.Group("/", s.sessions.Load(), s.localize(), auth.CSRF(), s.audit())
r.GET("/api/openapi.json", s.openAPIJSON)
r.GET("/install.sh", s.installScript)
g.GET("/api/docs", s.apiDocsPage)
v1 := g.Group("/api/v1")