Build snap in gitlab ci

I build snaps for my programm with GitLab CI and upload it to Snapcraft. I use this Code:

snapcraft_deploy:
    stage: deploy
    image: "ubuntu:latest"
    script:
        - apt update
        - apt install -y snapcraft
        - snapcraft
        - snapcraft login --with $SNAPCRAFT_LOGIN_DATA
        - snapcraft push --release=stable jdtextedit_7.2_amd64.snap
    artifacts:
        paths:
            - jdtextedit_7.2_amd64.snap
    only:
        - tags

But in 20.04 snapcraft is only available as snap, which does not work with Docker, which is usesd by GitLab CI. How can I build my snaps now?

1 Like

They’re not official, but you might have better luck using the cibuilds/snapcraft images. It provides core16 and core18 tags: the idea being to pick the one that matches your project’s base snap. So your job might be simplified to:

snapcraft_deploy:
    stage: deploy
    image: "cibuilds/snapcraft:core18"
    script:
        - snapcraft
        ...

Note that there are limitations to this method: as snapd does not function within a Docker container, this won’t work to build projects that make use of the build-snaps feature to install snaps on the build machine.

I’m also maintaining Container Images in Docker Hub. You might find mine are more suitable if you need to build for other architectures than amd64, or core20: https://hub.docker.com/r/diddledan/snapcraft

How about using the documentation in here?: https://snapcraft.io/docs/snapcraft-docker-images

I’m guessing it needs an update though (seems to hardcode “16”, as in 16.04), to make it work with Ubuntu 20.04, cause after trying it I get the error:

 /snap/bin/snapcraft: 3: exec: /snap/snapcraft/current/usr/bin/python3: not found

If anyone wants to know the exact bits of the build:

https://gitlab.com/knocte/fsx/-/blob/snapWithUbuntu20-04/install_snapcraft_dockerless.sh

1 Like

Unfortunately, it seems that neither the Docker image from @lucyllewy nor those from cibuilds work anymore.

I’m having more luck with using ubuntudesktop/gnome-3-38-2004 , which I copied from the Remmina repository.

The only viable way to build in a continuous way is the build service now. This is bad news for anyone who wants to publish a proprietary snap.

What’s the buildservice?

My app is not proprietary so I might give this a go in case it’s better than using GitHubActions (which is what I ended up using instead of GitLabCI, FTR).

Try this, https://gitlab.com/Remmina/Remmina/-/blob/master/.gitlab-ci.yml?ref_type=heads

1 Like