Getting somewhere with this. I’ll make some notes here in case it helps someone else.
Firstly, I’m focusing on a server-only plugin as that’s all I need for now, so haven’t got anywhere with making the web app part work.
MM Plugins are created in the Golang programming language, and pretty much all the initial problems I experienced here relate to downstream code dependencies. Code dependencies are complex in Golang. Modules are downloaded in source form (typically from other Github repos), and then the go.mod and go.sum files are used to work out which versions of dependencies work together, before building the target. Dependencies can themselves depend on other things, and you end up with a spider’s web of dependencies which can be difficult to untangle. The tooling normally takes care of this, but manual untangling this is messy.
I started with the barebones plugin template (mattermost-plugin-starter-template). The problems I faced were:
- References to modules which don’t exist (did exist at some point, but got renamed). There’s a sourcegraph library, and an ASN.1 BER library.
- The build had WAAAY too many dependencies to be practical. There’s a JSON encoder/decoder library (gojay) which somehow managed to depend on Google Cloud API modules. Long story short, this used over 5GB downloads and took more than 15 minutes to compile from cold. It’s manageable if you’re compiling all this stuff on a local machine because the dependencies get cached, but I build stuff in Github pipelines.
The fix for me was two-fold:
- Update everything to later dependencies which seemed to clear out all the references to packages which don’t exist any more.
- Fixed the gojay library by taking out the gojay and examples directories which don’t contain anything you need in a plugin. This involved forking the gojay library and deleting that stuff.
Down to 300MB of downloaded modules, and builds from a clean module cache in 30 seconds.
If you’re thinking of giving this a go maybe you would delete the go.sum file and replace the go.mod file with this…
module example/module/name
go 1.20
replace github.com/francoispqt/gojay v1.2.13 => github.com/kalntera/gojay v0.0.0-20240119150629-2858d078a506
require (
github.com/gorilla/mux v1.8.1
github.com/mattermost/mattermost/server/public v0.0.12
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.4
)
And then try go mod tidy -e
and all the other stuff you normally do to compute dependencies e.g. install things when the errors tell you to. There’s a reference there to GitHub - kalntera/gojay: high performance JSON encoder/decoder with stream API for Golang (reduced dependencies) which is my copy of the gojay library. The replace line is used to switch out a module for a different one, that overrides the default gojay import.