amazon-web-services - AWS CodeBuild golang 构建失败

标签 amazon-web-services go aws-codepipeline aws-codecommit

当我运行以下命令时:- go build -o app 我收到以下错误(针对多个依赖项):main.go:21:2: cannot find package "github .com/gorilla/mux"在任何一个: /usr/local/go/src/github.com/gorilla/mux(来自 $GOROOT) /go/src/github.com/gorilla/mux(来自 $GOPATH) /codebuild/output/src324986171/src/github.com/gorilla/mux

表示代码构建失败。知道我该如何解决这个问题,或者一般来说问题出在哪里? 感谢您的帮助。

编辑: 将 go get ./... 添加到构建后,我的所有本地包都出现以下错误:# cd .; git 克隆 https://github.com/aristotle/dbhelper/go/src/github.com/aristotle/dbhelper 克隆到 '/go/src/github.com/aristotle/dbhelper'...

我的 buildspec.yml 看起来像这样:

version: 0.2

phases:
  install: 
    commands:
      - echo CODEBUILD_SRC_DIR - $CODEBUILD_SRC_DIR
      - echo GOPATH - $GOPATH
      - echo GOROOT - $GOROOT
  build:
    commands:
      - echo Build started on `date`
      - echo Getting packages
      - go get ./...
      - echo Compiling the Go code...
      - go build -o app main.go
  post_build:
    commands:
      - echo Build completed on `date`
artifacts:
  files:
    - app

最佳答案

根据这篇文章,您需要将它添加到 buildspec.yml 文件的 install 部分。

install: 
    commands:
      - go get github.com/gorilla/mux

也许它也可以包含 go get ./... 这将解决所有依赖关系...但是如果您没有太多依赖关系,最好明确列出它们。

这是文章来源:https://www.contributing.md/2017/06/30/golang-with-aws-codebuild/

关于amazon-web-services - AWS CodeBuild golang 构建失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52633357/

相关文章:

python - 外部函数 : who deallocates memory?

amazon-web-services - 如果我通过 CloudFormation 部署 CodePipeline,有什么方法可以阻止 AWS 自动启动 CodePipeline?

c# - AWS S3 GetObjectAsync 挂起/超时

amazon-web-services - Amazon SQS Multi-Tenancy 和 HIPAA 合规性

linux - 由于参数中有空格,Bash 脚本因未知选项而失败

python - 使用 Oracle 的 AWS Python Lambda - OID 生成失败

go - 关闭 channel 会退出多个go例程?

go - 在 golang 中将字节数组更改为结构

jenkins - AWS CodePipeline 阶段超时/中止?

amazon-web-services - CloudFormation CodePipeline 模板无权执行 AssumeRole,为什么?