Snapcraft Login in Docker Image

I’m building a native app so I have a relatively involved CI pipeline that builds for Linux/Windows/Mac. In order to build for Mac I have to build on Mac because I need to link against SDKs that have ugly licenses. I’ve been building a Snap on Mac by using the snapcore/snapcraft Docker image.

I can get the build working totally fine, but I’m struggling to get publishing working. I have a very simple script that let’s me invoke snapcraft:

#!/usr/bin/env bash

docker run -v $PWD:/build -w /build --env SNAPCRAFT_STORE_CREDENTIALS snapcore/snapcraft:stable snapcraft $@

But the env variable doesn’t seem to get picked up. When I run whoami I get the following error:

You need to first login to use this command.

Am I trying to do something that isn’t actually possible? Or am I missing something?

I figured this out.

I was using the snapcore/snapcraft:stable Docker image which was too old for the SNAPCRAFT_STORE_CREDENTIALS environment variable.

I had to build a custom Docker image that was >= 7 and publish it. For anyone else struggling with this the defaults in the Dockerfile for snapcraft don’t work. The following combination worked for me:

ARG RISK=stable
ARG UBUNTU=bionic