Continuous integration on your devices

Deploy to Resin from GitHub using Travis CI We’ve heard from several users that it would be nice for Resin to ‘watch’ a GitHub repository and deploy directly from there to Resin-connected devices. So we prepared a simple demo project that uses Travis CI [https://travis-ci.org] to accomplish this. Another benefit is centralized build logs. We…

Deploy to Resin from GitHub using Travis CI

We’ve heard from several users that it would be nice for Resin to “watch” a GitHub repository and deploy directly from there to Resin-connected devices. So we prepared a simple demo project that uses Travis CI to accomplish this.

Another benefit is centralized build logs. We are working on native feature where all builds are accessible from the UI rather than just the local machine the code was pushed from but for until then you can use Travis CI’s build tracking to help your team work together with resin.io.

The project is available on GitHub, so feel free to fork it or base your projects on it.

The idea is simple: every time you push to your GitHub repo, Travis will also push the master branch to Resin’s git remote.

The main thing you need to make this work is a .travis.yml file:

yml
install: true
script:
- eval "" #start the ssh agent
- echo -e > id_rsa
- chmod 0600 id_rsa
- ssh-add ./id_rsa
- cat resinkey >> ~/.ssh/known_hosts
- git remote add resin
- git push resin master

The two environment variables involved can be set on the Travis settings page for your project: RESIN_REMOTE is the Resin git endpoint for your application, and RESIN_DEPLOY_KEY is a private SSH key that has permissions for your Resin remote. The project’s README has instructions on how to generate this key. We also add Resin’s SSH fingerprints to the known hosts in Travis’s environment.

Once you have this setup, you can see Charlie the unicorn on the Travis project page!
Hi Charlie!

This is a simple setup, but the same idea could be used for more complex stuff. For instance, you could make each branch push to a test application, so that you can ensure your Dockerfile builds before merging a Pull Request. Or you could have a staging App (in your Resin dashboard) where you always push master, and a production App where you push a production branch to automatically update your customers’ devices with code you already tested on staging.

This could be done like this (in .travis.yml):

yml
- git remote add resin-staging
- git push resin-staging master
- git remote add resin-production
- git push resin-production production:master

This opens the door to sophisticated continuous integration in IoT, leveraging known tools from the world of Web development and the power of Resin.io as a devops platform.

And most importantly, it allows you to add a nice little badge to your project’s README:
It should be passing...

Have questions, or just want to say hi? Find us on our community chat.


Posted

in

Tags: