Files
Bamboo/cmd/bamboo/main.go
T
VeillaxandClaude Sonnet 5.5 3dc8d1af46
CI / test (push) Successful in 5m57s
Release / release (push) Failing after 19m45s
Add opt-in auto-update from Gitea releases
The program now lives in /usr/local/lib/bamboo and is owned by its service user so it can replace itself.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-26 14:00:42 -06:00

61 lines
2.1 KiB
Go

// Bamboo is the site agent: run it inside a private network to expose services from there.
package main
import (
"context"
"flag"
"log"
"os"
"os/signal"
"strings"
"git.veillax.com/Veillax/bamboo"
"git.veillax.com/Veillax/reef/dotenv"
"git.veillax.com/Veillax/reef/selfupdate"
)
// version is set at build time (deploy/build.sh).
var version = "dev"
func env(k, def string) string {
if v := os.Getenv(k); v != "" {
return v
}
return def
}
func main() {
// secrets (tokens, DNS-provider credentials) can live in a .env file instead of the command line
envFile := dotenv.ArgPath(os.Args[1:], ".env")
if _, err := dotenv.Load(envFile); err != nil {
log.Fatalf("read %s: %v", envFile, err)
}
hh := flag.String("hammerhead", env("BAMBOO_HAMMERHEAD", ""), "URL of hammerhead")
token := flag.String("token", env("BAMBOO_TOKEN", ""), "site token from the hammerhead UI")
data := flag.String("data", env("BAMBOO_DATA", "./bamboo-data"), "directory for this agent's WireGuard key")
dockerOn := flag.Bool("docker", os.Getenv("BAMBOO_DOCKER") == "1", "report local Docker containers so they can be picked as targets in the UI")
flag.String("env", ".env", "file to read secrets and settings from")
autoUpdate := flag.Bool("auto-update", os.Getenv("BAMBOO_AUTO_UPDATE") == "1", "check for new releases every few hours and update and restart by itself (Linux and macOS)")
showVersion := flag.Bool("version", false, "print the version and exit")
flag.Parse()
if *showVersion {
os.Stdout.WriteString("bamboo " + version + "\n")
return
}
if *hh == "" || *token == "" {
flag.Usage()
os.Exit(2)
}
log.Printf("bamboo %s starting", version)
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
defer stop()
if *autoUpdate {
go selfupdate.Run(ctx, selfupdate.Config{Server: "https://git.veillax.com", Repo: "Veillax/bamboo", App: "bamboo", Current: version, Logf: log.Printf})
}
b, err := bamboo.New(bamboo.Config{Hammerhead: strings.TrimRight(*hh, "/"), Token: *token, DataDir: *data, Docker: *dockerOn})
if err != nil {
log.Fatal(err)
}
b.Run(ctx)
}