summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2019-08-12 14:50:37 +0100
committerNick Thomas <nick@gitlab.com>2019-08-12 15:37:55 +0100
commit89bccb02d1aadb6f336576a16598ba95aad14115 (patch)
tree2cfbe60a9d8047b88b1a21c11da12bea2d72229b /doc
parentd2ecbd747b148d965a7f7ab4f438ad02ca21faf9 (diff)
downloadgitlab-ce-89bccb02d1aadb6f336576a16598ba95aad14115.tar.gz
Don't use go mod vendor
This change comes out of a discussion between Ben Kochie and me, around this MR: https://gitlab.com/gitlab-org/gitlab-pages/merge_requests/164 gitlab-elasticsearch-indexer already uses `go mod` without a `vendor/` directory. It has caused some intermittent build failures in the gitlab-ce/ee CI pipelines, but has otherwise been fine. I think that treating our Go dependencies in the same way we do our Ruby or Node.js ones is reasonable, and it has some minor benefits: * Contributors find it easier to submit MRs * MRs are easier to review * Makefiles are easier to write
Diffstat (limited to 'doc')
-rw-r--r--doc/development/go_guide/index.md26
1 files changed, 26 insertions, 0 deletions
diff --git a/doc/development/go_guide/index.md b/doc/development/go_guide/index.md
index 9f0ac8cc753..83444093f9c 100644
--- a/doc/development/go_guide/index.md
+++ b/doc/development/go_guide/index.md
@@ -107,6 +107,32 @@ Modules](https://github.com/golang/go/wiki/Modules). It provides a way to
define and lock dependencies for reproducible builds. It should be used
whenever possible.
+When Go Modules are in use, there should not be a `vendor/` directory. Instead,
+Go will automatically download dependencies when they are needed to build the
+project. This is in line with how dependencies are handled with Bundler in Ruby
+projects, and makes merge requests easier to review.
+
+In some cases, such as building a Go project for it to act as a dependency of a
+CI run for another project, removing the `vendor/` directory means the code must
+be downloaded repeatedly, which can lead to intermittent problems due to rate
+limiting or network failures. In these circumstances, you should cache the
+downloaded code between runs with a `.gitlab-ci.yml` snippet like this:
+
+```yaml
+.go-cache:
+ variables:
+ GOPATH: $CI_PROJECT_DIR/.go
+ before_script:
+ - mkdir -p .go
+ cache:
+ paths:
+ - .go/pkg/mod/
+
+test:
+ extends: .go-cache
+ # ...
+```
+
There was a [bug on modules
checksums](https://github.com/golang/go/issues/29278) in Go < v1.11.4, so make
sure to use at least this version to avoid `checksum mismatch` errors.