Initial commit: AetherForge Linux (forge-mesh) v0.1.0-dev
Some checks failed
Test / test (push) Has been cancelled
Some checks failed
Test / test (push) Has been cancelled
This commit is contained in:
122
cmd/forge/main.go
Normal file
122
cmd/forge/main.go
Normal file
@@ -0,0 +1,122 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"forge-mesh/internal/config"
|
||||
"forge-mesh/internal/db"
|
||||
"forge-mesh/internal/forge"
|
||||
)
|
||||
|
||||
const defaultVersion = "0.1.0-dev"
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
printUsage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
switch os.Args[1] {
|
||||
case "build":
|
||||
runBuild(os.Args[2:])
|
||||
case "pubkey":
|
||||
runPubkey(os.Args[2:])
|
||||
default:
|
||||
printUsage()
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func runBuild(args []string) {
|
||||
fs := flag.NewFlagSet("build", flag.ExitOnError)
|
||||
configPath := fs.String("config", "data/config.json", "config path")
|
||||
version := fs.String("version", defaultVersion, "build version")
|
||||
public := fs.Bool("public", true, "mark builds as public")
|
||||
_ = fs.Parse(args)
|
||||
|
||||
cfg, err := config.Load(*configPath)
|
||||
if err != nil {
|
||||
log.Fatalf("config: %v", err)
|
||||
}
|
||||
if err := cfg.EnsureDataDirs(); err != nil {
|
||||
log.Fatalf("data dirs: %v", err)
|
||||
}
|
||||
|
||||
conn, err := db.Open(cfg.DatabasePath)
|
||||
if err != nil {
|
||||
log.Fatalf("database: %v", err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
root := moduleRoot()
|
||||
agentPath := filepath.Join(root, "cmd", "agent")
|
||||
pipe, err := forge.NewPipeline(conn, cfg.Forge.ArtifactsDir, cfg.Forge.SigningKeyPath, agentPath, *version)
|
||||
if err != nil {
|
||||
log.Fatalf("pipeline: %v", err)
|
||||
}
|
||||
|
||||
builds, err := pipe.BuildAll(*public)
|
||||
if err != nil {
|
||||
log.Fatalf("build: %v", err)
|
||||
}
|
||||
|
||||
for _, b := range builds {
|
||||
fmt.Printf("built %s/%s id=%s checksum=%s path=%s\n", b.OS, b.Arch, b.ID, b.Checksum, b.Path)
|
||||
}
|
||||
fmt.Printf("public key: %s\n", pipe.PublicKey())
|
||||
}
|
||||
|
||||
func runPubkey(args []string) {
|
||||
fs := flag.NewFlagSet("pubkey", flag.ExitOnError)
|
||||
configPath := fs.String("config", "data/config.json", "config path")
|
||||
_ = fs.Parse(args)
|
||||
|
||||
cfg, err := config.Load(*configPath)
|
||||
if err != nil {
|
||||
log.Fatalf("config: %v", err)
|
||||
}
|
||||
|
||||
kp, err := forge.LoadOrCreateKey(cfg.Forge.SigningKeyPath)
|
||||
if err != nil {
|
||||
log.Fatalf("key: %v", err)
|
||||
}
|
||||
fmt.Println(kp.PublicKeyHex())
|
||||
}
|
||||
|
||||
func moduleRoot() string {
|
||||
dir, err := os.Getwd()
|
||||
if err != nil {
|
||||
return "."
|
||||
}
|
||||
for {
|
||||
if _, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil {
|
||||
if _, err := os.Stat(filepath.Join(dir, "cmd", "agent")); err == nil {
|
||||
return dir
|
||||
}
|
||||
}
|
||||
parent := filepath.Dir(dir)
|
||||
if parent == dir {
|
||||
break
|
||||
}
|
||||
dir = parent
|
||||
}
|
||||
wd, _ := os.Getwd()
|
||||
return wd
|
||||
}
|
||||
|
||||
func printUsage() {
|
||||
fmt.Fprintf(os.Stderr, `forge-mesh forge CLI
|
||||
|
||||
Usage:
|
||||
forge build [--config data/config.json] [--version 0.1.0-dev] [--public]
|
||||
forge pubkey [--config data/config.json]
|
||||
|
||||
Cross-compiles linux/amd64 and linux/arm64 agent binaries, ed25519-signs artifacts,
|
||||
and records builds in SQLite (--public marks builds served on /api/v1/public/*).
|
||||
|
||||
`)
|
||||
}
|
||||
Reference in New Issue
Block a user