【问题标题】:AWS CodeBuild golang build failsAWS CodeBuild golang 构建失败
【发布时间】:2018-12-29 02:07:58
【问题描述】:

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

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

编辑: 将go get ./... 添加到构建后,我的所有本地包都收到以下错误:# cd .; git clone https://github.com/aristotle/dbhelper /go/src/github.com/aristotle/dbhelper Cloning into '/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

【问题讨论】:

  • 看起来您缺少依赖项 gorilla/mux ... 有没有机会在构建之前运行 go get ./... 之类的东西?
  • 是的,我可以,但是当你有很多依赖项时,这不是有点乏味吗?它在我的本地机器上也能正常工作。
  • @user1990524 您的本地计算机很可能已经下载了您第一次添加它们时的所有这些依赖项。你试过silverfighter的建议吗?
  • 是的,但我得到了新的错误。
  • 现在我没有看到具体的错误。 go get 从 github 克隆源代码应该没问题。在一切都是本地的之后,它应该可以构建了。所以不要忘记之后执行go build 。而且您不想缓存包,以便管道在每次构建时下载它们。

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


【解决方案1】:

根据本文,您需要将其添加到您的buildspec.yml 文件的install 部分。

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

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

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

【讨论】:

  • 我阅读了这篇文章,这是我从中获得构建规范的地方。可悲的是,移动 go get ./... 安装没有帮助。
猜你喜欢
  • 2023-01-28
  • 2019-06-24
  • 2020-03-09
  • 1970-01-01
  • 1970-01-01
  • 2023-02-24
  • 1970-01-01
  • 2019-02-27
  • 2022-10-05
相关资源
最近更新 更多