Skip to content

Commit fe5f7e9

Browse files
committed
Warn if parsed memory/scratchsize args 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 a recommended minimum. Closes: #509 Signed-off-by: Christopher Obbard <[email protected]>
1 parent f46d0f0 commit fe5f7e9

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
@@ -68,9 +68,9 @@ func main() {
6868
TemplateVars map[string]string `short:"t" long:"template-var" description:"Template variables (use -t VARIABLE:VALUE syntax)"`
6969
DebugShell bool `long:"debug-shell" description:"Fall into interactive shell on error"`
7070
Shell string `short:"s" long:"shell" description:"Redefine interactive shell binary (default: bash)" optionsl:"" default:"/bin/bash"`
71-
ScratchSize string `long:"scratchsize" description:"Size of disk backed scratch space"`
71+
ScratchSize string `long:"scratchsize" description:"Size of disk-backed scratch space (parsed with human-readable suffix; assumed bytes if no suffix)"`
7272
CPUs int `short:"c" long:"cpus" description:"Number of CPUs to use for build VM (default: 2)"`
73-
Memory string `short:"m" long:"memory" description:"Amount of memory for build VM (default: 2048MB)"`
73+
Memory string `short:"m" long:"memory" description:"Amount of memory for build VM (parsed with human-readable suffix; assumed bytes if no suffix. default: 2Gb)"`
7474
ShowBoot bool `long:"show-boot" description:"Show boot/console messages from the fake machine"`
7575
EnvironVars map[string]string `short:"e" long:"environ-var" description:"Environment variables (use -e VARIABLE:VALUE syntax)"`
7676
Verbose bool `short:"v" long:"verbose" description:"Verbose output"`
@@ -265,7 +265,12 @@ func main() {
265265
exitcode = 1
266266
return
267267
}
268-
m.SetMemory(int(memsize / 1024 / 1024))
268+
269+
memsizeMB := int(memsize / 1024 / 1024)
270+
if memsizeMB < 256 {
271+
log.Printf("WARNING: Memory size of %dMB is less than recommended minimum 256MB\n", memsizeMB)
272+
}
273+
m.SetMemory(memsizeMB)
269274

270275
if options.CPUs == 0 {
271276
// Set default CPU count for fakemachine
@@ -280,6 +285,11 @@ func main() {
280285
exitcode = 1
281286
return
282287
}
288+
289+
scratchsizeMB := int(size / 1000 / 1000)
290+
if scratchsizeMB < 512 {
291+
log.Printf("WARNING: Scratch size of %dMB is less than recommended minimum 512MB\n", scratchsizeMB)
292+
}
283293
m.SetScratch(size, "")
284294
}
285295

0 commit comments

Comments
 (0)