我在本地使用 docker 测试雅典,尝试设置身份验证,以便雅典能够访问公司的私有模块。我按照此处的指南操作,该命令go get github.com/SomeCompany/someprivatemodule
成功将该库的最新版本拉到我的本地。但是有一点很奇怪。
- 那些配置文件(.gitconfig、.ssh/config 和 .ssh/id_rsa)没有使该命令起作用。相反,由我的 GitHub 令牌组成的 .netrc 文件使其工作。我尝试在不安装这些配置文件的情况下运行 docker 映像,并且该命令仍然有效;但是,如果我在本地删除了 ~/.netrc,该
go get
命令将失败。似乎 go get 仍然取决于本地配置而不是雅典。
- 该
go get
命令确实从 GitHub 拉取私有模块。但是,在ATHENS_DISK_STORAGE_ROOT下,我只能找到github.com/SomeCompany/someprivatemodule依赖的那些公共模块,而那些私有模块只能在GOPATH /pkg/mod 下找到。雅典不应该将私有模块下载到ATHENS_DISK_STORAGE_ROOT,这样一旦 GitHub/gitlab 关闭,用户仍然可以从雅典下载这些私有模块吗?
这是我的设置:
GOPROXY=127.0.0.1:3000, which is the exposed port of Athens. GOPRIVATE="github.com/SomeCompany"
GONOPROXY="github.com/SomeCompany"
GONOSUMDB="github.com/SomeCompany"
~/.netrc
machine github.com login some_personal_access_token
.gitconfig
[url "ssh://git@github.com/"]
insteadOf = https://github.com/
[url "ssh://git@gitlab.com/"]
insteadOf = https://gitlab.com/
.ssh/配置
Host github.com
Hostname github.com
StrictHostKeyChecking no
IdentityFile /root/.ssh/id_rsa
运行docker镜像的命令
docker run -d -v $ATHENS_STORAGE:/var/lib/athens -e ATHENS_DISK_STORAGE_ROOT=/var/lib/athens -e ATHENS_STORAGE_TYPE=disk -v $PWD/.gitconfig:/root/.gitconfig -v @PWD/.ssh:/root/.ssh --name athens-proxy --restart always -p 3000:3000 gomods/athens:v0.11.0
第一次编辑
通过将 GOPRIVATE 设置为空,GONOPROXY 和 GONOSUMDB 会自动取消设置。我尝试使用原始设置重新运行 docker,但出现 404 错误:
码头工人日志:
INFO[2:35PM]: Exporter not specified. Traces won't be exported
2021-05-29 14:35:11.957339 I | Starting application at port :3000
INFO[2:35PM]: exit status 1: go list -m: github.com/SomeCompany@latest: invalid github.com/ import path "github.com/SomeCompany"
http-method=GET http-path=/github.com/SomeCompany/@v/list kind=Not Found module= operation=download.ListHandler ops=[download.ListHandler pool.List protocol.List vcsLister.List] request-id=3660faa3-256f-43fb-9937-f29565e7afa9 version=
INFO[2:35PM]: incoming request http-method=GET http-path=/github.com/SomeCompany/@v/list http-status=404 request-id=3660faa3-256f-43fb-9937-f29565e7afa9
INFO[2:35PM]: exit status 1: go list -m: github.com@latest: unrecognized import path "github.com": parse https://github.com/?go-get=1: no go-import meta tags ()
http-method=GET http-path=/github.com/@v/list kind=Not Found module= operation=download.ListHandler ops=[download.ListHandler pool.List protocol.List vcsLister.List] request-id=4d6659d2-710d-445f-b07f-7407aa4f2e3e version=
INFO[2:35PM]: incoming request http-method=GET http-path=/github.com/@v/list http-status=404 request-id=4d6659d2-710d-445f-b07f-7407aa4f2e3e
INFO[2:35PM]: incoming request http-method=GET http-path=/github.com/SomeCompany/someprivatemodule/@v/list http-status=200 request-id=e8d95d77-81dc-46fe-9523-e35f6dc8201f
DEBUG[2:35PM]: saving github.com/SomeCompany/someprivatemodule@v1.0.5 to storage... http-method=GET http-path=/github.com/SomeCompany/someprivatemodule/@v/v1.0.5.info request-id=24964b9c-b0b2-450a-bd9a-9d59f60a5c52
INFO[2:35PM]: github.com/SomeCompany/someprivatemodule@v1.0.5/go.mod: verifying module: github.com/SomeCompany/someprivatemodule@v1.0.5/go.mod: reading https://sum.golang.org/lookup/github.com/SomeCompany/someprivatemodule@v1.0.5: 410 Gone
server response: not found: github.com/SomeCompany/someprivatermodule@v1.0.5: invalid version: unknown revision v1.0.5 http-method=GET http-path=/github.com/SomeCompany/someprivatemodule/@v/v1.0.5.info kind=Not Found module=github.com/SomeCompany/someprivatemodule operation=download.InfoHandler ops=[download.InfoHandler pool.Info protocol.Info protocol.processDownload stash.Pool stasher.Stash stasher.fetchModule goGetFetcher.Fetch module.downloadModule] request-id=24964b9c-b0b2-450a-bd9a-9d59f60a5c52 version=v1.0.5
INFO[2:35PM]: incoming request http-method=GET http-path=/github.com/SomeCompany/someprivatemodule/@v/v1.0.5.info http-status=404 request-id=24964b9c-b0b2-450a-bd9a-9d59f60a5c52
雅典似乎试图从 sum.golang.org 找到包。所以我尝试使用正确的凭据挂载 .netrc 文件并设置 ATHENS_NETRC_PATH。这仍然给我同样的错误。
另一个事实:使用 v0.11.0,我无法使用 go get 下载任何内容。但是,使用雅典 docker 映像的 v0.2.0 版本,我能够下载部分模块。docker 日志(v0.2.0)如下所示:
buffalo: Unless you set SESSION_SECRET env variable, your session storage is not protected!
time="2021-05-29T19:39:20Z" level=info msg="Exporter not specified. Traces won't be exported"
buffalo: Starting application at :3000
time="2021-05-29T19:39:26Z" level=error msg="exit status 1: go list -m github.com/SomeCompany: invalid github.com/ import path \"github.com/SomeCompany\"\n" http-method=GET http-path="/github.com/SomeCompany/@v/list/" http-url="/github.com/SomeCompany/@v/list/" kind="Internal Server Error" module= operation=download.ListHandler ops="[download.ListHandler pool.List protocol.List vcsLister.List]" version=
handler: GET /github.com/SomeCompany/@v/list/ [500]
time="2021-05-29T19:39:26Z" level=error msg="exit status 1: go list -m github.com: unrecognized import path \"github.com\" (parse https://github.com?go-get=1: no go-import meta tags ())\n" http-method=GET http-path=/github.com/@v/list/ http-url=/github.com/@v/list/ kind="Internal Server Error" module= operation=download.ListHandler ops="[download.ListHandler pool.List protocol.List vcsLister.List]" version=
handler: GET /github.com/@v/list/ [500]
handler: GET /github.com/SomeCompany/someprivatemodule/@v/list/ [200]
time="2021-05-29T19:39:26Z" level=error msg="exit status 1: go: finding github.com/SomeCompany/someprivatemodule/somefile latest\ngo list -m github.com/SomeCompany/someprivatemodule/somefile: no matching versions for query \"latest\"\n" http-method=GET http-path="/github.com/SomeCompany/someprivatemodule/somefile/@v/list/" http-url="/github.com/SomeCompany/someprivatemodule/somefile/@v/list/" kind="Internal Server Error" module= operation=download.ListHandler ops="[download.ListHandler pool.List protocol.List vcsLister.List]" version=
handler: GET /github.com/SomeCompany/someprivatemodule/ratelimit/@v/list/ [500]
handler: GET /github.com/SomeCompany/someprivatemodule/@v/v1.0.5.info [200]
handler: GET /github.com/SomeCompany/someprivatemodule/@v/v1.0.5.mod [200]
handler: GET /github.com/SomeCompany/someprivatemodule/@v/v1.0.5.zip [200]
显然这仍然行不通,因为它缺少模块的一部分。
编辑:通过添加 GONOSUM_PATTERNS 解决