Go plugin ignores GOPATH


Since a couple of hours the containerd part [1] on MicroK8s is failing to build. Here is how it is failing:

+ snap refresh go --channel=1.15/stable
snap "go" has no updates available
+ go version
go version go1.15.5 linux/amd64
+ realpath ../go
+ export GOPATH=/root/parts/containerd/go
+ go get -d github.com/opencontainers/runc
+ cd /root/parts/containerd/go/src/github.com/opencontainers/runc
/bin/sh: 55: cd: can't cd to /root/parts/containerd/go/src/github.com/opencontainers/runc

On the debug console I see that the github.com/opencontainers/runc was not created under the export GOPATH=/root/parts/containerd/go. It is as if the export GOPATH is ignored.

Tried to snap revert snapcraft but had the same error with v4.4.2.

A workaround is to move to the dump plugin.


It looks like you’re not using the go plugin’s functionality, instead replacing the inbuilt build step with your own script. The problem, therefore, is likely either with your override-build script or go itself, which you’re installing with the go snap.

I suspect the underlying cause is this change to containerd:


Your project built successfully when containerd did not include a go.mod file, and fails now that they’ve added one.

Both the Go toolchain and Snapcraft’s Go plugin behave a little differently when building module aware code. In particular, modules downloaded with go get end up in $GOPATH/pkg/mod ratheer than $GOPATH/src.

You will either need to pin to an older release of containerd, or update your snapcraft.yaml to account for the upstream changes.

Thank you for your help.

I think I’ll go with the dump plugin since as you said i am already overriding the go plugin logic.