Amazon web services 在codebuild中缓存go模块而不使用自定义docker映像 TL;博士
如何使用AWS提供的映像(Go 1.12)在代码构建中缓存模块 背景 我试图使用AWS的go映像(1.12)在代码构建中缓存go模块 正在尝试缓存/go/pkg/mod 在深入挖掘之后,我发现该图像中没有Amazon web services 在codebuild中缓存go模块而不使用自定义docker映像 TL;博士,amazon-web-services,go,caching,aws-codebuild,Amazon Web Services,Go,Caching,Aws Codebuild,如何使用AWS提供的映像(Go 1.12)在代码构建中缓存模块 背景 我试图使用AWS的go映像(1.12)在代码构建中缓存go模块 正在尝试缓存/go/pkg/mod 在深入挖掘之后,我发现该图像中没有/go/pkg文件夹。因此,当我试图缓存/go/pkg时,它会抛出一个错误 装载/go/pkg/mod:symlink/codebuild/local cache/custom//go/pkg/mod/go/pkg/mod时出错:没有这样的文件或目录 即使我运行了go mod download(
/go/pkg
文件夹。因此,当我试图缓存/go/pkg
时,它会抛出一个错误
装载/go/pkg/mod:symlink/codebuild/local cache/custom//go/pkg/mod/go/pkg/mod时出错:没有这样的文件或目录
即使我运行了go mod download
(这将创建/go/pkg/mod
,它也不会缓存文件夹,因为codebuild无法更早地装载它)
这是我的codebuild.yml
version: 0.2
phases:
install:
runtime-versions:
golang: 1.12
nodejs: 10
commands:
- npm install
build:
commands:
- go build -ldflags="-s -w" -o api/bin/main api/main.go
cache:
paths:
- /go/src/**/*
- /go/pkg/mod/**/*
正在尝试缓存。/vendor
我还尝试缓存./vendor文件夹,它不会在代码构建中抛出任何错误。但是,我认为它不会缓存任何东西,因为构建时间不会减少。它还说它忽略了符号链接
警告:忽略符号链接/codebuild/output/src074479210/src/github.com/kkesley/myrepo/vendor
go:查找github.com/aws/aws-lambda-go v1.11.1
转到:查找github.com/stretchr/authentic v1.2.1
go:查找github.com/pmezard/go-difflib v1.0.0
go:查找github.com/daveggh/go-spew v1.1.0
转到:查找gopkg.in/urfave/cli.v1.20.0
go:下载github.com/aws/aws-lambda-go v1.11.1
go:提取github.com/aws/aws-lambda-go v1.11.1
这是我的codebuild.yml
版本:
version: 0.2
phases:
install:
runtime-versions:
golang: 1.12
nodejs: 10
commands:
- npm install
- go mod vendor
build:
commands:
- go build -mod vendor -ldflags="-s -w" -o api/bin/main api/main.go
cache:
paths:
- /go/src/**/*
- vendor/**/*
问题:
如何在不使用自定义docker映像的情况下在代码构建中缓存go模块?有可能吗?使用默认的代码构建Ubuntu构建映像(我使用的是v4)
/go/pkg/**.*
go mod download
构建之前包含一个步骤在此之前,缓存似乎不起作用,因此这似乎是一个关键步骤。version: 0.2
phases:
install:
runtime-versions:
golang: latest
commands:
- "git config --global credential.helper '!aws codecommit credential-helper $@'"
- "git config --global credential.UseHttpPath true"
build:
commands:
- 'go mod edit -dropreplace git-codecommit.ap-southeast-2.amazonaws.com/v1/repos/xyz'
- 'go mod download'
# Use latest from develop for the build (test env only)
- 'go get git-codecommit.ap-southeast-2.amazonaws.com/v1/repos/xyz@develop'
- 'rm -rf "dist"'
- 'cp -r "eb-template" "dist"'
- 'env GOOS=linux GOARCH=amd64 go build -o "dist/bin/server"'
- 'go mod edit -replace git-codecommit.ap-southeast-2.amazonaws.com/v1/repos/xyz=../xyz'
- 'echo -n ${CODEBUILD_RESOLVED_SOURCE_VERSION} > dist/commithash'
artifacts:
base-directory: dist
files:
- '**/*'
cache:
paths:
- '/go/pkg/**/*'
你弄明白了吗?我也在试着做同样的事…@JoelDuckworth抱歉,我最后没弄明白。
version: 0.2
phases:
install:
runtime-versions:
golang: latest
commands:
- "git config --global credential.helper '!aws codecommit credential-helper $@'"
- "git config --global credential.UseHttpPath true"
build:
commands:
- 'go mod edit -dropreplace git-codecommit.ap-southeast-2.amazonaws.com/v1/repos/xyz'
- 'go mod download'
# Use latest from develop for the build (test env only)
- 'go get git-codecommit.ap-southeast-2.amazonaws.com/v1/repos/xyz@develop'
- 'rm -rf "dist"'
- 'cp -r "eb-template" "dist"'
- 'env GOOS=linux GOARCH=amd64 go build -o "dist/bin/server"'
- 'go mod edit -replace git-codecommit.ap-southeast-2.amazonaws.com/v1/repos/xyz=../xyz'
- 'echo -n ${CODEBUILD_RESOLVED_SOURCE_VERSION} > dist/commithash'
artifacts:
base-directory: dist
files:
- '**/*'
cache:
paths:
- '/go/pkg/**/*'