Files
Blacktip/cmd/blacktip/main.go
T
VeillaxandClaude Sonnet 5.5 e951d22687
CI / test (push) Canceled after 14m46s
Release / release (push) Successful in 6m4s
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:30 -06:00

65 lines
2.5 KiB
Go

// Blacktip is the edge: run it on a public server that owns the IP addresses.
package main
import (
"context"
"flag"
"log"
"os"
"os/signal"
"strings"
"git.veillax.com/Veillax/blacktip"
"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("BLACKTIP_HAMMERHEAD", ""), "URL of hammerhead, e.g. http://10.0.0.5:8080")
token := flag.String("token", env("BLACKTIP_TOKEN", ""), "edge token from the hammerhead UI")
tun := flag.String("tunnel", env("BLACKTIP_TUNNEL", ":51820"), "UDP listen address for the WireGuard tunnel (open this UDP port in your firewall)")
data := flag.String("data", env("BLACKTIP_DATA", "./blacktip-data"), "directory for the WireGuard key and certificates")
dockerOn := flag.Bool("docker", os.Getenv("BLACKTIP_DOCKER") == "1", "report local Docker containers so they can be picked as targets in the UI")
traefikPath := flag.String("traefik", os.Getenv("BLACKTIP_TRAEFIK"), "path to a Traefik binary: serve http/https resources with Traefik instead of the built-in proxy")
acmeDNS := flag.String("acme-dns", os.Getenv("BLACKTIP_ACME_DNS"), "with -traefik: DNS-challenge provider (e.g. cloudflare) for wildcard certificates; its credentials go in this process's environment")
noACME := flag.Bool("no-acme", false, "with -traefik: serve Traefik's self-signed certificate instead of requesting Let's Encrypt ones")
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("blacktip " + version + "\n")
return
}
if *hh == "" || *token == "" {
flag.Usage()
os.Exit(2)
}
b, err := blacktip.New(blacktip.Config{
Hammerhead: strings.TrimRight(*hh, "/"), Token: *token, TunnelAddr: *tun, DataDir: *data, Docker: *dockerOn,
Traefik: blacktip.TraefikConfig{Path: *traefikPath, ACMEDNS: *acmeDNS, NoACME: *noACME},
})
if err != nil {
log.Fatal(err)
}
log.Printf("blacktip %s starting", version)
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
defer stop()
if err := b.Run(ctx); err != nil {
log.Fatal(err)
}
}