cli icon indicating copy to clipboard operation
cli copied to clipboard

devcontainer up trims docker command in logs

Open brian-mcnamara opened this issue 1 year ago • 3 comments

When launching a devcontainer, the docker command being logged is not the same command that is actually being passed to docker. This is due to the logger replacing everything after the new line with an empty space: https://github.com/devcontainers/cli/blob/a48200c005724ddaecae3ed6b188a7d99ca482a4/src/spec-common/commonUtils.ts#L329 and the arguments containing a new lines https://github.com/devcontainers/cli/blob/a48200c005724ddaecae3ed6b188a7d99ca482a4/src/spec-node/singleContainer.ts#L381

Ideally the command being logged should be exactly what is being passed to docker.

Current log output of the command:

docker run --sig-proxy=false -a STDOUT -a STDERR --mount source=/dev,target=/workspace,type=bind --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker-host.sock -l devcontainer.local_folder=/dev -l devcontainer.config_file=/dev/.devcontainer/devcontainer.json --entrypoint /bin/sh vsc-c5067b6e1911c7c50ffae27b6e3a0b6304f4375a5b0021508f278d172f3835a8-features-uid -c echo Container started

when the actual docker execution is:

docker run --sig-proxy=false -a STDOUT -a STDERR --mount source=/dev,target=/workspace,type=bind --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker-host.sock -l devcontainer.local_folder=/dev -l devcontainer.config_file=/dev/.devcontainer/devcontainer.json --entrypoint /bin/sh vsc-c5067b6e1911c7c50ffae27b6e3a0b6304f4375a5b0021508f278d172f3835a8-features-uid -c echo Container started
trap "exit 0" 15
/usr/local/share/docker-init.sh
exec "$@"
while sleep 1 & wait $!; do :; done -

It would be nice to format the log correctly to make it easy to recreate the container for testing

brian-mcnamara avatar Dec 08 '23 17:12 brian-mcnamara

Thank you @brian-mcnamara for reporting this issue and sharing the details. We really appreciate it. Would you consider contributing a PR to make this better?

@chrmarti btw do we have any specific reasoning for trimming it at newline?

eljog avatar Dec 12 '23 02:12 eljog

Hey @eljog , happy to submit a PR, I did not initially because I was unsure of whether there was a reason the new lines were trimmed and whether just wrapping the cmd arguments in a single quote was the prefered solution. Ill see if @chrmarti has anything to add

brian-mcnamara avatar Dec 12 '23 02:12 brian-mcnamara

The output can become very verbose depending on what commands we are executing, so I truncated the command and its arguments at the first newline.

chrmarti avatar Dec 12 '23 11:12 chrmarti