Continuous integration for my config with docker, git, and travis!

I’m pretty new to docker, and hass so PLEASE make suggestions (pull requests would be amazing!) :slight_smile: Hopefully everyone can learn something!

TLDR
I can now modify my files on any machine with git, commit the changes and if travis passes the build my HASS instance will update it’s config and restart to re-load the config.

The setup
I like to run everything in docker - so HASS is in docker running on Ubuntu.

Implementation
Firstly get your config into git, and configure travis to automatically test your builds - the guide is really good, and I have nothing to add to it!

After your config is backed up, and travis is configured it’s time to use webhooks to get your HASS to update git, and reboot the docker image automatically (if the tests pass)

I’ve created a simple docker image that can validate a travis webhook and call a script - you can find the image on dockerhub. This image is responsible for calling the script that will update your local config when the build tests all pass.

Note the script runs in the docker container… so this is where I think improvements can probably be made.

My script creates a text file called “update-hass.txt” in the scripts volume the docker container uses.

I then have the following script that checks to see if the file exists. If it does I do a pull from git, then I reset my HASS docker container

This script simply runs as a cron job every minute.

Finally you need to update .travis.yml to call the notification handler:

Potential improvements
I’m sure you can watch for files being creating in linux, but I’m not too worried about that - also my shares are mounted from a network share and I’ve had lots of issues with file watches working with this setup.

Currently if I modify a config file, then commit it to git it causes travis to build, then the webhook call makes my HASS reboot. This is totally pointless as nothing has changed. I’m sure there will be a way to modify the autoupdate.sh script to only restart docker if something changes.

5 Likes

First of all, thanks for sharing!

I am looking at a way to build a robust way to both be able to quickly get many changes integrated easily, and on the other hand minimize downtime and keep the setup up and running so that other members in my household actually enjoy using it.

An improvement that I am thinking about setting up (now only find the time, right) is have a change in configs, result in a new version of the docker image. I.e. build a new container with the changed configs in it. That way, you could quickly move forward by stopping the now “old” container and spin up the new version. But if something turns out to be wrong with the new one, or it does not quite work the way you wanted to, easily switch back. I lack the skills to this yet, but I’m learning…

Keep us all posted, please!

OOO. I REALLY like this idea… the only problem would be the state (also when the base image updates I’d have to trigger a new build…)

hmm I’ll have a think!

Maybe not include the database in the image but in a separate instance? Although that could be difficult when the database needs a data model change (not sure if/how often that happens though) The current docker image does not work that way. Or maybe it is possible to create a way (component?) to export the state upon a shutdown of the home assistant service, which can be imported in a new instance…

I would like to do something similar with a mosquitto container that can be upgraded/changed so I can run two instances on the same hardware platform, one for “production” and one for dev/test when building diy sensor nodes using mqtt. Keeping states (retained messages) between versioned containers is tricky there too…