Streamlining our Snapcraft builds with Circle CI

We’re building Snaps, we think they’re a great package to work with, but we’re also tired of building these packages by hand and would like to get some CI goodness going. At Spicule we’re great fans of CircleCI and wanted to leverage some CircleCI build chain stuff without having to deploy a bit docker image with loads of stuff we don’t need.

So I got bored last night and crafted the worlds simplest Docker file with a couple of basic scripts in to fit our needs: https://github.com/spiculedata/circleci-snapcraft

This Docker image is available at buggtb/circleci-snapcraft and I’m sure over time will be extended further, but for now, its enough to get us going.

Whats in it? Not much! 😉 We have git, snapcraft and a tool called expect. Thats about it, but the cool thing is, CircleCI can then leverage that very easily. For example:

version: 2
jobs:
 build:
   docker:
     - image: buggtb/circleci-snapcraft

   working_directory: ~/repo
 
   steps:
     - checkout
     - setup_remote_docker 
     - run: apt -y update
     - run: /run.sh

So we have a very simple build chain that will go away spin up our custom docker image, checkout the code in to ~/repo and then run, apt update and our run.sh script. All the script does is run a snapcraft build, great, then it runs the expect command with another script called snaplogin. For those of you who interact with Snapcraft or Juju you’ll know that you need to authenticate with Ubuntu USSO to push stuff upstream. As great as the tooling in, the logins generally suck, so we have a very simple expect script that fakes a user and logs in for us! (This of course won’t work if you use 2FA). All we do is add USERNAME and PASSWORD environment variables to our Circle CI build, and that will do the login on our behalf. Once this is done, boom, snapcraft push and our new build is queued up waiting for a review or push to a channel.

There may be better ways, and probably more features to add, but for us, it will help us build out our CI solution for Snap packaging quickly, and easily. As ever, comments, suggestions and pull requests welcome!



Leave a Reply