Deploy failed when running balena deploy

balena deploy myApp--logs --source . --emulated

[Error]   Deploy failed
The command '/tmp/qemu-execve -execve /bin/sh -c JOBS=MAX npm config set unsafe-perm true && npm install --unsafe-perm --production && npm cache clean --force && npm i npm@latest -g &&   rm -rf /tmp/* && node_modules/.bin/electron-rebuild' returned a non-zero code: 127

Hi everyone

I have the same problem. I followed the Getting Started Guide and double checked everything with the recently released Setup-Stream recording.
I am trying to deploy the Example Application but it is crashing in the build process. I am on Arch, using the the Npm Balena-CLI.

Here is the output:

[dario@ArchDW sense-snake]$ DEBUG=1 balena deploy openBalenaTest --logs --source . --emulated
[Debug]   Parsing input...
[Debug]   Loading project...
[Debug]   Resolving project...
[Debug]   Failed to resolve project: 
[Debug]   AggregateError of:
[Debug]       Error: ENOENT: no such file or directory, open '/home/dario/balena/sense-snake/docker-compose.yml'
[Debug]       Error: ENOENT: no such file or directory, open '/home/dario/balena/sense-snake/docker-compose.yaml'
[Info]    Creating default composition with source: /home/dario/balena/sense-snake
[Debug]   Creating project...
[Info]    Building for armv7hf/raspberrypi3
[Build]   Building services...
[Build]   main Preparing...
[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/13 : FROM resin/raspberrypi3-node:8.5.0 AS base
[Build]   main  ---> cef40d008ff1
[Build]   main Step 2/13 : COPY [".balena/qemu-execve","/tmp/qemu-execve"]
[Build]   main  ---> Using cache
[Build]   main  ---> ed0bc7ee9e48
[Build]   main Step 3/13 : WORKDIR /usr/src/app
[Build]   main  ---> Using cache
[Build]   main  ---> d46077ba63f9
[Build]   main Step 4/13 : COPY ["package.json","."]
[Build]   main  ---> Using cache
[Build]   main  ---> 0ccf89689b98
[Build]   Built 1 service in 0:03
[Error]   Deploy failed
Error: The command '/tmp/qemu-execve -execve /bin/sh -c JOBS=MAX npm install --unsafe-perm --production' returned a non-zero code: 139
    at Stream.<anonymous> (/usr/lib/node_modules/balena-cli/node_modules/resin-docker-build/build/builder.js:178:23)
    at Stream.stream.write (/usr/lib/node_modules/balena-cli/node_modules/through/index.js:26:11)
    at Stream.ondata (internal/streams/legacy.js:15:31)
    at Stream.emit (events.js:197:13)
    at Stream.EventEmitter.emit (domain.js:481:20)
    at drain (/usr/lib/node_modules/balena-cli/node_modules/through/index.js:36:16)
    at Stream.stream.queue.stream.push (/usr/lib/node_modules/balena-cli/node_modules/through/index.js:45:5)
    at Parser.parser.onToken (/usr/lib/node_modules/balena-cli/node_modules/JSONStream/index.js:132:18)
    at Parser.proto.write (/usr/lib/node_modules/balena-cli/node_modules/jsonparse/jsonparse.js:135:34)
    at Stream.<anonymous> (/usr/lib/node_modules/balena-cli/node_modules/JSONStream/index.js:23:12)
    at Stream.stream.write (/usr/lib/node_modules/balena-cli/node_modules/through/index.js:26:11)
    at IncomingMessage.ondata (_stream_readable.js:696:20)
    at IncomingMessage.emit (events.js:197:13)
    at IncomingMessage.EventEmitter.emit (domain.js:481:20)
    at addChunk (_stream_readable.js:288:12)
    at readableAddChunk (_stream_readable.js:269:11)
    at IncomingMessage.Readable.push (_stream_readable.js:224:10)
    at HTTPParser.parserOnBody (_http_common.js:126:22)
    at Socket.socketOnData (_http_client.js:447:20)
    at Socket.emit (events.js:197:13)
    at Socket.EventEmitter.emit (domain.js:481:20)
    at addChunk (_stream_readable.js:288:12)
    at readableAddChunk (_stream_readable.js:269:11)
    at Socket.Readable.push (_stream_readable.js:224:10)
    at Pipe.onStreamRead [as onread] (internal/stream_base_commons.js:150:17)

Thanks a lot
Dario

Could you update to the latest balena-cli version and try again? This looks like an issue in the CLI tool rather that something openBalena specific.

Hi, i have the same issue:

balena deploy MiApp --source /home/dcanob/app/main/rpi/ --deviceType raspberrypi3 --arch armv7hf --logs --emulated --build --nocache 
[Info]    Compose file detected
[Info]    Building for armv7hf/raspberrypi3
[Build]   Building services...
[Build]   app Preparing...
[Info]    Emulation is enabled
[Build]   app Step 1/10 : FROM resin/raspberrypi3-node:10-stretch
[Build]   app  ---> 881b7a980651
[Build]   app Step 2/10 : COPY [".balena/qemu-execve","/tmp/qemu-execve"]
[Build]   app  ---> faee13532c97
[Build]   app Step 3/10 : ENV INITSYSTEM="on"
[Build]   app  ---> Running in 5c880e11efff
[Build]   app Removing intermediate container 5c880e11efff
[Build]   app  ---> c18cb5949b01
[Build]   app Step 4/10 : ENV UDEV="1"
[Build]   app  ---> Running in fda0a7ca2f4a
[Build]   app Removing intermediate container fda0a7ca2f4a
[Build]   app  ---> 103030dc59ac
[Build]   app Step 5/10 : ENV DBUS_SYSTEM_BUS_ADDRESS="unix:path=/host/run/dbus/system_bus_socket"
[Build]   app  ---> Running in 786425143d36
[Build]   app Removing intermediate container 786425143d36
[Build]   app  ---> 2ad0edb37f58
[Build]   app Step 6/10 : WORKDIR /usr/src/app
[Build]   app  ---> Running in 89d9668bfc05
[Build]   app Removing intermediate container 89d9668bfc05
[Build]   app  ---> 49ed8bd73304
[Build]   app Step 7/10 : COPY [".","./"]
[Build]   app  ---> 3b8aaaa88a14
[Build]   app Step 8/10 : RUN ["/tmp/qemu-execve","-execve","/bin/sh","-c","JOBS=MAX npm install --unsafe-perm --production"]
[Build]   app  ---> Running in c0bc262eedc3
[Build]   app > mi-ecobox@1.0.6 postinstall /usr/src/app
[Build]   app > electron-rebuild
[Build]   app internal/modules/cjs/loader.js:583
[Build]   app     throw err;
[Build]   app     ^
[Build]   app Error: Cannot find module './rebuild'
[Build]   app     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
[Build]   app     at Function.Module._load (internal/modules/cjs/loader.js:507:25)
[Build]   app     at Module.require (internal/modules/cjs/loader.js:637:17)
[Build]   app     at require (internal/modules/cjs/helpers.js:20:18)
[Build]   app     at Object.<anonymous> (/usr/src/app/node_modules/.bin/electron-rebuild:17:19)
[Build]   app     at Module._compile (internal/modules/cjs/loader.js:689:30)
[Build]   app     at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
[Build]   app     at Module.load (internal/modules/cjs/loader.js:599:32)
[Build]   app     at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
[Build]   app     at Function.Module._load (internal/modules/cjs/loader.js:530:3)
[Build]   app npm ERR! code ELIFECYCLE
[Build]   app npm ERR! errno 1
[Build]   app npm ERR! mi-ecobox@1.0.6 postinstall: `electron-rebuild`
[Build]   app npm ERR! Exit status 1
[Build]   app npm ERR! 
[Build]   app npm ERR! Failed at the mi-ecobox@1.0.6 postinstall script.
[Build]   app npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
[Build]   app npm ERR! A complete log of this run can be found in:
[Build]   app npm ERR!     /root/.npm/_logs/2019-04-09T04_04_15_048Z-debug.log
[Build]   Built 1 service in 1:11
[Error]   Deploy failed
The command '/tmp/qemu-execve -execve /bin/sh -c JOBS=MAX npm install --unsafe-perm --production' returned a non-zero code: 1

Additional information may be available in debug mode. Prefix the command
line with DEBUG=1, i.e.:  DEBUG=1 balena ...
If you need help, don't hesitate in contacting our support forums at
https://forums.balena.io

For bug reports or feature requests, have a look at the GitHub issues or
create a new one at: https://github.com/balena-io/balena-cli/issues/

but if run:

npm run rebuild

> mi-ecobox@1.0.6 rebuild /home/dcanob/ecobox/main/rpi/app
> electron-rebuild

✔ Rebuild Complete

and on CloudBalena this works too, my balena cli version:

balena version
10.0.0

I have this exact same problem,

balena --version
11.22.0

here is the full output:

balena deploy myApp --logs --source . --emulated
[debug] original argv0="balena" argv=[/home/balena/balena-cli/balena,/snapshot/versioned-source/bin/balena,deploy,myApp,--logs,--source,.,--emulated] length=8
[Debug]   Parsing input...
[Debug]   Loading project...
[Debug]   Resolving project...
[Debug]   Failed to resolve project:
[Debug]   AggregateError of:
[Debug]       Error: ENOENT: no such file or directory, open '/home/balena/services/sense-snake/docker-compose.yml'
[Debug]       Error: ENOENT: no such file or directory, open '/home/balena/services/sense-snake/docker-compose.yaml'
[Info]    Creating default composition with source: /home/balena/services/sense-snake
[Debug]   Creating project...
[Info]    Building for aarch64/raspberrypi4-64
[Build]   Building services...
[Build]   main Preparing...
[Info]    Installing qemu for aarch64 emulation...
[Info]    Emulation is enabled
[Debug]   Found build tasks:
[Debug]       main: build [.]
[Debug]   Resolving services with [raspberrypi4-64|aarch64]
[Debug]   Found project types:
[Debug]       main: Architecture-specific Dockerfile
[Debug]   Prepared tasks; building...
[Build]   main Step 1/13 : FROM balenalib/raspberrypi3-node:8-build AS base
[Build]   main  ---> 5ae69787fd80
[Build]   main Step 2/13 : COPY [".balena/qemu-execve","/tmp/qemu-execve"]
[Build]   main  ---> 0832684c3ce7
[Build]   main Step 3/13 : WORKDIR /usr/src/app
[Build]   main  ---> Running in 925c0b4a9ece
[Build]   main Removing intermediate container 925c0b4a9ece
[Build]   main  ---> 0b622ce8d6b0
[Build]   main Step 4/13 : COPY ["package.json","."]
[Build]   main  ---> ef30bb937c96
[Build]   main Step 5/13 : RUN ["/tmp/qemu-execve","-execve","/bin/sh","-c","JOBS=MAX npm install --unsafe-perm --production"]
[Build]   main  ---> Running in b79ee1c08bc2
[Build]   main /bin/sh: Invalid ELF image for this architecture
[Build]   Built 1 service in 0:39
[Error]   Deploy failed
The command '/tmp/qemu-execve -execve /bin/sh -c JOBS=MAX npm install --unsafe-perm --production' returned a non-zero code: 255
Error: The command '/tmp/qemu-execve -execve /bin/sh -c JOBS=MAX npm install --unsafe-perm --production' returned a non-zero code: 255
    at Stream.<anonymous> (/snapshot/versioned-source/node_modules/resin-docker-build/build/builder.js:178:23)
    at Stream.stream.write (/snapshot/versioned-source/node_modules/through/index.js:26:11)
    at Stream.ondata (internal/streams/legacy.js:15:31)
    at Stream.emit (events.js:189:13)
    at Stream.EventEmitter.emit (domain.js:441:20)
    at drain (/snapshot/versioned-source/node_modules/through/index.js:36:16)
    at Stream.stream.queue.stream.push (/snapshot/versioned-source/node_modules/through/index.js:45:5)
    at Parser.exports.parse.parser.onToken (/snapshot/versioned-source/node_modules/JSONStream/index.js:132:18)
    at Parser.proto.write (/snapshot/versioned-source/node_modules/jsonparse/jsonparse.js:135:34)
    at Stream.<anonymous> (/snapshot/versioned-source/node_modules/JSONStream/index.js:23:12)
    at Stream.stream.write (/snapshot/versioned-source/node_modules/through/index.js:26:11)
    at IncomingMessage.ondata (_stream_readable.js:689:20)
    at IncomingMessage.emit (events.js:189:13)
    at IncomingMessage.EventEmitter.emit (domain.js:441:20)
    at addChunk (_stream_readable.js:284:12)
    at readableAddChunk (_stream_readable.js:265:11)
    at IncomingMessage.Readable.push (_stream_readable.js:220:10)
    at HTTPParser.parserOnBody (_http_common.js:122:22)
    at Socket.socketOnData (_http_client.js:442:20)
    at Socket.emit (events.js:189:13)
    at Socket.EventEmitter.emit (domain.js:441:20)
    at addChunk (_stream_readable.js:284:12)
    at readableAddChunk (_stream_readable.js:265:11)
    at Socket.Readable.push (_stream_readable.js:220:10)
    at Pipe.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
    at createBuildStream.Bluebird.try.then (/snapshot/versioned-source/node_modules/resin-docker-build/build/builder.js:72:20)
    at Builder.createBuildStream (/snapshot/versioned-source/node_modules/resin-docker-build/build/builder.js:71:97)
    at Promise (/snapshot/versioned-source/node_modules/resin-multibuild/build/build.js:82:17)
    at Object.runBuildTask (/snapshot/versioned-source/node_modules/resin-multibuild/build/build.js:59:12)
    at /snapshot/versioned-source/node_modules/resin-multibuild/build/index.js:157:34
    at Generator.next (<anonymous>)
    at __awaiter (/snapshot/versioned-source/node_modules/resin-multibuild/build/index.js:8:71)
    at new Promise (<anonymous>)
    at __awaiter (/snapshot/versioned-source/node_modules/resin-multibuild/build/index.js:4:12)
    at performSingleBuild (/snapshot/versioned-source/node_modules/resin-multibuild/build/index.js:155:12)
    at Bluebird.map (/snapshot/versioned-source/node_modules/resin-multibuild/build/index.js:140:20)
    at runCallback (timers.js:705:18)
    at tryOnImmediate (timers.js:676:5)
    at processImmediate (timers.js:658:5)
    at process.topLevelDomainCallback (domain.js:120:23)
    at Object.<anonymous> (/snapshot/versioned-source/node_modules/resin-multibuild/build/index.js:139:39)
    at Generator.next (<anonymous>)
    at fulfilled (/snapshot/versioned-source/node_modules/resin-multibuild/build/index.js:5:58)
From previous event:
    at runCommand (/snapshot/versioned-source/build/app-capitano.js:181:14)
    at Object.exports.run (/snapshot/versioned-source/build/app-capitano.js:193:39)
    at routeCliFramework (/snapshot/versioned-source/build/preparser.js:39:79)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (pkg/prelude/bootstrap.js:1322:13)
    at startup (internal/bootstrap/node.js:320:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:659:3)

If you need help, don't hesitate in contacting our support forums at
https://forums.balena.io

For CLI bug reports or feature requests, have a look at the GitHub issues or
create a new one at: https://github.com/balena-io/balena-cli/issues/

@Ciantic, they key error is probably:

[Build]   main /bin/sh: Invalid ELF image for this architecture

Which usually indicates a CPU architecture mismatch, such as Intel vs ARM, 32 bit vs 64 bit. It is happening at Dockerfile step 5/13, "npm install --unsafe-perm --production".

Given the following output:

[Info]    Building for aarch64/raspberrypi4-64
[Info]    Installing qemu for aarch64 emulation...
[Debug]   Resolving services with [raspberrypi4-64|aarch64]

I gather that you project is for the RPi 4, 64 bits. The base image is however for the RPi 3, 32 bits:

[Build]   main Step 1/13 : FROM balenalib/raspberrypi3-node:8-build AS base

I don’t know if this image mismatch is necessarily a problem – I actually seem to remember that the RPi3 image works fine on the RPi4. However, it might be worth trying an RPi 4 base image, balenalib/raspberrypi4-64-node.

Also: balena deploy, as used, is building the image using your laptop (dev machine) Docker installation. To narrow down the issue, try also building without emulation on balenaCloud builders (we have ARM servers) with balena push, and/or building on a real RPi4 device on your desk. To test the latter, flash a development image and place the device in local mode, then run something like:

balena deploy myApp --logs --source . --dockerPort 2375 --dockerHost 192.168.1.2

replacing 192.168.1.2 with your device’s IP address.

If building without emulation works, the problem may be that QEMU is simply not up to the task; it is known to fail on some compilation tasks or other tasks, which npm install may be triggering. Try also running some other binary executables (other than npm) to rule this out – starting with something like /bin/sh -c 'echo hello world'.

Something else that occurs to me. The installed Qemu is for aarch64:

[Info]    Installing qemu for aarch64 emulation...

because the application, myApp, is likely an RPi4 app, while the base image is 32 bits. Try creating an RPi3 application, myApp2, then re-run the deploy command for myApp2 instead of myApp. You will likely see a different Qemu being installed.

Similarly but alternatively, try balena build + balena deploy in separate steps, explicitly specifying the device type and architecture instead of an app name in the balena build step:

balena build . --logs --emulated --deviceType raspberrypi3 --arch armv7hf
...
balena deploy myApp myImage

where myImage is the name of the image built in the first step (don’t use the --tag option because of issue 825).