Building a snap on bitbucket pipelines

Hi

I am trying to introduce snaps on my job to build our internal tools. I found snaps a great way to update the software across the office…

I want to automate the building and upload to store process. In my company we use bitbucket pipelines for continuous deployment, so I want to build my snaps inside bitbucket.

To build my snap I use “base: core18” and multipass. I understand multipass uses virtual machines to build in a clean environment. But I can not get to work this on bitbucket. I know pipeline runs on docker so what I want is a way to build a snap inside a docker container.

Is there an official docker image to build a snap on docker? I found this article https://docs.snapcraft.io/build-on-docker/4158 but it seems to use and old version of snapcraft.

Please, can anyone point me in the right direction

You can build snaps using snapcraft running in a docker container, however when running in a docker container, snapcraft won’t be able to install any snaps, and so you won’t be able to use build-snaps anywhere in your snapcraft.yaml and you will need to match the base you choose with the docker container that it runs on, i.e. if you’re using base: core18 then you need to build with a ubuntu:18.04 docker base image.

Additionally, the upstream docker images for snapcraft are only published for amd64, so if you need to build on other architectures you will need to roll your own snapcraft docker images.

Thanks for the fast answer!!!

I tried that a couple of days ago. I installed snapd inside a container trying to install snapcraft from snap. But as you say, it is not possible. But the version of snapcraft available on apt is very old (2.43.1+18.04)… I was not able to build my snap…

Is there another way to install snapcraft inside the container?

Here’s the Dockerfile used to build the snapcraft docker images:

https://github.com/snapcore/snapcraft/blob/master/docker/stable.Dockerfile

You might be able to use similar logic (downloading and unpacking the core and snapcraft snaps, then copying over a wrapper that sets the environment variables) in an 18.04 container.

1 Like

Wow! thanks!! I will try this in the morning ;)… I will let you know if I success :smiley:

I can confirm that this exactly works… we currently run daily builds for the edgexfoundry snap in a docker container on jenkins this way. Note that going down this route you will encounter https://bugs.launchpad.net/snapcraft/+bug/1826611

2 Likes

thanks again. I will try it tomorrow.

In the end I managed to build it on pipelines using a plain 18.04 image. These are the steps I used if someone need them. Also I exported my credentials to a “login-credentials” files to push the snap to the store.

  • apt update
  • apt dist-upgrade --yes
  • apt install snapcraft -y
  • snapcraft
  • snapcraft login --with login-credentials
  • snapcraft push my.snap

Note that installing snapcraft via apt will only get you version 2.43 and as such your snap will be built with an older version of snapcraft than is currently maintained. Additionally, AFAIK only security bugs will be backported to the deb going forward, so no new features (such as support for bases) will be available in the deb.

I personally use the Dockerfiles located here, depending on the base being used:

1 Like

Thanks… I will use other solution in the future

Wow!, thanks for the link to snap-builder. I’ll try to use it to build my snap. I whish it were easier. I love to build snaps because it is easy, but for CI no so :frowning:

@alejandro.vera What docker image did you end up using to build snaps in bitbucket pipeline?