我正在尝试为使用来自不同私有(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/