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 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

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:

install: true  
  - eval "$(ssh-agent -s)" #start the ssh agent
  - echo -e $RESIN_DEPLOY_KEY > id_rsa
  - chmod 0600 id_rsa
  - ssh-add ./id_rsa
  - cat resinkey >> ~/.ssh/known_hosts
  - git remote add resin $RESIN_REMOTE
  - 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):

  - git remote add resin-staging $RESIN_STAGING_REMOTE
  - git push resin-staging master
  - git remote add resin-production $RESIN_PRODUCTION_REMOTE
  - 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 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.

comments powered by Disqus
Terms of Service | Privacy Statement | Master agreement | Copyright 2019 Balena | All Rights Reserved