diff options
author | Héctor Orón Martínez <zumbi@debian.org> | 2018-08-10 18:07:56 +0200 |
---|---|---|
committer | Héctor Orón Martínez <zumbi@debian.org> | 2018-08-10 18:07:56 +0200 |
commit | a3819b2c8c823955bb053d5a34da27c94aef4d47 (patch) | |
tree | 430633212532264c15f75ca47e02f3e4740c7c3c /cmd/debos | |
parent | 8ab62bc45ed897f007493d02084538503ade6f37 (diff) |
New upstream version 1.0.0+git20180808.5b74d5d
Diffstat (limited to 'cmd/debos')
-rw-r--r-- | cmd/debos/debos.go | 68 |
1 files changed, 50 insertions, 18 deletions
diff --git a/cmd/debos/debos.go b/cmd/debos/debos.go index 0d1f7ff..f0f0ce3 100644 --- a/cmd/debos/debos.go +++ b/cmd/debos/debos.go @@ -14,25 +14,29 @@ import ( "github.com/jessevdk/go-flags" ) -func checkError(context debos.DebosContext, err error, a debos.Action, stage string) int { +func checkError(context *debos.DebosContext, err error, a debos.Action, stage string) int { if err == nil { return 0 } + context.State = debos.Failed log.Printf("Action `%s` failed at stage %s, error: %s", a, stage, err) - debos.DebugShell(context) + debos.DebugShell(*context) return 1 } func main() { var context debos.DebosContext var options struct { - ArtifactDir string `long:"artifactdir"` + ArtifactDir string `long:"artifactdir" description:"Directory for packed archives and ostree repositories (default: current directory)"` InternalImage string `long:"internal-image" hidden:"true"` - TemplateVars map[string]string `short:"t" long:"template-var" description:"Template variables"` + TemplateVars map[string]string `short:"t" long:"template-var" description:"Template variables (use -t VARIABLE:VALUE syntax)"` DebugShell bool `long:"debug-shell" description:"Fall into interactive shell on error"` Shell string `short:"s" long:"shell" description:"Redefine interactive shell binary (default: bash)" optionsl:"" default:"/bin/bash"` ScratchSize string `long:"scratchsize" description:"Size of disk backed scratch space"` + CPUs int `short:"c" long:"cpus" description:"Number of CPUs to use for build VM (default: 2)"` + Memory string `short:"m" long:"memory" description:"Amount of memory for build VM (default: 2048MB)"` + ShowBoot bool `long:"show-boot" description:"Show boot/console messages from the fake machine"` } var exitcode int = 0 @@ -111,9 +115,11 @@ func main() { context.Architecture = r.Architecture + context.State = debos.Success + for _, a := range r.Actions { err = a.Verify(&context) - if exitcode = checkError(context, err, a, "Verify"); exitcode != 0 { + if exitcode = checkError(&context, err, a, "Verify"); exitcode != 0 { return } } @@ -122,6 +128,24 @@ func main() { m := fakemachine.NewMachine() var args []string + if options.Memory == "" { + // Set default memory size for fakemachine + options.Memory = "2Gb" + } + memsize, err := units.RAMInBytes(options.Memory) + if err != nil { + fmt.Printf("Couldn't parse memory size: %v\n", err) + exitcode = 1 + return + } + m.SetMemory(int(memsize / 1024 / 1024)) + + if options.CPUs == 0 { + // Set default CPU count for fakemachine + options.CPUs = 2 + } + m.SetNumCPUs(options.CPUs) + if options.ScratchSize != "" { size, err := units.FromHumanSize(options.ScratchSize) if err != nil { @@ -132,6 +156,8 @@ func main() { m.SetScratch(size, "") } + m.SetShowBoot(options.ShowBoot) + m.AddVolume(context.Artifactdir) args = append(args, "--artifactdir", context.Artifactdir) @@ -148,8 +174,11 @@ func main() { } for _, a := range r.Actions { + // Stack PostMachineCleanup methods + defer a.PostMachineCleanup(&context) + err = a.PreMachine(&context, m, &args) - if exitcode = checkError(context, err, a, "PreMachine"); exitcode != 0 { + if exitcode = checkError(&context, err, a, "PreMachine"); exitcode != 0 { return } } @@ -161,12 +190,13 @@ func main() { } if exitcode != 0 { + context.State = debos.Failed return } for _, a := range r.Actions { - err = a.PostMachine(context) - if exitcode = checkError(context, err, a, "Postmachine"); exitcode != 0 { + err = a.PostMachine(&context) + if exitcode = checkError(&context, err, a, "Postmachine"); exitcode != 0 { return } } @@ -177,8 +207,11 @@ func main() { if !fakemachine.InMachine() { for _, a := range r.Actions { + // Stack PostMachineCleanup methods + defer a.PostMachineCleanup(&context) + err = a.PreNoMachine(&context) - if exitcode = checkError(context, err, a, "PreNoMachine"); exitcode != 0 { + if exitcode = checkError(&context, err, a, "PreNoMachine"); exitcode != 0 { return } } @@ -195,22 +228,21 @@ func main() { for _, a := range r.Actions { err = a.Run(&context) - if exitcode = checkError(context, err, a, "Run"); exitcode != 0 { - return - } - } - for _, a := range r.Actions { - err = a.Cleanup(context) - if exitcode = checkError(context, err, a, "Cleanup"); exitcode != 0 { + // This does not stop the call of stacked Cleanup methods for other Actions + // Stack Cleanup methods + defer a.Cleanup(&context) + + // Check the state of Run method + if exitcode = checkError(&context, err, a, "Run"); exitcode != 0 { return } } if !fakemachine.InMachine() { for _, a := range r.Actions { - err = a.PostMachine(context) - if exitcode = checkError(context, err, a, "PostMachine"); exitcode != 0 { + err = a.PostMachine(&context) + if exitcode = checkError(&context, err, a, "PostMachine"); exitcode != 0 { return } } |