// 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() upd := selfupdate.Config{Server: "https://git.veillax.com", Repo: "Veillax/bamboo", App: "bamboo", Current: version, Logf: log.Printf} if *autoUpdate { go selfupdate.Run(ctx, upd) } b, err := bamboo.New(bamboo.Config{Hammerhead: strings.TrimRight(*hh, "/"), Token: *token, DataDir: *data, Docker: *dockerOn, Version: version, AutoUpdate: *autoUpdate, UpdateNow: func(ctx context.Context) (string, error) { return selfupdate.CheckOnce(ctx, upd) }}) if err != nil { log.Fatal(err) } b.Run(ctx) }