Skip to content
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

balena "build" command eats stdout #2684

Open
icanhazpython opened this issue Oct 6, 2023 · 0 comments
Open

balena "build" command eats stdout #2684

icanhazpython opened this issue Oct 6, 2023 · 0 comments

Comments

@icanhazpython
Copy link

icanhazpython commented Oct 6, 2023

Expected Behavior

Balena build command should output stdout and stderr streams from each Dockerfile step.

Actual Behavior

When running a build using something like balena build --docker /Users/me/.docker/run/docker.sock --fleet <fleet>, the build output eats stdout in a very strange way. I'm not sure if this is intended behavior, but it sure confused me at first, as this is not the behavior exhibited by docker build (even with DOCKER_BUILDKIT=0 as seems to be how balena runs it).

Important to note that balena build does not eat EVERY SINGLE stdout line, but in my test, it eats 7 of 10 lines.

Steps to Reproduce the Problem

Create the following python file:

#!/usr/bin/env python3

import sys

def main():
    print("Start")

    lc = 1

    while True:
        print(f'stdout line {lc}')
        print(f'stderr line {lc}', file=sys.stderr)
        if lc >= 10:
            break
        lc += 1

    print("Done")
    sys.exit(100)

if __name__ == '__main__':
    main()

And the following dockerfile:

FROM debian:buster-slim

RUN apt-get update && apt-get install -y python3

COPY buffertest.py /tmp/
RUN chmod +x /tmp/buffertest.py && /tmp/buffertest.py

Now run balena build --docker /Users/me/.docker/run/docker.sock --fleet <somefleet>

Output is

[Build]   Building services...
[Build]   mycontainer Preparing...
[Info]    Building for aarch64/raspberrypi4-64
[Info]    Docker Desktop detected (daemon architecture: "aarch64")
[Info]      Docker itself will determine and enable architecture emulation if required,
[Info]      without balena-cli intervention and regardless of the --emulated option.
[Build]   mycontainer Step 1/4 : FROM debian:buster-slim
[Build]   mycontainer  ---> 68f3a0301924
[Build]   mycontainer Step 2/4 : RUN apt-get update && apt-get install -y python3
[Build]   mycontainer  ---> Using cache
[Build]   mycontainer  ---> 46ddd870660a
[Build]   mycontainer Step 3/4 : COPY buffertest.py /tmp/
[Build]   mycontainer  ---> Using cache
[Build]   mycontainer  ---> 57234c164e95
[Build]   mycontainer Step 4/4 : RUN chmod +x /tmp/buffertest.py && /tmp/buffertest.py
[Build]   mycontainer  ---> Running in 2520d065141f
[Build]   mycontainer stderr line 1
[Build]   mycontainer stderr line 2
[Build]   mycontainer stderr line 3
[Build]   mycontainer stderr line 4
[Build]   mycontainer stderr line 5
[Build]   mycontainer stderr line 6
[Build]   mycontainer stderr line 7
[Build]   mycontainer stderr line 8
[Build]   mycontainer stderr line 9
[Build]   mycontainer stderr line 10
[Build]   mycontainer Start
[Build]   mycontainer stdout line 1
[Build]   mycontainer stdout line 2
[Build]   mycontainer stdout line 3
[Build]   Built 1 service in 0:01
[Error]   Build failed.
The command '/bin/sh -c chmod +x /tmp/buffertest.py && /tmp/buffertest.py' returned a non-zero code: 100

Additional information may be available with the `--debug` flag.

For further help or support, visit:
https://www.balena.io/docs/reference/balena-cli/#support-faq-and-troubleshooting

Now try this with docker: DOCKER_BUILDKIT=0 docker build .

Output:

DEPRECATED: The legacy builder is deprecated and will be removed in a future release.
            BuildKit is currently disabled; enable it by removing the DOCKER_BUILDKIT=0
            environment-variable.

Sending build context to Docker daemon   25.6kB
Step 1/4 : FROM debian:buster-slim
 ---> 68f3a0301924
Step 2/4 : RUN apt-get update && apt-get install -y python3
 ---> Using cache
 ---> 46ddd870660a
Step 3/4 : COPY buffertest.py /tmp/
 ---> 57234c164e95
Step 4/4 : RUN chmod +x /tmp/buffertest.py && /tmp/buffertest.py
 ---> Running in 2626ea8414f1
stderr line 1
stderr line 2
stderr line 3
stderr line 4
stderr line 5
stderr line 6
stderr line 7
stderr line 8
stderr line 9
stderr line 10
Start
stdout line 1
stdout line 2
stdout line 3
stdout line 4
stdout line 5
stdout line 6
stdout line 7
stdout line 8
stdout line 9
stdout line 10
Done
The command '/bin/sh -c chmod +x /tmp/buffertest.py && /tmp/buffertest.py' returned a non-zero code: 100

As you can see, the stdout and stderr lines are displayed by docker in all their glory.

Specifications

  • balena CLI version: Present on two versions I tested: balena-cli version "17.0.0" / Node.js version "18.16.1" AND balena-cli version "15.2.0" / Node.js version "14.21.3"
  • Cloud backend: openBalena or balenaCloud? balenaCloud
  • Operating system version: macOS 13.5.1
  • 32/64 bit OS and processor: Apple M1
  • Install method: npm or zip package or executable installer
  • If npm install, Node.js and npm version: e.g. Node v8.16.0 and npm v6.4.1
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

No branches or pull requests

1 participant