feat: migrate builds plugin to go and track per-build records
Adds typed JSON build records under data/builds/<app>/<build-id>.{json,log} keyed on a stable base36 ULID-style DOKKU_BUILD_ID generated for every deploy. The new commands surface that history (builds:list, builds:info, builds:prune) and an operator-configurable retention via builds:set retention. The existing builds:cancel and builds:output now key on the build-id (with safe handling for already-finalized and abandoned records), and the per-build log file replaces journalctl as the durable source of truth for builds:output.
This commit is contained in:
30 files changed
+2690
-196
No files matched your search
@@ -0,0 +1,77 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/dokku/dokku/plugins/builds"
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
|
||||
flag "github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
func main() {
|
||||
parts := strings.Split(os.Args[0], "/")
|
||||
subcommand := parts[len(parts)-1]
|
||||
|
||||
var err error
|
||||
switch subcommand {
|
||||
case "cancel":
|
||||
args := flag.NewFlagSet("builds:cancel", flag.ExitOnError)
|
||||
args.Parse(os.Args[2:])
|
||||
err = builds.CommandCancel(args.Arg(0))
|
||||
case "info":
|
||||
args := flag.NewFlagSet("builds:info", flag.ExitOnError)
|
||||
format := args.String("format", "stdout", "format: [ stdout | json ]")
|
||||
args.Parse(os.Args[2:])
|
||||
err = builds.CommandInfo(args.Arg(0), args.Arg(1), *format)
|
||||
case "list":
|
||||
args := flag.NewFlagSet("builds:list", flag.ExitOnError)
|
||||
format := args.String("format", "stdout", "format: [ stdout | json ]")
|
||||
kind := args.String("kind", "", "filter by kind: [ build | deploy ]")
|
||||
status := args.String("status", "", "filter by status: [ running | succeeded | failed | canceled | abandoned ]")
|
||||
args.Parse(os.Args[2:])
|
||||
err = builds.CommandList(args.Arg(0), *format, *kind, *status)
|
||||
case "output":
|
||||
args := flag.NewFlagSet("builds:output", flag.ExitOnError)
|
||||
args.Parse(os.Args[2:])
|
||||
err = builds.CommandOutput(args.Arg(0), args.Arg(1))
|
||||
case "prune":
|
||||
args := flag.NewFlagSet("builds:prune", flag.ExitOnError)
|
||||
allApps := args.Bool("all-apps", false, "--all-apps: prune every app")
|
||||
args.Parse(os.Args[2:])
|
||||
err = builds.CommandPrune(args.Arg(0), *allApps)
|
||||
case "report":
|
||||
args := flag.NewFlagSet("builds:report", flag.ExitOnError)
|
||||
format := args.String("format", "stdout", "format: [ stdout | json ]")
|
||||
reportArgs, flagErr := common.ParseReportArgs("builds", os.Args[2:])
|
||||
if flagErr == nil {
|
||||
args.Parse(reportArgs.OSArgs)
|
||||
appName := args.Arg(0)
|
||||
if reportArgs.IsGlobal {
|
||||
appName = "--global"
|
||||
}
|
||||
err = builds.CommandReport(appName, *format, reportArgs.InfoFlag)
|
||||
}
|
||||
case "set":
|
||||
args := flag.NewFlagSet("builds:set", flag.ExitOnError)
|
||||
global := args.Bool("global", false, "--global: set a global property")
|
||||
args.Parse(os.Args[2:])
|
||||
appName := args.Arg(0)
|
||||
property := args.Arg(1)
|
||||
value := args.Arg(2)
|
||||
if *global {
|
||||
appName = "--global"
|
||||
property = args.Arg(0)
|
||||
value = args.Arg(1)
|
||||
}
|
||||
err = builds.CommandSet(appName, property, value)
|
||||
default:
|
||||
err = fmt.Errorf("Invalid plugin subcommand call: %s", subcommand)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
common.LogFailWithError(err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user