Skip to content

Use Go 1.5's GOMODCACHE to improve docker build times #1227

@Laremere

Description

@Laremere

Currently, the base build docker image performs multiple copies to improve build speed:

  1. Copy over the go.mod and go.sum files.
  2. go get
  3. copy over the rest of the files

This is done so that with docker layer caching, making a small code change doesn't result in it needing to download all dependencies. However whenever the dependencies do change, it does require a full re-download. Plus you need to run go commands locally to get the go.mod / go.sum files to update.

Go 1.5 is adding an environmental variable which allows specifying where the go mod cache is located.

I think the current double copy can be removed, and replaced with:
In the docker build commands, specify a mount of the host machine's go mod cache, and set the environment variable for the go mod cache to that mount (say, "/gomodcache")

This makes it a little more dependent on the host machine, which isn't great for docker. However it simplifies the docker files, plus go.sum is used to perform a checksum of the go mod cache files, so given the immutability here I'm not worried, and think the tradeoffs are worth it.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions