I recently started work on my second add-on for Home Assistant. Unfortunately, that meant a lot more time with the Home Assistant add-on builder. I’d been finding that using the add-on builder was often taking an hour to build the container based add-on, for the four platforms for which I build (e.g. i386, amd64, armv7..). I’d previously looked into why the add-on builder was slow, and had seen comments in the forum about it being due to the emulation of the other hardware platforms – and hence normal.
I did a bit more digging this time in the script that runs the add-on builder, and embarrassingly found out that the builder container was running additional containers inside itself – docker in docker basically – rather than relying on the docker engine of the base host. It works, but its slow. After a bit more digging, it turns out that you need to map the docker.sock file from the host into the builder container, so that you don’t end up with containers inside containers.
With the new configuration, the builds are now taking several minutes instead of an hour.
sudo docker run --rm --privileged \ -v ~/.docker:/root/.docker homeassistant/amd64-builder \ --all -t ADDON_NAME -r ADDON_REPOSITORY -b dev
sudo docker run --rm --privileged \ -v /var/run/docker.sock:/var/run/docker.sock \ -v ~/.docker:/root/.docker homeassistant/amd64-builder \ --all -t ADDON_NAME -r ADDON_REPOSITORY -b dev