Fastest way to dev on local device

My project is based on the Pi Zero W, and because of that it is terribly slow, even code syncs. After working on this project for over a year I have come to a couple of different optimizations and workflow changes to make development as fast as possible. Hopefully this will help someone in the future!

First: Use the Docker cache

Second: If using Raspberry Pi, use PiWheels! Its awesome! No more compiling numpy for days on end. No more accidently breaking the cache and having to twiddle thumbs for a few hours during the workday.

Third: Use base images: When building a base image on your computer, you have these lines at the start and end of the base image dockerfile:

RUN [ "cross-build-start" ]
RUN [ "cross-build-end" ]

which I think means its cross compiling on my computer. You should do all apt-get install and pip install commands in the base image. If I am just testing a package, I only install that one package in the standard dockerfile used in the push, or I use PiWheels so its much faster.

Lastest: Use sshfs! I’ve been using this command for a mounting cloud servers to my host machine, and its pretty convenient. It uses ssh in order to mount remote filesystems into a folder on your machine. Install sshfs on your Balena device, and mount your PCs code folder on the Balena device.

Workflow Without sshfs:

balena local push

wait for it to push, once its done you can kill it and ssh in:

ctrl-C
balena local ssh
tail -f /data/my_application_log.log

Each push takes 10-20 seconds or so, then you ssh, which you have to select which container to ssh into, and then finally you open up the log.

Workflow with sshfs:
SSH into the device twice, one of the windows will be used for viewing the debug log, and one will be used to restart your program. The benefits however, is this ssh session does not get killed on each push.

balena local ssh
sshfs myname@myip:/home/code/ /usr/src/app/code
python3 /usr/src/app/code/app.py
balena local ssh
tail -f /data/my_application_log.log

This configuration lets me edit code on my computer, and immediately run it on my Pi Zero W device. Saves me a good 30 seconds per code change, and helps keep my focus since I am not tempted to switch tasks in the meantime.

1 Like