Skip to content

Commit

Permalink
More conservative argument trimming policy. Dockerfy trims only its o…
Browse files Browse the repository at this point in the history
…wn args
  • Loading branch information
markriggins committed Jul 18, 2016
1 parent 9e12eba commit 3a297ea
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
3 changes: 2 additions & 1 deletion args.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ func removeCommandsFromOsArgs() Commands {
cmd.Path, _ = exec.LookPath(cmd.Path)
}
}
cmd.Args = append(cmd.Args, arg_i)
// Only trim our own args, not --run cmd's or --start cmd's
cmd.Args = append(cmd.Args, os.Args[i])
} else {
newOsArgs = append(newOsArgs, arg_i)
}
Expand Down
8 changes: 5 additions & 3 deletions dockerfy.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,14 @@ func main() {
flag.DurationVar(&waitTimeoutFlag, "timeout", 10*time.Second, "Host wait timeout duration, defaults to 10s")
flag.DurationVar(&reapPollIntervalFlag, "reap-poll-interval", 120*time.Second, "Polling interval for reaping zombies")

// Manually pre-process the --debug flag so we can debug our removeCommandsFromOsArgs which happens BEFORE
// we call flag.Parse()
// Manually pre-process the --debug and --verbose flags so we can debug our complex argument pre-processing
// that happens BEFORE flag.Parse()
for i := 0; i < len(os.Args); i++ {
if os.Args[i] == "--debug" {
if strings.TrimSpace(os.Args[i]) == "--debug" {
debugFlag = true
log.Printf("debugging output ..")
} else if strings.TrimSpace(os.Args[i]) == "--verbose" {
verboseFlag = true
}
}

Expand Down
15 changes: 15 additions & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,18 @@ run-exit-code-test:
@echo "run-exit-code-test PASSED"


run-trim-args-test:
@docker rm -f test-nginx >/dev/null 2>&1 || true
@echo "\n\nrun-trim-args-test:"
@echo "\tVerify that dockerfy trims its own args, but not those to --run or --start cmds"
@echo "################################################################################"
docker run -it --name test-nginx \
-v $(PWD):/secrets \
nginx-with-dockerfy-and-zombie-maker \
' --debug ' \
' --secrets-files ' " /secrets/secrets.json:/secrets/secrets.2.json " \
--run echo ' LEADING SPACES ' -- echo DONE >/dev/null 2>&1
docker logs test-nginx 2>&1 | egrep -q 'debugging output'
docker logs test-nginx 2>&1 | egrep -q '^ LEADING SPACES'
docker logs test-nginx 2>&1 | egrep -q 'loaded secret: JSON_SECRET'
@echo "run-trim-args-test PASSED"

0 comments on commit 3a297ea

Please sign in to comment.