Building Hugo with Go Modules and Athens 🎉
Hey Gophers! We're gonna build Hugo with Go Modules and Athens. I gave this demo at CodeMotion Rome 2019 in the session titled "Using the Athens Proxy to Improve Your Golang Projects"
Below is how how to do the demo yourself. The instructions are for Linux/Mac OS X systems.
You can do this anywhere on your system:
$ git clone https://github.com/gohugoio/hugo.git && cd hugo
This will make go
talk to Athens for all its dependencies, not directly to the VCS:
$ export GOPROXY=https://athens.azurefd.net
Note: the proxy at this URL is experimental and should not be used in production settings
This will force go
to ask Athens for all the dependencies. You have to run this with sudo
because the Go toolchain restricts modules to read-only. It tries to keep dependencies immutable too, just like Athens does! 😄.
$ sudo rm -r $GOPATH/pkg/mod
No need to change your familiar tools to do this:
$ go build .
Just to make sure things worked properly:
$ ls -al ./hugo
$ ./hugo version
You can use Athens for any project that uses Go modules. Just set GOPROXY to https://athens.azurefd.net in your environment.
But remember, that URL is an experimental Athens server for now. Please do not rely on it for production code.
If you'd rather not rely on the public Athens (it is experimental after all!), then run your own! The easiest way to do that -- and the way I recommend -- is using Docker. Run this to start up Athens:
$ docker run -p 3000:3000 -e GO_ENV=development gomods/athens:v0.3.1
And then to set your environment variable to point to the local server:
$ export GOPROXY=http://localhost:3000
From here, go back and clear your cache and build Hugo again. Magic!!!
If you want to learn more, check out docs.gomods.io! And we'd love for you to get involved! Here are some ways to do so:
- Come star our repo
- Come say hello on the
#athens
channel in the Gophers Slack- This is a great place to come ask for help getting started and ask questions too 😄
- Come to one of our developer meetings. Absolutely everybody is welcome, regardless of experience, background or anything else
- And of course, file bug reports or feature requests and contribute code!