Skip to content

output of CODER_SETUP_SCRIPT is not logged if running headless #394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
johnstcn opened this issue Oct 17, 2024 · 1 comment · Fixed by #402
Closed

output of CODER_SETUP_SCRIPT is not logged if running headless #394

johnstcn opened this issue Oct 17, 2024 · 1 comment · Fixed by #402
Assignees

Comments

@johnstcn
Copy link
Member

johnstcn commented Oct 17, 2024

Motivation

If you're trying to troubleshoot issues with ENVBUILDER_SETUP_SCRIPT, you would most likely need to view the log output.

I've noticed that if running envbuilder with no stdout/stdin attached, you end up missing the log output:

Example (main@aba2f46):

$ docker run -d -e ENVBUILDER_GIT_URL=https://github.com/coder/envbuilder-starter-devcontainer -e ENVBUILDER_INIT_SCRIPT='bash' -e ENVBUILDER_SETUP_SCRIPT="echo 'setting up...'; sleep 3; echo 'done' | tee /setup.log" envbuilder:latest
envbuilder v1.0.3+dev-aba2f46 - Build development environments from repositories in a container
[...]
=== Running the setup command "echo 'setting up...'; sleep 3; echo 'done' | tee /setup.log" as the root user...
=== Running init command as user "coder": ["/bin/sh" "-c" "bash"]

Whereas running with a terminal attached results in the logs becoming visible:

docker run -it -e ENVBUILDER_GIT_URL=https://github.com/coder/envbuilder-starter-devcontainer -e ENVBUILDER_INIT_SCRIPT='bash' -e ENVBUILDER_
SETUP_SCRIPT="echo 'setting up...'; sleep 3; echo 'done' | tee /setup.log" envbuilder:latest
envbuilder v1.0.3+dev-aba2f46 - Build development environments from repositories in a container
[...]
=== Running the setup command "echo 'setting up...'; sleep 3; echo 'done' | tee /setup.log" as the root user...
setting up...
done
=== Running init command as user "coder": ["/bin/sh" "-c" "bash"]
🐳 5a1e4fa7be68 envbuilder-starter-devcontainer #  

Workaround

Redirect or tee the output to some file (as shown in the above examples).

Proposed Solution

Not sure yet!

@coder-labeler coder-labeler bot added the help wanted Extra attention is needed label Oct 17, 2024
@mafredri
Copy link
Member

mafredri commented Nov 1, 2024

This looks like a plain logic bug, we're scanning an empty bytes.Buffer, that'll just exit immediately and never log anything.

envbuilder/envbuilder.go

Lines 895 to 900 in c4b082e

go func() {
scanner := bufio.NewScanner(&buf)
for scanner.Scan() {
opts.Logger(log.LevelInfo, "%s", scanner.Text())
}
}()

@mafredri mafredri self-assigned this Nov 1, 2024
@mafredri mafredri removed the help wanted Extra attention is needed label Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants