I want to use dep (https://golang.github.io/dep) for one of our services. I am using the latest golang image from the official repository (aws/codebuild/golang:1.10). According to the Dockerfile this version is provided with dep out of the box.
In my buildspec I tried this:
While running my build, however, it fails with the following message:
bash: /go/bin/dep: Permission denied
Thanks for reporting this @rvdwijngaard! We're working on getting the dep permissions fixed in our internal release process. In the meantime, chmod +x /go/bin/dep in your buildspec should get your build going.
Thanks for your answer @clareliguori; I think it might be very useful to give an example of building a golang project with sub packages and dep with codebuild.
I am able to use dep with codebuild fine when properly define a SRC_DIR in buildspec.yaml and if the submitter is root meaning click start build directly in codebuild
env:
variables:
SRC_DIR: src/github.com/xxx/xxx
in the build logs there should be
CODEBUILD_SRC_DIR=/codebuild/output/src694249801/src/github.com/xxx/xxx
However, if I were to use codepipeline to be a submitter, it doesn't seem to create a directory defined in buildspec and this causes dep to fail
This error
root project import: dep does not currently support using GOPATH/src as the project root
Build logs
CODEBUILD_SRC_DIR=/codebuild/output/src127950602/src
would love to know how to solve this.
Fixed f524c815
@apisit I'm running into the same issue with dep - documented on https://github.com/golang/dep/issues/417
This is how I worked around it in my buildspec file:
phases:
pre_build:
commands:
- mkdir -p ../github.com/sapessi/xxxxxxx
- mv * ../github.com/sapessi/xxxxxxx
- mv ../github.com .
- cd github.com/sapessi/xxxxxxx && dep ensure
...
Another workaround for dep:
If you echo $GOPATH, we will get /go:/codebuild/output/src265478100. So if you simply copy all contents of vendor/ contents to /go, build succeeds for me. I'm running aws managed go 1.10.x machine image in codebuild config.
version: 0.2
env:
variables:
GOOS: "linux"
phases:
install:
commands:
- echo CODEBUILD_SRC_DIR - $CODEBUILD_SRC_DIR
- echo GOPATH - $GOPATH
- echo GOROOT - $GOROOT
- echo Moving packages
- cp -r ./vendor/* /go/src/
build:
commands:
- echo Build started on `date`
- echo Compiling the Go code...
- go build -o app main.go
post_build:
commands:
- echo Build completed on `date`
artifacts:
files:
- app
- appspec.yml
- buildspec.yml
- codedeploy/*
Catch here is - you have to commit vendor/ to git. Which is fine because many projects commit all the deps to the repo to have one solid working unit without relying on packages/repos disappearing from remotes.
Most helpful comment
I am able to use
depwith codebuild fine when properly define aSRC_DIRinbuildspec.yamland if the submitter isrootmeaning click start build directly in codebuildin the build logs there should be
However, if I were to use codepipeline to be a submitter, it doesn't seem to create a directory defined in buildspec and this causes
depto failThis error
Build logs
would love to know how to solve this.