jjzjj

docker - 为什么 "go build"对我的 Docker 项目失败?

coder 2024-07-06 原文

我有一个 npm 二进制文件,我想打包到 Docker 容器中。我有这样的配置:

# Docker image for the Mongo Stitch command

FROM golang:alpine

# Do a system update
RUN apk update

RUN apk add git

# Declare base dir
WORKDIR /root

# The console binary for Mongo Stitch
RUN git clone https://github.com/10gen/stitch-cli.git

WORKDIR /root/stitch-cli

RUN go build

CMD ["/bin/sh"]

我收到这个错误:

main.go:8:2: cannot find package "github.com/10gen/stitch-cli/commands" in any of:
    /usr/local/go/src/github.com/10gen/stitch-cli/commands (from $GOROOT)
    /go/src/github.com/10gen/stitch-cli/commands (from $GOPATH)
main.go:9:2: cannot find package "github.com/10gen/stitch-cli/utils" in any of:
    /usr/local/go/src/github.com/10gen/stitch-cli/utils (from $GOROOT)
    /go/src/github.com/10gen/stitch-cli/utils (from $GOPATH)
main.go:11:2: cannot find package "github.com/mitchellh/cli" in any of:
    /usr/local/go/src/github.com/mitchellh/cli (from $GOROOT)
    /go/src/github.com/mitchellh/cli (from $GOPATH)

这是出乎意料的,因为我想官方 Go 容器应该有我需要的一切。我设置了这些变量:

~ # set | grep GO
GOLANG_VERSION='1.11.5'
GOPATH='/go'

build instructionsgo build 足以让它工作。我玩过 go get,有各种错误输出,但我认为这可能是徒劳的追逐,因为如果我必须手动获取依赖项,说明会这样说。

尽管如此,如果我确实在容器 shell 中发出 go get,我会得到:

~/stitch-cli # go get
go get: no install location for directory /root/stitch-cli outside GOPATH
    For more details see: 'go help gopath'

我已经尝试解析上述帮助文件中的 Material ,但我不确定哪一部分适用于我的案例。

所以,我想知道 missing GOROOT was worth fixing .我这样做了:

~/stitch-cli # which go
/usr/local/go/bin/go
~/stitch-cli # GOROOT=/usr/local/go
~/stitch-cli # export GOROOT
~/stitch-cli # go build
# _/root/stitch-cli
./main.go:25:3: cannot use commands.NewWhoamiCommandFactory(ui) (type "github.com/10gen/stitch-cli/vendor/github.com/mitchellh/cli".CommandFactory) as type "github.com/mitchellh/cli".CommandFactory in map value
./main.go:26:3: cannot use commands.NewLoginCommandFactory(ui) (type "github.com/10gen/stitch-cli/vendor/github.com/mitchellh/cli".CommandFactory) as type "github.com/mitchellh/cli".CommandFactory in map value
./main.go:27:3: cannot use commands.NewLogoutCommandFactory(ui) (type "github.com/10gen/stitch-cli/vendor/github.com/mitchellh/cli".CommandFactory) as type "github.com/mitchellh/cli".CommandFactory in map value
./main.go:28:3: cannot use commands.NewExportCommandFactory(ui) (type "github.com/10gen/stitch-cli/vendor/github.com/mitchellh/cli".CommandFactory) as type "github.com/mitchellh/cli".CommandFactory in map value
./main.go:29:3: cannot use commands.NewImportCommandFactory(ui) (type "github.com/10gen/stitch-cli/vendor/github.com/mitchellh/cli".CommandFactory) as type "github.com/mitchellh/cli".CommandFactory in map value
~/stitch-cli # 

好吧,也许这有点远,但我现在坚定地处于“尝试随机事物”领域。有什么我可以做的让它开箱即用吗?

我也尝试过手动安装 Go 的普通 Alpine (v3.9),它甚至没有设置 GOPATH,但我遇到了同样的“找不到包”错误。接下来我可以尝试什么来编译它?

我也尝试过切换到 Golang 图像的全脂版本,而不是这个更轻的 Alpine 图像,我遇到了同样的问题,buildget.

我也可以回到通过 NPM 安装,但我遇到了问题(这个问题可能超出了 Golang 问题的范围)。

可能重复

我的问题已被确定为可能重复 of this question .我认为这个问题本质上是这里提到的次要问题的重复,正如我之前提到的,这可能是一个转移注意力的问题。如果有任何重复项详细说明第一个错误的答案,那可能是一个更好的路标。

最佳答案

Flimzy 友善地向我指出了另一个答案(如果没有知识渊博的帮助,我永远不会找到这个答案)。由于我认为构建过程非常重要,尤其是对于像我这样的非 Gophers,我将发布新的 Dockerfile:

# Docker image for the Mongo Stitch command

FROM golang:alpine

# Do a system update
RUN apk update

RUN apk add git curl

# Declare base dir
WORKDIR /root/src

RUN git clone https://github.com/10gen/stitch-cli.git

WORKDIR /root/src/stitch-cli

# Remove the old dependencies
RUN rm -rf vendor

# Fetch the dependencies
RUN curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
RUN GOPATH=$GOPATH:/root dep ensure

# Now it should build
RUN GOPATH=$GOPATH:/root go build

CMD ["/bin/sh"]

获取依赖项导致此错误:

Warning: the following project(s) have [[constraint]] stanzas in Gopkg.toml:

  ✗  github.com/10gen/escaper
  ✗  github.com/dgrijalva/jwt-go
  ✗  github.com/ogier/pflag
  ✗  gopkg.in/mgo.v2

However, these projects are not direct dependencies of the current project:
they are not imported in any .go files, nor are they in the 'required' list in
Gopkg.toml. Dep only applies [[constraint]] rules to direct dependencies, so
these rules will have no effect.

Either import/require packages from these projects so that they become direct
dependencies, or convert each [[constraint]] to an [[override]] to enforce rules
on these projects, if they happen to be transitive dependencies.

但是,它似乎仍然可以编译。我担心的是,我必须执行的步骤比文档中的要多得多,这让我认为我已经把它变得比需要的更复杂了。

docker repo

我已将我的 Docker 存储库永久化 available here .

关于docker - 为什么 "go build"对我的 Docker 项目失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54504906/

有关docker - 为什么 "go build"对我的 Docker 项目失败?的更多相关文章

  1. ruby - 为什么我可以在 Ruby 中使用 Object#send 访问私有(private)/ protected 方法? - 2

    类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc

  2. ruby-on-rails - rails : "missing partial" when calling 'render' in RSpec test - 2

    我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou

  3. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-

  4. ruby-on-rails - Rails - 子类化模型的设计模式是什么? - 2

    我有一个模型:classItem项目有一个属性“商店”基于存储的值,我希望Item对象对特定方法具有不同的行为。Rails中是否有针对此的通用设计模式?如果方法中没有大的if-else语句,这是如何干净利落地完成的? 最佳答案 通常通过Single-TableInheritance. 关于ruby-on-rails-Rails-子类化模型的设计模式是什么?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.co

  5. ruby - 如何在 buildr 项目中使用 Ruby 代码? - 2

    如何在buildr项目中使用Ruby?我在很多不同的项目中使用过Ruby、JRuby、Java和Clojure。我目前正在使用我的标准Ruby开发一个模拟应用程序,我想尝试使用Clojure后端(我确实喜欢功能代码)以及JRubygui和测试套件。我还可以看到在未来的不同项目中使用Scala作为后端。我想我要为我的项目尝试一下buildr(http://buildr.apache.org/),但我注意到buildr似乎没有设置为在项目中使用JRuby代码本身!这看起来有点傻,因为该工具旨在统一通用的JVM语言并且是在ruby中构建的。除了将输出的jar包含在一个独特的、仅限ruby​​

  6. ruby - 什么是填充的 Base64 编码字符串以及如何在 ruby​​ 中生成它们? - 2

    我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%

  7. ruby - 解析 RDFa、微数据等的最佳方式是什么,使用统一的模式/词汇(例如 schema.org)存储和显示信息 - 2

    我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i

  8. ruby - 为什么 4.1%2 使用 Ruby 返回 0.0999999999999996?但是 4.2%2==0.2 - 2

    为什么4.1%2返回0.0999999999999996?但是4.2%2==0.2。 最佳答案 参见此处:WhatEveryProgrammerShouldKnowAboutFloating-PointArithmetic实数是无限的。计算机使用的位数有限(今天是32位、64位)。因此计算机进行的浮点运算不能代表所有的实数。0.1是这些数字之一。请注意,这不是与Ruby相关的问题,而是与所有编程语言相关的问题,因为它来自计算机表示实数的方式。 关于ruby-为什么4.1%2使用Ruby返

  9. ruby - 检查 "command"的输出应该包含 NilClass 的意外崩溃 - 2

    为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar

  10. ruby - ruby 中的 TOPLEVEL_BINDING 是什么? - 2

    它不等于主线程的binding,这个toplevel作用域是什么?此作用域与主线程中的binding有何不同?>ruby-e'putsTOPLEVEL_BINDING===binding'false 最佳答案 事实是,TOPLEVEL_BINDING始终引用Binding的预定义全局实例,而Kernel#binding创建的新实例>Binding每次封装当前执行上下文。在顶层,它们都包含相同的绑定(bind),但它们不是同一个对象,您无法使用==或===测试它们的绑定(bind)相等性。putsTOPLEVEL_BINDINGput

随机推荐