balena-io / balena-cli

The official balena CLI tool.
Apache License 2.0
454 stars 139 forks source link

`balena build --dockerfile Dockerfile.template --emulated` fails with "returned a non-zero code: 1" #2549

Open thgreasi opened 2 years ago

thgreasi commented 2 years ago

Expected Behavior

balena build --debug --deviceType raspberrypi3 --arch armv7hf --emulated --nocache --dockerfile Dockerfile.template should work on a non-arm system

Actual Behavior

Please describe what actually happened instead:

balena build --debug --deviceType raspberrypi3 --arch armv7hf --emulated --nocache --dockerfile Dockerfile.template

on a amd64 system fails.

Steps to Reproduce the Problem

  1. Create the following Dockerfile.template
FROM balenalib/%%BALENA_MACHINE_NAME%%-alpine

RUN echo "HELLO WORLD" | cat
  1. Run an emulated build (tested on amd64 Ubuntu 22.04)
DEBUG=1 balena build --debug --deviceType raspberrypi3 --arch armv7hf --emulated --nocache --dockerfile Dockerfile.template 
[debug] original argv0="node" argv=[/home/myuser/.nvm/versions/node/v12.20.0/bin/node,/home/myuser/.nvm/versions/node/v12.20.0/bin/balena,build,--debug,--deviceType,raspberrypi3,--arch,armv7hf,--emulated,--nocache,--dockerfile,Dockerfile.template] length=12
[debug] new argv=[/home/myuser/.nvm/versions/node/v12.20.0/bin/node,/home/myuser/.nvm/versions/node/v12.20.0/bin/balena,build,--deviceType,raspberrypi3,--arch,armv7hf,--emulated,--nocache,--dockerfile,Dockerfile.template] length=11
[debug] Deprecation check: 1.01372 days since last npm registry query for next major version release date.
[debug] Will not query the registry again until at least 7 days have passed.
[Debug]   Parsing input...
[Debug]   Loading project...
[Debug]   Resolving project...
[Info]    No "docker-compose.yml" file found at "/home/myuser/tmp"
[Info]    Creating default composition with source: "/home/myuser/tmp"
[Debug]   Creating project...
[Build]   Building services...
[Build]   main Preparing...
[Info]    Building for armv7hf/raspberrypi3
[Info]    Emulation is enabled
[Debug]   Found build tasks:
[Debug]       main: build [.]
[Debug]   Resolving services with [raspberrypi3|armv7hf]
[Debug]   Found project types:
[Debug]       main: Dockerfile.template
[Debug]   Prepared tasks; building...
[Build]   main Step 1/2 : FROM balenalib/raspberrypi3-alpine
[Build]   main  ---> 3d3155b4337a
[Build]   main Step 2/2 : RUN echo "HELLO WORLD" | cat
[Build]   main  ---> [Warning] The requested image's platform (linux/arm/v7) does not match the detected host platform (linux/amd64) and no specific platform was requested
[Build]   main  ---> Running in 85c10b551424
[Build]   main exec /bin/sh: exec format error
[Build]   Built 1 service in 0:04
[Error]   Build failed.
The command '/bin/sh -c echo "HELLO WORLD" | cat' returned a non-zero code: 1

Error: The command '/bin/sh -c echo "HELLO WORLD" | cat' returned a non-zero code: 1
    at Stream.<anonymous> (/home/myuser/.nvm/versions/node/v12.20.0/lib/node_modules/balena-cli/node_modules/@balena/compose/dist/build/builder.js:102:23)
    at Stream.stream.write (/home/myuser/.nvm/versions/node/v12.20.0/lib/node_modules/balena-cli/node_modules/through/index.js:26:11)
    at Stream.ondata (internal/streams/legacy.js:19:31)
    at Stream.emit (events.js:314:20)
    at Stream.EventEmitter.emit (domain.js:483:12)
    at drain (/home/myuser/.nvm/versions/node/v12.20.0/lib/node_modules/balena-cli/node_modules/through/index.js:36:16)
    at Stream.stream.queue.stream.push (/home/myuser/.nvm/versions/node/v12.20.0/lib/node_modules/balena-cli/node_modules/through/index.js:45:5)
    at Parser.parser.onToken (/home/myuser/.nvm/versions/node/v12.20.0/lib/node_modules/balena-cli/node_modules/JSONStream/index.js:132:18)
    at Parser.proto.write (/home/myuser/.nvm/versions/node/v12.20.0/lib/node_modules/balena-cli/node_modules/jsonparse/jsonparse.js:135:34)
    at Stream.<anonymous> (/home/myuser/.nvm/versions/node/v12.20.0/lib/node_modules/balena-cli/node_modules/JSONStream/index.js:23:12)
    at Stream.stream.write (/home/myuser/.nvm/versions/node/v12.20.0/lib/node_modules/balena-cli/node_modules/through/index.js:26:11)
    at IncomingMessage.ondata (_stream_readable.js:718:22)
    at IncomingMessage.emit (events.js:314:20)
    at IncomingMessage.EventEmitter.emit (domain.js:483:12)
    at addChunk (_stream_readable.js:297:12)
    at readableAddChunk (_stream_readable.js:272:9)
From previous event:
    at /home/myuser/.nvm/versions/node/v12.20.0/lib/node_modules/balena-cli/node_modules/@balena/compose/dist/build/builder.js:39:20
    at processImmediate (internal/timers.js:461:21)
From previous event:
    at Builder.createBuildStream (/home/myuser/.nvm/versions/node/v12.20.0/lib/node_modules/balena-cli/node_modules/@balena/compose/dist/build/builder.js:38:97)
    at /home/myuser/.nvm/versions/node/v12.20.0/lib/node_modules/balena-cli/node_modules/@balena/compose/dist/multibuild/build.js:90:21
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

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

Interestingly enough when not explicitly providing the dockerfile parameter the command works:

balena build --debug --deviceType raspberrypi3 --arch armv7hf --emulated --nocache

This doesn't seem to be a case specific to not accepting template file for the --dockerfile parameter since the command works fine for non-emulated builds

balena build --debug --deviceType intel-nuc --arch amd64 --nocache --dockerfile Dockerfile.template

FWIW the emulated commands do succeed when pointing to a plain Dockerfile

balena build --debug --deviceType raspberrypi3 --arch armv7hf --emulated --nocache --dockerfile OtherDockerfile
balena build --debug --deviceType intel-nuc --arch amd64 --nocache --dockerfile OtherDockerfile

Specifications

Additional References

If applicable, please add additional links to GitHub projects, forums.balena.io threads, gist.github.com, Google Drive attachments, etc.

jellyfish-bot commented 2 years ago

[thgreasi] This has attached https://jel.ly.fish/abf3ee13-ea23-46a4-92e6-facb984582cf