【问题标题】:fatal: could not read Username for 'https://gitlab.com': terminal prompts disabled致命:无法读取“https://gitlab.com”的用户名:终端提示已禁用
【发布时间】:2020-08-02 03:29:37
【问题描述】:

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

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

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

现在,我想在构建 Docker 映像时做同样的事情,但不使用 ssh 密钥,所以我想使用部署令牌(该令牌可以访问 gitlab 组中的所有存储库)。

码头文件:

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

您能否分享您对如何使用部署令牌使其工作的想法?

【问题讨论】:

  • 在构建期间是否将 ${USER}${KEY} 设置为构建参数?
  • 是的,我是这样构建的:docker build --build-arg USER=$GITLAB_DOCKER_USER --build-arg KEY=$GITLAB_DOCKER_KEY -t go-dns .
  • 设置了GIT_TERMINAL_PROMPT 吗?见stackoverflow.com/a/38237165/2087704
  • 是的,像这样RUN export GIT_TERMINAL_PROMPT=1
  • RUN git config credential.helperdocker build 上返回什么?

标签: git docker go package gitlab


【解决方案1】:

作为解决方法,我手动克隆 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

【讨论】:

    猜你喜欢
    • 2023-02-07
    • 1970-01-01
    • 2021-11-04
    • 2020-05-04
    • 2019-08-29
    • 2017-08-12
    • 2022-11-25
    • 2021-03-09
    • 2022-11-14
    相关资源
    最近更新 更多