Developing Multi-Device Support?

I’m developing an Octoprint container and I’m wondering what the best method of developing for multiple targets is? Currently I’m making branches for those devices, but is there a better method? There is a lot of overlap between the dockerfile I’ve made for an Orange Pi Zero and a regular Pi for example, and I wouldn’t want to have to make duplicate changes every single time I push an update.

Hey, have you checked out our Dockerfile.templates: https://www.balena.io/docs/learn/develop/dockerfile/#dockerfile-templates ? They are designed to help this case of having a single codebase for multiple device types

I haven’t, thanks for guiding me in that direction :slight_smile:

Actually I’ve just read this, I think you’re misunderstanding what I’m saying. In my project there are reasons why the build fails for an Orange Pi Zero, but do not fail on a Raspberry Pi Zero.

Raspberry Pi:

# Install deps
  && apk add --no-cache \
        avahi \
        avahi-compat-libdns_sd \
        avrdude \
        curl \
        imagemagick \
        python \
        py-pip \
        raspberrypi-libs \
        raspberrypi-dev \

Orange Pi:

  && apk add --no-cache \
        avahi \
        avahi-compat-libdns_sd \
        avrdude \
        curl \
        imagemagick \
        python \
        py-pip \
        libffi-dev \
        openssl-dev \

The difference here is caused by a multitude of different things. One is that the Raspberry Pi has raspberrypi-libs and raspberrypi-dev, both of which are required to interact with hardware like cameras.

The orange pi needs libffi-dev, avahi-compat-libdns_sd and openssl-dev for some reason, because errors are thrown if they are not present, whereas they are not in the alpine image for the raspberry pi. I do not know why.

Either way, your documentation does not resolve this problem easily. I still need two dockerfiles that otherwise overlap just to change dependencies per device. How can I resolve this need to duplicate effort?

All of the other build steps are the same, it is just the dependencies that change between the OPi Zero and the Raspi 3. So is it not possible to have a theoretical Dependencyfile.raspberrypi3 and Dependencyfile.orangepizero in order to run this layer separately and not have to edit the large build file considering the steps are otherwise the same in both?

Hi @matthewcroughan ,

You should be able to utilise the BALENA_MACHINE_NAME builder variable to make changes based on the target. For example, if %%BALENA_MACHINE_NAME%% is raspberry-pi then install the packages required for the Pi Zero, and if not then install those required for the Orange Pi Zero, something like:

RUN if [ %%BALENA_ARCH%% = "raspberry-pi" ] ; then <INSTALL PI ZERO PACKAGES> else <INSTALL ORANGE PI ZERO PACKAGES>; fi

Best regards,

Heds

That file would get quite large as your device support expanded. Are you saying this would be a well accepted method of doing this?

Hi,

For two devices, then this seems an acceptable method for doing so. If you’re going to support many devices, then just like any other script, if the divergence becomes greater than the common parts, then using separate Dockerfiles makes far more sense (and in fact several of our own projects do just that).

Best regards,

Heds