"Unknown error executing apt-key" on Apple Silicon

apt-get and install_packages with balenalib/rpi-raspbian images seem to be broken on Apple Silicon. It works fine on Intel (macOS).

I logged a bug "Unknown error executing apt-key" on Apple Silicon · Issue #109 · balena-io-library/resin-rpi-raspbian · GitHub but nobody seems to be paying attention there.

In short:

Doesn’t work on Apple Silicon:

% docker run --platform linux/arm/v6 balenalib/rpi-raspbian:latest apt-get update -y
Get:1 http://archive.raspberrypi.org/debian buster InRelease [32.7 kB]
Get:2 http://archive.raspbian.org/raspbian buster InRelease [15.0 kB]
Err:1 http://archive.raspberrypi.org/debian buster InRelease
  Unknown error executing apt-key
% docker run --platform linux/arm/v6 balenalib/rpi-raspbian:latest apt-key exportall
Warning: apt-key output should not be parsed (stdout is not a terminal)
qemu: uncaught target signal 4 (Illegal instruction) - core dumped
Illegal instruction
% uname -m

Works on Intel (macOS):

% docker run --platform linux/arm/v6 balenalib/rpi-raspbian:latest apt-get update -y
Get:1 http://archive.raspbian.org/raspbian buster InRelease [15.0 kB]
Get:2 http://archive.raspberrypi.org/debian buster InRelease [32.7 kB]
Get:3 http://archive.raspbian.org/raspbian buster/main armhf Packages [18.3 MB]
Get:4 http://archive.raspbian.org/raspbian buster/firmware armhf Packages [1201 B]
Get:5 http://archive.raspbian.org/raspbian buster/non-free armhf Packages [126 kB]
Get:6 http://archive.raspbian.org/raspbian buster/contrib armhf Packages [68.6 kB]
Get:7 http://archive.raspbian.org/raspbian buster/rpi armhf Packages [1299 B]
Get:8 http://archive.raspberrypi.org/debian buster/main armhf Packages [376 kB]
Fetched 18.9 MB in 7s (2638 kB/s)
Reading package lists...
% uname -m

Any ideas for a workaround? This is a blocker for doing Balena local builds and using local mode.

Hi, what Docker version do you have installed on your M1 device? This seems to be a common issue because of the qemu version used by Docker to emulate x86_64:

Can you try upgrading to Docker Desktop 3.3.2 and see if that fixes the issue?

I have the latest v3.3.3 on my M1 device :slightly_frowning_face:

Hi, if you are using local mode on a development device, you should be able to do a balena push directly to the development device. You can also do balena push to balenaCloud and have the builders build the images for you. Are you using openBalena for deployments?

Oh, this is fantastic! For some reason I was under the impression that local mode skipped the cloud infra but still needed the development machine to do the build (and balena build fails here). But balena push to a development device in local mode seems to be working! A bit slow, but maybe still faster than going through the cloud. (We are paying for Balena Cloud.)

Thanks, this helps a lot!

Regarding the reported bug, is it a Balena build issue or blocked on an upstream dependency?

Awesome! Happy to know that balena push to your local device works for you. We also use balena push to a development device on local mode for developing features for balenaCloud. :wink:

The bug is a Docker issue as it seems their emulation for platform types when using Apple M1 is not yet perfect. They will probably have that fixed soon but you can also help them out by posting your findings as an issue in the Docker for Mac Github repo.