I’m not quite sure if this is a feature request or a support issue requesting help with a better workflow. When building a Balena project on Raspberry Pi Zero W with the application in Python. Local mode takes FOREVER to build the container because it is building locally on the RPi Zero. Every time I make changes to the container (e.g. editing Dockerfile, adding additional install_packages, changing my requirements.txt (Python is building all the libraries locally on the ARM architecture and it takes a many hours to build numpy wheels on RPi Zero)) the cycle time is hours. Maybe there is opportunity to optimize my Dockerfile to make better use of caching, but that’s a bit of a separate thread.
I really want a workflow where large builds are performed on the cloud and then downloaded locally but I can still attach to the local device ( balena push NNNNNNN.local) so that Livepush can function afterwards. Even if this is just the initial deploy built on the cloud and the current local mode is used after that?
I might be missing something simple like the proper use of the cross build commands in my Dockerfile as mentioned here… Fastest way to dev on local device
@ab77 I found how to build locally and push locally in the balena CLI masterclass. Local build works great using balena build --arch rpi --deviceType raspberry-pi --emulated. And I see how to deploy locally using balena push 827b231.local– but that still tries to build on the Rpi Zero.
The CLI docs (--help for deploy or push) don’t seem to explain how to get the container I built on my computer onto my local device.
balena push --help
Usage: push
This command can be used to start a build on the remote balena cloud builders,
or a local mode balena device.
When building on the balenaCloud servers, the given source directory will be
sent to the remote server. This can be used as a drop-in replacement for the
“git push” deployment method.
When building on a local mode device, the given source directory will be
built on the device, and the resulting containers will be run on the device.
Logs will be streamed back from the device as part of the same invocation.
Use this command to deploy an image or a complete multicontainer project to an
application, optionally building it first. The source images are searched for
(and optionally built) using the docker daemon in your development machine or
balena device. (See also the balena push command for the option of building
the image in the balenaCloud build servers.)
push doesn’t let you specify a local, already built, container. And deploy doesn’t let you specify a local device… am I missing something obvious?
Hi @ductape – you’re right that balena push does build on the device. What you can try is:
Ensure your Dockerfile has the package installation steps (or any other steps that take a long time) close to the beginning of the file, so they make an earlier Docker layer
Run balena deploy <appName> <image> (to send your laptop-built image up to balena Cloud), or balena push <appName> (to have the balena Cloud builders build the image)
Switch the device out of local mode, and ensure the device pulls down that image
Switch back to local mode, and ensure that any additional changes come in subsequent Docker layers; this should end up re-using the earlier, cloud-built layers
Can you give that a try and let us know how it goes?
Thanks @saintaardvark, that’s a much improved workflow! It looks like that will work. I tried it and looks like the cached version is used for the existing steps (it’s not trying to reinstall the OS dependencies or rebuild my Python dependencies now.
I can’t promise it works because it seems the local mode CLI is getting some node error (I’m using a Python container?) before the logging starts, but I believe that’s unrelated to this posting.
It looks like a crash caused by one of the module used by balena-cli (net-kepalive).
Please let us know if you reproduce this on the latest CLI version. If yes, we’ll ask our CLI maintainers to take a look.
@roman-mazur it looks like the same error is still there in balena-cli v11.35.1. I see there is another update to the CLI, so I’ll try that and post back later.
Also for reference, I’m running macOS 10.15.4 using bash as shell and homebrew to install the Balena CLI. System is running Docker version 19.03.8 build afacb8b. There is expectedly no difference in result when using native terminal app or vscode terminal.
@ductape, I’ve seen some stack traces like that before, with Node.js v14. The balena CLI is not yet compatible with Node.js v14. Also, homebrew is not an official distribution channel for the balena CLI – I understand it is maintained by some balena users. The supported installation methods and Node.js versions are documented at: https://github.com/balena-io/balena-cli/blob/master/INSTALL.md
Try one of the methods documented there, and/or downgrade Node.js to v12 (e.g. 12.16.3). Let us know if this solves the issue for you.