Resin CLI installation instructions for containers

resin-cli

#1

Hello, my Resin applications are generally rooted at resin/raspberrypi3-debian:latest and I would like to integrate the Resin CLI into my environment to get more functionality from the Resin APIs. Now, I see the installation instructions here, but I’ve had a very tough time getting node to install as part of my system package installation Dockerfile stanza. After trying a few options found on the Internet, I basically gave up.

What is the correct Node installation incantation for Debian? I’ll be honest that I’d prefer not to take a NodeJS dependency in my container if I don’t already have this. Are there other CLI variants that I could use?

Thanks!

Edit: here’s an example of the last attempt to get NodeJS installed (setup_6.x and setup_8.x each failed in different ways):

RUN curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - \
     && apt-get install -y --no-install-recommends \
     nodejs \
     && npm install --global --production resin-cli

I currently interact with the Resin APIs through a Python wrapper around the Resin SDK for Python: https://github.com/resin-io/resin-sdk-python


#4

Is npm and nodejs installed on your workstation/laptop? Not sure why Docker or your Dockerfile are entering the picture.

I just installed as per instructions, all good.


#5

Thanks for the feedback. I use the Resin APIs from the Resin-deployed applications to discover the expected topology of devices in other applications, so I need Resin CLI deployed to my devices, not my development environment/laptop. As I mentioned, I created a lightweight wrapper around the Python SDK for this but I’d like the more full-featured CLI if possible.

Edit: I’ve edited the title of this thread to make the intent more clear.


#7

Hi, we have the base images with nodejs preinstalled come with few variants (https://docs.resin.io/runtime/resin-base-images/#-a-name-node-a-docker-node, base images for raspberry pi 3 https://docs.resin.io/runtime/resin-base-images/#-a-name-node-a-docker-node). With these images, you can just install resin-cli without worrying about other dependencies (If you use the Slim variant, you might need few dependencies like python or git since we don’t preinstall them).


#8

Thank you. I’ll give this a try.


#10

Hey there,

is this advice still true in 2019?

I tried to install the balena cli in one of your docker images on my raspberry pi 2 (balenalib/raspberry-pi2-node).
The installation fails with the following log:

gyp: Call to 'sh liblzma-config.sh "/home/node_modules/lzma-native/build" "/home/node_modules/lzma-native/deps/xz-5.2.3.tar.bz2"' returned exit status 2 while in binding.gyp. while trying to load binding.gyp
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:345:16)
gyp ERR! stack     at ChildProcess.emit (events.js:182:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:254:12)
gyp ERR! System Linux 4.14.79-v7+
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/home/node_modules/lzma-native/binding-v4.0.3-node-v67-linux-arm/lzma_native.node" "--module_name=lzma_native" "--module_path=/home/node_modules/lzma-native/binding-v4.0.3-node-v67-linux-arm" "--napi_version=3" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v67"
gyp ERR! cwd /home/node_modules/lzma-native
gyp ERR! node -v v11.3.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
node-pre-gyp ERR! build error 
node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/home/node_modules/lzma-native/binding-v4.0.3-node-v67-linux-arm/lzma_native.node --module_name=lzma_native --module_path=/home/node_modules/lzma-native/binding-v4.0.3-node-v67-linux-arm --napi_version=3 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v67' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/home/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:182:13)
node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:978:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:265:5)
node-pre-gyp ERR! System Linux 4.14.79-v7+
node-pre-gyp ERR! command "/usr/local/bin/node" "/home/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /home/node_modules/lzma-native
node-pre-gyp ERR! node -v v11.3.0
node-pre-gyp ERR! node-pre-gyp -v v0.11.0
node-pre-gyp ERR! not ok 
Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/home/node_modules/lzma-native/binding-v4.0.3-node-v67-linux-arm/lzma_native.node --module_name=lzma_native --module_path=/home/node_modules/lzma-native/binding-v4.0.3-node-v67-linux-arm --napi_version=3 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v67' (1)
npm WARN enoent ENOENT: no such file or directory, open '/home/package.json'
npm WARN balena-request@10.0.1 requires a peer of balena-auth@^2.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN resin-register-device@5.0.0 requires a peer of resin-request@^9.0.2 but none is installed. You must install peer dependencies yourself.
npm WARN home No description
npm WARN home No repository field.
npm WARN home No README data
npm WARN home No license field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: removedrive@1.1.2 (node_modules/removedrive):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for removedrive@1.1.2: wanted {"os":"win32","arch":"any"} (current: {"os":"linux","arch":"arm"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: winusb-driver-generator@1.2.4 (node_modules/winusb-driver-generator):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for winusb-driver-generator@1.2.4: wanted {"os":"win32","arch":"any"} (current: {"os":"linux","arch":"arm"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: macmount@1.0.0 (node_modules/macmount):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for macmount@1.0.0: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"arm"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! lzma-native@4.0.3 install: `node-pre-gyp install --fallback-to-build && rimraf build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the lzma-native@4.0.3 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-02-04T08_58_11_926Z-debug.log

I’ve installed all dependencies, even node-gyp and node-pre-gyp.
I’m not too familiar with the node.js universe so I might be missing something obvious.

Help please :slight_smile:


#11

Hi @electrobusch,
You should be able to install the balena CLI into any supported base image (NodeJS full support including node-gyp).

Would it be possible to supply the Dockerfile (or at the minimum the base image name/tag you’re trying to use), so that we can take a deeper look?

Best regards, Heds


#12

Apologies, I’ve just seen you did say `balenalib/raspberry-pi2-node). We’ll take a look at this and get back to you (though the Dockerfile fragment would still be useful if possible!).


#13

Hi @hedss,
I just ran the following commands, trying out the alpine image on a raspberry pi 2 (no Dockerfile):

docker run -it balenalib/raspberry-pi2-alpine-node /bin/bash
# then inside the container
install_packages g++ make python git  
# this works
npm install balena-cli -g --production --unsafe-perm
# this fails with the following
../deps/e2fsprogs/lib/ext2fs/ext_attr.c:1501:8: note: 'shortname' was declared here
  char *shortname;
        ^~~~~~~~~
  CC(target) Release/obj.target/ext2fs/deps/e2fsprogs/lib/ext2fs/extent.o
  CC(target) Release/obj.target/ext2fs/deps/e2fsprogs/lib/ext2fs/fallocate.o
  CC(target) Release/obj.target/ext2fs/deps/e2fsprogs/lib/ext2fs/fileio.o
  CC(target) Release/obj.target/ext2fs/deps/e2fsprogs/lib/ext2fs/finddev.o
  CC(target) Release/obj.target/ext2fs/deps/e2fsprogs/lib/ext2fs/flushb.o
  CC(target) Release/obj.target/ext2fs/deps/e2fsprogs/lib/ext2fs/freefs.o
  CC(target) Release/obj.target/ext2fs/deps/e2fsprogs/lib/ext2fs/gen_bitmap64.o
  CC(target) Release/obj.target/ext2fs/deps/e2fsprogs/lib/ext2fs/gen_bitmap.o
  CC(target) Release/obj.target/ext2fs/deps/e2fsprogs/lib/ext2fs/get_num_dirs.o
  CC(target) Release/obj.target/ext2fs/deps/e2fsprogs/lib/ext2fs/get_pathname.o
  CC(target) Release/obj.target/ext2fs/deps/e2fsprogs/lib/ext2fs/getsectsize.o
../deps/e2fsprogs/lib/ext2fs/getsectsize.c:34:22: fatal error: linux/fd.h: No such file or directory
 #include <linux/fd.h>
                      ^
compilation terminated.
make: *** [ext2fs.target.mk:184: Release/obj.target/ext2fs/deps/e2fsprogs/lib/ext2fs/getsectsize.o] Error 1
make: Leaving directory '/usr/local/lib/node_modules/balena-cli/node_modules/ext2fs/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:188:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:254:12)
gyp ERR! System Linux 4.14.79-v7+
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/balena-cli/node_modules/ext2fs
gyp ERR! node -v v11.6.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
npm WARN balena-request@10.0.1 requires a peer of balena-auth@^2.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN resin-register-device@5.0.0 requires a peer of resin-request@^9.0.2 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: removedrive@1.1.2 (node_modules/balena-cli/node_modules/removedrive):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for removedrive@1.1.2: wanted {"os":"win32","arch":"any"} (current: {"os":"linux","arch":"arm"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: winusb-driver-generator@1.2.4 (node_modules/balena-cli/node_modules/winusb-driver-generator):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for winusb-driver-generator@1.2.4: wanted {"os":"win32","arch":"any"} (current: {"os":"linux","arch":"arm"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: macmount@1.0.0 (node_modules/balena-cli/node_modules/macmount):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for macmount@1.0.0: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"arm"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ext2fs@1.0.26 install: `prebuild-install || node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the ext2fs@1.0.26 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-02-04T09_43_48_997Z-debug.log

I can attach the full log if necessary.
I tried the debian image on osx (balenalib/amd64-debian-node) and that worked.
So I’m currently running the arm (rpi2) version of that image to see how that goes.
I’ll report back as soon as it’s finished.

Thanks, for looking into it.


#14

Unfortunately it failed also with the debian image.
So here’s the complete log (at least I think it’s complete):
debug.log (639.0 KB)


#15

Hi @electrobusch,
So it looks like you’re missing the kernel headers as well. I’ve used the balenalib/raspberry-pi2-node which you were originally trying to use and the build-essential package to include the headers, make, etc:

FROM balenalib/raspberry-pi2-node

RUN apt-get update && apt-get install -yq \
    git build-essential python && \
    apt-get clean && rm -rf /var/lib/apt/lists/*

RUN npm -g i balena-cli

CMD ["balena", "version", "&&", "sleep", "200000"]

This builds correctly (although I’ve not tested it, I don’t have a Pi2 unfortunately), and I would expect it to work.

Let me know if that helps!

Best regards, Heds


#17

Thank you, I’ll give it a shot and let you know if it works.


#18

Hooray! It worked. Thanks again. :+1:


#19

That’s great news, you’re most welcome. :slight_smile: