Files
Bamboo/cmd/bamboo/main.go
T
VeillaxandClaude Sonnet 5.5 d87c77dc13
CI / test (push) Failing after 57s
Release / release (push) Successful in 5m12s
Add Gitea Actions CI and release workflows and deployment assets
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-26 03:05:34 -06:00

56 lines
1.7 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"
)
// 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")
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()
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)
}