Guide to setting up a fully automated CI for Hassio

I’ve finally got something working that I’ve been meaning to do for a while; a continuous integration process for my HA config which automatically validates then deploys and restarts HA. Complete with notifications to my phone as the build progresses.

Here’s a set by step guide to adding the same to your HA config:

  1. Have you config stored it GitHub

  2. Setup Travis with your GitHub

    Most people should be able to use my .travis.yml with little or no editing (I can’t remember who I got the original version of this from or I’d give credit).

    You’ll also need a secrets.yaml.sample which contains blanked out versions of your secrets, the build will complain about any missing secrets in your config otherwise.

  3. Install and configure the Git Pull addon* for Hassio. In the config you only need to put in the repository for your GitHub (e.g. https://github.com/danrspencer/hass-config.git) and turn on auto_restart. It’s worth starting it once to check it’s working, but then you can stop the addon again (and leave off auto start).

    NOTE: The addon wipes your current config folder if you don’t already have it setup with git, so make sure you already have your config backed up at this point!

  4. Copy in my build_ci.yaml package. This sets up some automations which will notify you of your build’s progress; on a passing build it temporarily turns on the Git Pull addon which will update and restart your HA instance. In this you’ll just need to replace the URLs to my Travis with yours.

  5. Push new changes to your GitHub and watch as it gets validated and updates automatically. :+1:

*The GitPull addon can be configured to automatically poll for changes and will validate your config before applying, but I find the added visibility and readability of build output from Travis worth the extra effort.

6 Likes

Thanks for your guide! I am on step 2 and Travis keeps saying I have an invalid config for the http: component. However, when I check the config in the UI it is valid.

Failed config

  http: 

    - Invalid config for [http]: not a file for dictionary value @ data['http']['ssl_certificate']. Got '/ssl/fullchain.pem'

not a file for dictionary value @ data['http']['ssl_key']. Got '/ssl/privkey.pem'. (See /home/travis/build/dnaphreak/hassio-config/./configuration.yaml, line 62). Please check the docs at https://home-assistant.io/components/http/

Has anyone else had this issue?

It seems the issue was the .travis.yml file creates the *.pem files in the root directory but my configuration has them located in the /ssl folder. Adding commands to create the /ssl folder in the .travis.yml file fixed the issue. My .travis.yml file:

language: python
cache: pip
python:
  - "3.5"
install:
  - "pip3 install homeassistant"
script:
  - "mv secrets.yaml.sample secrets.yaml"
  - "sudo mkdir -p /ssl/ && sudo touch /ssl/fullchain.pem"
  - "sudo mkdir -p /ssl/ && sudo touch /ssl/privkey.pem"
  - "hass --version"
  - "hass -c . --script check_config | tee check.output"
  - '! less check.output | grep -q "Failed config"'

This is so awesome, seems to be the missing piece of my own Github automation adventure. Thanks a lot!

I’m a pretty new member in the Home Assistant world, so maybe this is a really dumb question, but I see you have some notifications set up in the build script. Is this linked to the Home Assistant iOS app or something else? Haven’t downloaded the app yet, but would be great to know!

I also have a question about the build script, should this file be included in the configuration.yaml file or should it be added in some other way (don’t forget, I’m a beginner :slight_smile: ). And I guess it should be excluded from the Github repo via .gitignore?

Thank you very much for this, will come in real handy!

I think I have answered my own questions (well, Google and lurking your Github repo has). From what I can tell, like notifications are indeed sent to the iPhone app and it seems like you’re importing the build script in the configuration.yaml file.

So unless I’m mistaken, please ignore my first comment :smiley: