Snaps are easy

  2016-10-14


Snaps are easy and I like that.

Now, I know what you are thinking, this guy works for Canonical, he is biased but If you ask around you will know that I actually am not, I have been very critical of Canonical in the past and I am the first to admit that, for instance, even though I like ppas I hate launchpad.

Some time ago I decided that I wanted to try caddy and that the best way to do that, like everything else in my server, was “the debian way”™ so I embarked in the unhappy packaging task and had to let some water go under the bridge before getting to the task of maintaining it. Recently I wrote a tool that allows me to have an easily isolated env for caddy and therefore generate the codebase I need to publish each version as the new deb file source.

As part of my continuous self education, and because it was very easy, I decided to try a snap to feel how much was the actual difference between building a snap and a deb. To build it I used snapcraft which is basically the easiest way to do snaps and leveraged the existing go plugin. For the moment all my snap provides is the base caddy binary but here is my todo list:

  • Build from a tag (requires some extra step because caddy doesn’t do vendoring).
  • Build all plugins (I have no clue how to do this).
  • Include systemd scripts.

Now, upon trying both methods, ill lay out the facts and let you judge.

What building the ppa took (and takes).

Note: this is for the particular way of packaging I chose, with more debian-fu you can create packages in a different way that does not go really well with go

  • Research for a good couple of days on how is a debian package done.
  • Checkout the code for the project and all its dependencies and export it into the debian file structure.
  • Write Debian specific files for all the extra stuff I needed like systemd files and such.
  • Try it in an awful, heavy and slow tool that does this for debian files (It basically debootstraps a whole env I believe).
  • Fight with “the debian way”™ requiring the most insane packaging for go and its packages and having the right go deb.
  • Puch to launchpad.
  • Discover how to get my ppa to build there properly.
  • A couple of sprinkled failures and things from launchpad to set up.

What building the snap took.

  • run snapcraft init
  • Express my desires in the following file.
    name: caddy-hduran
    version: '0.9.3'
    summary: The HTTP/2 web server with automatic HTTPS
    description: |
     Caddy is a lightweight, general-purpose web server for Windows, Mac, Linux, BSD and Android. 
     It is a capable alternative to other popular and easy to use web servers. (@caddyserver on Twitter)
     The most notable features are HTTP/2, Let's Encrypt support, Virtual Hosts, TLS + SNI, and easy 
     configuration with a Caddyfile. In development, you usually put one Caddyfile with each site. 
     In production, Caddy serves HTTPS by default and manages all cryptographic assets for you.
    
    grade: stable
    confinement: strict
    
    apps:
      caddy:
        command: bin/caddy
        plugs: [network, network-bind]
    
    parts:
      caddy:
        plugin: go
        go-importpath: github.com/mholt/caddy
        source: https://github.com/mholt/caddy
        source-type: git
        snap:
        - bin/caddy
    
  • run snapcraft (at this point I already have an installable snap package)
  • run snapcraft push caddy-hduran_0.9.3_amd64.snap (at this point I have my snap in the snap site under my two-click-process registered name.
  • add the yaml file to the previously mentioned debian file repo, at the root
  • push it.
  • click around in launchpad discovering how to turn snap on and enable it (at this point launchpad is uploading the builds for my snap for many archs to my namespace in the apps store.

So, if I just wanted to create the snap package for my arch and run caddy in a constrained env, the first 3 steps are enough, you dont have to believe me, just download the yaml and run snapcraft on the same folder, you get the snap in the time it takes to fetch the code and compile, try it, change it, own it, enjoy it, I know I will, my .deb files are reaching an end:

The world is changed.

I feel it in the water.

I feel it in the earth.

I smell it in the air (Elvish translation).

Much that once was is lost;

for none now live who remember it.

– Cate Blanchett Playing Galadriel (honestly I have no clue who to attribute the quote autoring)

comments powered by Disqus