The go plugin

The Go plugin integrates projects written in Go. This plugin uses the common plugin keywords as well as those for sources. For more information, see Snapcraft parts metadata.

Plugin-specific features and syntax are dependent on which base is being used, as outlined below:

See Go applications for a simple example, or search GitHub for projects already using the plugin.

ⓘ This is a snapcraft plugin. See Snapcraft plugins and Supported plugins for further details on how plugins are used.

base: core22

The go plugin in core22 exclusively requires the use of go.mod.

Additionally, the build environment does not include go by default. To install the latest version, add go to a build-snaps section for the part:

build-snaps:
  - go

This plugin uses the following plugin-specific keywords:

  • go-buildtags (list of strings) Tags to use during the go build. Default is not to use any build tags.

Requires Snapcraft version 7.0+.

base: core20

The go plugin in core20 exclusively requires the use of go.mod.

This plugin uses the following plugin-specific keywords:

  • go-channel (string, default: latest/stable) The snap Store channel to install go from. If set to an empty string, go will be installed using the system’s traditional package manager.

  • go-buildtags (list of strings) Tags to use during the go build. Default is not to use any build tags.

Requires Snapcraft version 4.0+.

base: core18 | core

The go plugin support in core and core18 can be used by Go projects using go get, the command used to grab a project’s dependencies or go mod.

This plugin uses the following plugin-specific keywords:

  • go-channel (string, default: latest/stable) The snap Store channel to install go from. If set to an empty string, go will be installed using the system’s traditional package manager.

  • go-packages (list of strings) Go packages to fetch, these must be a “main” package. Dependencies are pulled in automatically by go get. Packages that are not “main” will not cause an error, but would not be useful either. If the package is a part of the go-importpath the local package
    corresponding to those sources will be used

  • go-importpath (string) This entry tells the checked out source to live within a certain path
    within GOPATH. This is not needed and does not affect go-packages.

  • go-buildtags (list of strings) Tags to use during the go build. Default is not to use any build tags.

Requires Snapcraft version 3.x.

go-channel doesn’t work.

Failed to load plugin: properties failed to load: Additional properties are not allowed (‘go-channel’ was unexpected)

Hello - could you provide a few more details, or a paste of your snapcraft.yaml? For reference, the following snapcraft.yaml with go-channel is working for me:

grv-snapcraft.yaml
name: grv
summary: view and manipulate Git repositories from the command line
description: |
     GRV is a terminal based interface for viewing Git repositories. It
     allows refs, commits and diffs to be viewed, searched and filtered.
     The behaviour and style can be customised through configuration. A query
     language can be used to filter refs and commits, see the Documentation
     section for more information.
adopt-info: grv
grade: stable
base: core18

confinement: strict

apps:
  grv:
    command: bin/grv
    plugs:
      - home
      - network
parts:
  libgit2:
    plugin: cmake
    source: https://github.com/libgit2/libgit2.git
    source-type: git
    build-packages:
        - libssl-dev
        - libssh-dev
        - libncursesw5-dev
  grv:
    plugin: go
    go-channel: 1.11/stable
    after:
      - libgit2
    source-type: git
    source: https://github.com/rgburke/grv
    override-pull: |
      snapcraftctl pull
      snapcraftctl set-version \
      "$(git describe --long --tags --always --match=v*.*.* | sed 's/v//')"
    override-build: |
      export GOPATH=$(dirname $SNAPCRAFT_PART_INSTALL)/go
      go get -d github.com/rgburke/grv/cmd/grv
      cd $GOPATH/src/github.com/rgburke/grv
      make install
      mkdir -p $SNAPCRAFT_PART_INSTALL/bin/
      mv grv $SNAPCRAFT_PART_INSTALL/bin/
    go-importpath: github.com/rgburke/grv
    build-packages:
      - pkg-config
      - libreadline-dev
      - libncurses5-dev
    stage-packages:
      - git

I’ve commented lines that caused issues.

name: permaweb-host
#title: Permaweb Host
base: core18
version: git
summary: Throws a Git repo to IPNS
description: |
  Permaweb Host exposes a web interface and an API to add Git repos to IPNS.
  This interface is not protected. Ideally, if you want to sell its services,
  you should create your own web interface with user authentication and a payment gateway.
type: app
confinement: devmode
#license: MIT
grade: devel
parts:
  pwemaweb-host:
    build-packages:
      - git
      - gcc
    build-snaps:
      - go/stable
#      - ipfs/edge
      - node/12/stable
    override-build: |
      sudo npm install --global hogan.js
      npx hulk ./web/mustache/*.html --outputdir ./web/templates/
      go get -u github.com/GeertJohan/go.rice/rice
      ~/go/bin/rice embed-go
      ./scripts/ipfs.sh
      snapcraftctl build
    source: .
    source-type: git
#    stage-snaps:
#      - ipfs/edge
#      - ipfs-cluster/edge
    plugin: go
#    go-channel: stable
#    go-importpath: github.com/Permaweb/Host/

I also created a separate topic.

I’ve encountered so many unexpected problems so far, I’m sorry if I’m a bit salty. I’ll do my best.

It also seems like I’m not the only one to have this problem.

In my case what solved all my problems, was installing snapcraft via snap, because for some stupid reason, the ubuntu repositories had an ages old version of snapcraft that didn’t align with the documentation.

2 Likes

Ah, dammit. I had both installed.

The go plugin doesn’t work with relative source paths. The snapcraft.yaml located in ./contrib/snapcraft/snap/snapcraft.yaml was modified to use parent sources, and started to fail.

image

The failure with source: ../...

Pulling podman 
github.com/containers/libpod/dependencies/dependencies.go:4:2: import "github.com/containers/libpod/vendor/github.com/onsi/ginkgo/ginkgo" is a program, not an importable package
github.com/containers/libpod/dependencies/dependencies.go:5:2: import "github.com/containers/libpod/vendor/github.com/varlink/go/cmd/varlink-go-interface-generator" is a program, not an importable package
go get -t -d ./github.com/containers/libpod/...
Failed to run 'go get -t -d ./github.com/containers/libpod/...' for 'podman': Exited with code 1.
Verify that the part is using the correct parameters and try again.
Exit status: 2

The failure with source: ../../.. is slightly more verbose, and doesn’t work too.

Pulling podman 
package github.com/containers/libpod/cmd/podman/cliconfig: /var/tmp/go/src/github.com/containers/libpod/contrib/snapcraft/parts/podman/go/src/github.com/containers/libpod exists but /var/tmp/go/src/github.com/containers/libpod/contrib/snapcraft/parts/podman/go/src/github.com/containers/libpod/.git does not - stale checkout?
package github.com/containers/libpod/cmd/podman/imagefilters: cannot find package "github.com/containers/libpod/cmd/podman/imagefilters" in any of:
...

This plugin has also other common keywords that can be used, like source and source-type. Can this be mentioned (with a link) in any plugin where this applies?

E.g. In addition to the keywords mentioned here, this plugin also uses source keywords and other common keywords.

Thanks for the suggestion! I’ll add the direct link to sources but doesn’t the first sentence already say something similar to what you’d like to see?

The go plugin in core22 exclusively requires the use of go.mod.

Is it possible to expand what does the plugin do with go.mod? What is so exclusive to that?

Also, what are the build defaults, compared to go build which is run locally in the project root.