构建 Go 文件时,出现私有存储库 Dockerfile/go.mod 的错误提示
来源:stackoverflow
时间:2024-02-15 09:36:25 417浏览 收藏
从现在开始,我们要努力学习啦!今天我给大家带来《构建 Go 文件时,出现私有存储库 Dockerfile/go.mod 的错误提示》,感兴趣的朋友请继续看下去吧!下文中的内容我们主要会涉及到等等知识点,如果在阅读本文过程中有遇到不清楚的地方,欢迎留言呀!我们一起讨论,一起学习!
尝试使用 dockerfile 构建映像,但看到以下错误:
[6/7] 运行 go mod 下载 && go mod 验证:
#10 4.073 go: github.com/private-repo/[email protected]: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /app/pkg/mod/cache/vcs/40ae0075df7a81e12f09aaa30354204db332938b8767b01daf7fd56ca3ad7956: exit status 128: #10 4.073 [email protected]: permission denied (publickey). #10 4.073 fatal: could not read from remote repository. #10 4.073 please make sure you have the correct access rights #10 4.073 and the repository exists. ------ executor failed running [/bin/sh -c go mod download && go mod verify]: exit code: 1
这是我的 dockerfile:
#start from base image 1.16.5: from golang:1.16.5 arg ssh_private_key env elastic_hosts=localhost:9200 env log_level=info #configure the repo url so we can configure our work directory: env repo_url=github.com/private-repo/repo-name #setup out $gopath env gopath=/app env app_path=$gopath/src/$repo_url #/app/src/github.com/private-repo/repo-name/src #copy the entire source code from the current directory to $workpath env workpath=$app_path/src copy src $workpath workdir $workpath run mkdir -p ~/.ssh && umask 0077 && echo "${ssh_private_key}" > ~/.ssh/id_rsa \ && git config --global url."ssh://[email protected]/private-repo".insteadof https://github.com \ && ssh-keyscan github.com >> ~/.ssh/known_hosts #prevent the reinstallation of vendors at every change in the source code copy go.mod go.sum $workdir run go mod download && go mod verify run go build -x -o image-name . #expose port 8081 to the world: expose 8081 cmd ["./image-name"]
在我的 go 环境中,我确实有 go111module=on & goprivate=github.com/private-repo/*
此外,我可以在我的终端上进行身份验证:
ssh -t [电子邮件受保护]
你好,私人仓库!您已成功通过身份验证,但 github 不提供 shell 访问权限。
“获取私有仓库名称”成功。
我通过 dockerfile 构建:
docker build --build-arg ssh_private_key -t image-name .
其中有命令:
run go build -x -o image-name .
我尝试过的:
GO111MODULE="on" GONOPROXY="github.com/user-id/*" GONOSUMDB="github.com/user-id/*" GOPRIVATE="github.com/user-id/*" GOPROXY="https://proxy.golang.org,direct" [url "ssh://[email protected]/"] insteadOf = https://github.com/
正确答案
基本上,github.com/user-name/
下有多个存储库,并且所有这些存储库都是我想使用的私有存储库。
我宁愿使用更具体的指令:
git config --global \ url."ssh://[email protected]/user-name/*".insteadOf https://github.com/user-name/*
这样一来,代替将不会应用于所有 https://github.com
url,仅适用于与您需要使用 ssh 的私有存储库匹配的 url。
OP ios-mxe 在 the comments 中确认它确实按预期工作。
以上就是《构建 Go 文件时,出现私有存储库 Dockerfile/go.mod 的错误提示》的详细内容,更多关于的资料请关注golang学习网公众号!
-
502 收藏
-
502 收藏
-
501 收藏
-
501 收藏
-
501 收藏
-
139 收藏
-
204 收藏
-
325 收藏
-
477 收藏
-
486 收藏
-
439 收藏
-
357 收藏
-
352 收藏
-
101 收藏
-
440 收藏
-
212 收藏
-
143 收藏
-
- 前端进阶之JavaScript设计模式
- 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
- 立即学习 542次学习
-
- GO语言核心编程课程
- 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
- 立即学习 508次学习
-
- 简单聊聊mysql8与网络通信
- 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
- 立即学习 497次学习
-
- JavaScript正则表达式基础与实战
- 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
- 立即学习 487次学习
-
- 从零制作响应式网站—Grid布局
- 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
- 立即学习 484次学习