I’ve been playing a lot with OpenFaaS lately, but one of the things that’s been annoying me about it is how slow it is to build the images on my Raspberry Pi (I need ARM images as I’m running OpenFaaS on my Raspberry Pi). Whilst scrolling through their documentation I found something interesting, you can build just the Dockerfile.
This gave me the idea that I can use Docker’s new feature BuildX. BuildX is an experimental feature that ships with 19.03+ and allows you to build multi-arch images from another machine e.g. my laptop.
If you’ve never used OpenFaaS but are intrigued, Alex Ellis has a great blog post on how to set this up in a few minutes on that spare Raspberry Pi that we all have knocking about.
I’m going to generate a blank function to demonstrate this functionality with, so we’ll need to ensure we’ve got a template and create a blank function.
faas-cli new --lang node10-express-armhf function
This will create you a function.yml as well as folder with the outline of a new OpenFaaS function.
faas build --shrinkwrap -f function.yml
After a couple of seconds this will generate a Dockerfile for you in a new directory build/function/
docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 -t mikegrant/openfaas-function --push ./build/function/
If you’ve used docker before, then you should recognise a lot of this output. It’s simply just doing the same tasks across each of the platforms you have selected, creating a manifest file at the end and pushing the images and manifest file to the relevant registry. Once it’s complete, you’ll have images for all the platforms that you can now use accross your OpenFaaS instances, and my issues with slow builds for my raspberry pi is gone!