devspace-sh / devspace

DevSpace - The Fastest Developer Tool for Kubernetes ⚡ Automate your deployment workflow with DevSpace and develop software directly inside Kubernetes.
https://devspace.sh
Apache License 2.0
4.22k stars 353 forks source link

Pipeline output is not displayed until a newline is reached #2743

Open jackwilsdon opened 9 months ago

jackwilsdon commented 9 months ago

What happened? Text printed from a pipeline is not output to the terminal until a newline is reached.

What did you expect to happen instead?
Text should be printed without needing a newline.

How can we reproduce the bug? (as minimally and precisely as possible)

  1. Create this devspace.yaml:
    version: v2beta1
    pipelines:
      test: |
        echo -n "Text without a newline"
        sleep 1
        echo "... finished!"
  2. Run devspace run-pipeline test
  3. Note that "Text without a newline" doesn't appear until "... finished!" is printed

Local Environment:

Anything else we need to know?
This is a bigger issue when using read -p "Some prompt here: ", as the prompt doesn't appear until the user has hit enter (completing the read).

jackwilsdon commented 9 months ago

From what I can tell, this is caused by this code (Scan only returns when it finds a newline):

https://github.com/devspace-sh/devspace/blob/69e7df31933df3f5590195b7fba8cb2da684d96d/pkg/devspace/pipeline/job.go#L101-L107

Not sure what the right fix is, as it seems like pkg/util/log doesn't have any support for logging without a newline.

lizardruss commented 9 months ago

@jackwilsdon Thanks for the analysis! We will take a look at a fix. I had previously assumed that this was an issue with the library we were using for the shell emulation, but you're probably right in that it's the scanner using the ScanLines function to tokenize the reader output.

lizardruss commented 6 months ago

@jackwilsdon While not a solution for this particular problem, I've found that read -p "Some prompt here: " works as expected in commands. The read values can then be passed into DevSpace using the --var flag. Hope that's helpful.