我已经将项目升级到Go 1.11并为我的项目启用了模块支持,但似乎CircleCI正在重新下载每个构建的依赖项。我知道CircleCI允许在重建之间进行缓存,所以我查看了Go模块的文档,虽然它提到了缓存,但我似乎无法找到它实际存在的位置。
Go模块的源缓存在哪里?
截至最终的1.11版本,go模块缓存(用于存储下载的模块和源代码)位于$GOPATH/pkg/mod
位置(请参阅docs here)。为了澄清,go构建缓存(用于存储最近的编译结果)位于不同的位置。
This article,表示它在$GOPATH/src/mod
,但在最近约40天的时间跨度,golang团队必须改变目标位置。 This message thread讨论了为什么下载的项目最终在$GOPATH/pkg
。
您还可以使用go mod download -json
命令查看下载的模块/源元数据及其在本地磁盘上的位置。示例输出如下:
$ go mod download -json
go: finding github.com/aws/aws-sdk-go v1.14.5
go: finding github.com/aws/aws-lambda-go v1.2.0
{
"Path": "github.com/aws/aws-lambda-go",
"Version": "v1.2.0",
"Info": "/go/pkg/mod/cache/download/github.com/aws/aws-lambda-go/@v/v1.2.0.info",
"GoMod": "/go/pkg/mod/cache/download/github.com/aws/aws-lambda-go/@v/v1.2.0.mod",
"Zip": "/go/pkg/mod/cache/download/github.com/aws/aws-lambda-go/@v/v1.2.0.zip",
"Dir": "/go/pkg/mod/github.com/aws/[email protected]",
"Sum": "h1:2f0pbAKMNNhvOkjI9BCrwoeIiduSTlYpD0iKEN1neuQ=",
"GoModSum": "h1:zUsUQhAUjYzR8AuduJPCfhBuKWUaDbQiPOG+ouzmE1A="
}
{
"Path": "github.com/aws/aws-sdk-go",
"Version": "v1.14.5",
"Info": "/go/pkg/mod/cache/download/github.com/aws/aws-sdk-go/@v/v1.14.5.info",
"GoMod": "/go/pkg/mod/cache/download/github.com/aws/aws-sdk-go/@v/v1.14.5.mod",
"Zip": "/go/pkg/mod/cache/download/github.com/aws/aws-sdk-go/@v/v1.14.5.zip",
"Dir": "/go/pkg/mod/github.com/aws/[email protected]",
"Sum": "h1:+l1m6QH6LypE2kL0p/G0Oh7ceCv+IVQ1h5UEBt2xjjU=",
"GoModSum": "h1:ZRmQr0FajVIyZ4ZzBYKG5P3ZqPz9IHG41ZoMu1ADI3k="
}
该输出来自CircleCI 2.0的构建,使用他们的官方circleci/golang:1.11
图像。这是一个人为的例子,展示了如何为新的golang模块缓存位置包含restore_cache
和save_cache
步骤:
steps:
- checkout
- restore_cache:
keys:
- gomod-cache-{{ checksum "go.sum" }}
- run: go vet ./...
- save_cache:
key: gomod-cache-{{ checksum "go.sum" }}
paths:
- /go/pkg/mod