2017-10-25 03:35
浏览 100

docker go-wrapper脚本如何工作

hey can anyone explain to me what docker go-wrapper should do ? https://github.com/docker-library/golang/blob/master/go-wrapper following this comment:

This script allows us to take a generic directory of Go source files such as "/go/src/app" and determine that the canonical "import path" of where that code expects to live and reference itself is "github.com/jsmith/my-cool-app". It will then ensure that "/go/src/github.com/jsmith/my-cool-app" is a symlink to "/go/src/app", which allows us to build and run it under the proper package name.

I understand that if I am developing a project under mine github go path then mounting it /go/src/app inside a docker container will work with imports still remained unchanged (github imports) correct ?

COPY . /go/src/app
WORKDIR /go/src/app

RUN go-wrapper download
RUN go-wrapper install

however when i try to install/run with vendors using dep

go get -u github.com/golang/dep/cmd/dep
dep init
dep ensure -update

it downloads my repo to vendor and then tries to import it from there why is that ?

图片转代码服务由CSDN问答提供 功能建议

嘿,谁能向我解释docker go-wrapper 应该做什么? < a href =“ https://github.com/docker-library/golang/blob/master/go-wrapper” rel =“ nofollow noreferrer”> https://github.com/docker-library/golang/blob/master / go-wrapper 跟随此注释:

此脚本允许我们获取Go源文件的通用目录 ,例如“ / go / src / app”,并确定该代码希望驻留并引用自身的规范“导入路径” 是“ github.com/jsmith/my-cool-app”。 然后,它将确保 “ /go/src/github.com/jsmith/my-cool-app”是指向“ / go / src / app”的符号链接, 允许我们在 正确的程序包名称。

我了解,如果我要在我的github下开发项目,请转到path,然后将其安装 / go / src / app 可以在docker容器中使用导入,而导入仍保持不变(github导入),对吗?

  COPY。  / go / src / app 
WORKDIR / go / src / app 
RUN go-wrapper下载
RUN go-wrapper安装

但是当我尝试 使用dep

  go与供应商安装/运行go get -u github.com/golang/dep/cmd/dep
dep init 


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duankui3838
    duankui3838 2018-02-03 04:08

    I'm not familiar with dep so I cannot comment on that part of your problem. However, the text you quoted relates to the canonical import path and you did not say you are using a canonical import path. You MUST use a canonical import path to get go-wrapper to behave like described in the quote.

    Once your package has a canonical import path (like package main // import "github.com/user/projname") then go-wrapper will recognize that special comment and create a symlink from go/src/github.com/user/projname to /go/src/app inside the docker container. This symlink will prevent go-wrapper download from downloading sub-packages like github.com/user/projname/subpackage from the remote (github.com).

    This behavior is especially useful for me when I am developing locally because I want to test my local changes to sub-packages before I commit them to the remote. If go-wrapper did not symlink for me, then it would go to the remote and download each of the sub-packages, which means I would be getting the older version instead of my locally edited sub-packages.

    点赞 评论