git - 致命的 : could not read Username for 'https://gitlab.com' : terminal prompts disabled

标签 git docker go package gitlab

我正在尝试为使用来自不同私有(private) gitlab 存储库的不同 go 包的 go 应用程序构建 docker 镜像。当我在本地机器上执行此操作时,我必须添加以下命令才能使其正常工作;

git config --global url.git@gitlab.com:.insteadOf https://gitlab.com/
export GOPRIVATE=*gitlab*

在这种情况下,将使用我的 ssh key 并且它工作正常。

现在,我想在构建 Docker 镜像时做同样的事情,但不使用 ssh key ,所以我考虑使用部署 token (该 token 可以访问 gitlab 组中的所有存储库)。

docker 文件:

FROM golang:1.14 AS builder

...

ARG USER
ARG KEY

RUN git config --global url."https://${USER}:${KEY}@gitlab.com/".insteadOf "https://gitlab.com/"
RUN export GOPRIVATE=*gitlab*

显然,这没有用,我变成了以下错误:

Fatal: could not read Username for 'https://gitlab.com': terminal prompts disabled

关于我如何使用部署 token 使其工作,您能否分享您的想法?

最佳答案

作为解决方法,我手动克隆 repo,然后编辑 go mod 文件

RUN git clone https://${USER}:${KEY}@gitlab.com/mygroup/myproject
RUN go mod init gitlab.com/mygroup/go-dns
RUN go mod edit -replace=gitlab.com/mygroup/myproject=./myproject

关于git - 致命的 : could not read Username for 'https://gitlab.com' : terminal prompts disabled,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61308739/

相关文章:

android - repo 同步结果在 "fatal: Not a git repository: ' working_dir/.repo/projects/external/ipsec-tools.git'"

git - 如果 diff'ing 不在存储库中,则没有选项可以忽略文件模式吗?

c# - Visual Studio + Docker - 使用“编辑并继续”调试应用程序?

go - time.Timer 的行为

unit-testing - 如何定义模拟方法被调用零次

git - Jenkins 多分支(管道)/分支跟踪

python - 向服务器上的 git 存储库添加一层身份验证

reactjs - 如何使用Dockerfile.dev和Yarn构建React应用

docker - 更新 docker 上的根证书

非 RFC 3339 格式的 json 解码时间