feat(console): install instructions for new agents, outdated agents
Creating a checker or status page server now shows how to install it next to the one-time token: the one-liner of the platform's install script and the Compose files with .env, with the token and kind filled in, and a switch between the self-updating and the plain image. Agents behind the platform's release are marked outdated in the organization's and the admin's agent lists, which also show each agent's release and the platform's. Closes #131 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
0c382f814c
commit
e281bcd604
8 files changed
+931
-456
No files matched your search
@@ -22,6 +22,7 @@ import (
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/schedule"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/store"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/tenant"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/web"
|
||||
)
|
||||
|
||||
// AgentTokenPrefix marks agent tokens, distinct from user API tokens.
|
||||
@@ -148,6 +149,26 @@ func (s *Server) agentUpdate(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, u)
|
||||
}
|
||||
|
||||
// installView is what the console shows to install a new agent.
|
||||
func (s *Server) installView() web.InstallView {
|
||||
v := web.InstallView{
|
||||
ScriptURL: strings.TrimSuffix(s.cfg.PublicURL, "/") + "/install.sh",
|
||||
APIURL: strings.TrimSuffix(s.cfg.PublicURL, "/"),
|
||||
Image: s.cfg.AgentImage,
|
||||
Channel: agentdeploy.Channel(buildinfo.Version),
|
||||
Compose: map[string]string{},
|
||||
}
|
||||
if buildinfo.Version != "dev" {
|
||||
v.Release = buildinfo.Version
|
||||
}
|
||||
for _, kind := range []string{"checker", "statuspage"} {
|
||||
if c, err := agentdeploy.Compose(kind); err == nil {
|
||||
v.Compose[kind] = string(c)
|
||||
}
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// 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) {
|
||||
|
||||
@@ -628,7 +628,7 @@ func (s *Server) adminOrgsPage(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (s *Server) buildRegionsView(ctx context.Context, regions []store.Region, agents []store.ListAgentsRow, apiBase, next string, manageable func(store.Region) bool) (web.RegionsView, error) {
|
||||
v := web.RegionsView{APIBase: apiBase, Next: next}
|
||||
v := web.RegionsView{APIBase: apiBase, Next: next, Install: s.installView()}
|
||||
never := i18n.T(ctx, "tokens.never")
|
||||
for _, r := range regions {
|
||||
n, err := s.sched.Instances(ctx, r.ID.String())
|
||||
@@ -646,7 +646,8 @@ func (s *Server) buildRegionsView(ctx context.Context, regions []store.Region, a
|
||||
if a.LastSeenAt != nil {
|
||||
seen = a.LastSeenAt.Format(time.DateTime)
|
||||
}
|
||||
wa := web.Agent{ID: a.ID.String(), Kind: a.Kind, Name: a.Name, Region: deref(a.RegionName), Prefix: a.Prefix, LastSeen: seen}
|
||||
wa := web.Agent{ID: a.ID.String(), Kind: a.Kind, Name: a.Name, Region: deref(a.RegionName), Prefix: a.Prefix, LastSeen: seen, Release: deref(a.Release)}
|
||||
wa.Outdated = v.Install.Release != "" && wa.Release != "" && wa.Release != "dev" && wa.Release != v.Install.Release
|
||||
if a.Kind == "checker" && a.OrgID != nil {
|
||||
wa.AllowPrivate = &a.AllowPrivate
|
||||
}
|
||||
|
||||
@@ -4,11 +4,15 @@ import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"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/config"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/store"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/tenant"
|
||||
)
|
||||
@@ -153,3 +157,46 @@ func (b *browser) userIDSelf() uuid.UUID {
|
||||
_, me := b.do("GET", "/api/v1/me", nil)
|
||||
return uuid.MustParse(me["id"].(string))
|
||||
}
|
||||
|
||||
func TestAgentInstallConsole(t *testing.T) {
|
||||
e := newEnvWith(t, func(c *config.API) { c.PublicURL = "https://uptime.example.com" })
|
||||
owner := e.browser(t)
|
||||
owner.signup("o@"+uniq("inst")+".test", uniq("inst-"))
|
||||
st, body := owner.do("POST", "/api/v1/org/agents", map[string]any{"kind": "statuspage", "name": "pages"})
|
||||
if st != http.StatusCreated {
|
||||
t.Fatalf("create agent = %d %v", st, body)
|
||||
}
|
||||
tok := body["token"].(string)
|
||||
|
||||
old := buildinfo.Version
|
||||
buildinfo.Version = "v1.4.2"
|
||||
t.Cleanup(func() { buildinfo.Version = old })
|
||||
_, _, html := owner.page("/settings/regions")
|
||||
for _, want := range []string{
|
||||
"curl -fsSL https://uptime.example.com/install.sh | sudo sh -s -- {kind} --token {token}{manual}",
|
||||
`data-channel="latest"`, "Update automatically", "}-statuspage:${UPTIME_AGENT_TAG",
|
||||
"The platform runs v1.4.2.",
|
||||
} {
|
||||
if !strings.Contains(html, want) {
|
||||
t.Errorf("the page lacks %q", want)
|
||||
}
|
||||
}
|
||||
if strings.Contains(html, ">· outdated<") {
|
||||
t.Error("an agent that never reported is marked outdated")
|
||||
}
|
||||
|
||||
client := agentapi.NewClient(e.srv.URL, tok, uuid.New(), "v1.4.1").WithHTTPClient(e.srv.Client())
|
||||
if _, err := client.Hello(context.Background()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, _, html := owner.page("/settings/regions"); !strings.Contains(html, "v1.4.1") || !strings.Contains(html, "outdated") {
|
||||
t.Error("an agent behind the platform is not marked outdated")
|
||||
}
|
||||
current := agentapi.NewClient(e.srv.URL, tok, uuid.New(), "v1.4.2").WithHTTPClient(e.srv.Client())
|
||||
if _, err := current.Hello(context.Background()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, _, html := owner.page("/settings/regions"); strings.Contains(html, "· outdated") {
|
||||
t.Error("an agent on the platform's release is marked outdated")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user