Skip to content

Commit 4ba7ea3

Browse files
committed
debos: Warn if parsed memory/scratchsize may be too small
Since the --memory and --scratchsize arguments are parsed with human-readable suffixes into bytes (e.g 2048MB or 2GB), if a user does not put a suffix the arguments are parsed as bytes which can cause issues later when a user sets the memory to be 2048 assuming it will be parsed as MB. Change the documentation to match reality and also add a warning if the user has set either parameter less than the recommended default. Closes: #509 Signed-off-by: Christopher Obbard <[email protected]>
1 parent e8bc216 commit 4ba7ea3

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

cmd/debos/debos.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ func main() {
6666
TemplateVars map[string]string `short:"t" long:"template-var" description:"Template variables (use -t VARIABLE:VALUE syntax)"`
6767
DebugShell bool `long:"debug-shell" description:"Fall into interactive shell on error"`
6868
Shell string `short:"s" long:"shell" description:"Redefine interactive shell binary (default: bash)" optionsl:"" default:"/bin/bash"`
69-
ScratchSize string `long:"scratchsize" description:"Size of disk backed scratch space"`
69+
ScratchSize string `long:"scratchsize" description:"Size of disk-backed scratch space (parsed with human-readable suffix; assumed bytes if no suffix)"`
7070
CPUs int `short:"c" long:"cpus" description:"Number of CPUs to use for build VM (default: 2)"`
71-
Memory string `short:"m" long:"memory" description:"Amount of memory for build VM (default: 2048MB)"`
71+
Memory string `short:"m" long:"memory" description:"Amount of memory for build VM (parsed with human-readable suffix; assumed bytes if no suffix. default: 2048MB)"`
7272
ShowBoot bool `long:"show-boot" description:"Show boot/console messages from the fake machine"`
7373
EnvironVars map[string]string `short:"e" long:"environ-var" description:"Environment variables (use -e VARIABLE:VALUE syntax)"`
7474
Verbose bool `short:"v" long:"verbose" description:"Verbose output"`
@@ -257,7 +257,12 @@ func main() {
257257
exitcode = 1
258258
return
259259
}
260-
m.SetMemory(int(memsize / 1024 / 1024))
260+
261+
memsizeMB := int(memsize / 1024 / 1024)
262+
if memsizeMB < 2048 {
263+
log.Printf("WARNING: Memory size of %dMB is less than recommended 2048MB\n", memsizeMB)
264+
}
265+
m.SetMemory(memsizeMB)
261266

262267
if options.CPUs == 0 {
263268
// Set default CPU count for fakemachine
@@ -272,6 +277,11 @@ func main() {
272277
exitcode = 1
273278
return
274279
}
280+
281+
scratchsizeMB := int(size / 1024 / 1024)
282+
if scratchsizeMB < 2048 {
283+
log.Printf("WARNING: Scratch size of %dMB is less than recommended 2048MB\n", scratchsizeMB)
284+
}
275285
m.SetScratch(size, "")
276286
}
277287

0 commit comments

Comments
 (0)