问题,公司自建gitlab
有一个项目1,引用了项目2
项目1 go.mod有如下内容:
gitlab.westhpc.net/platform/aaaaaa
但是在编译机上,无法下载

解决办法:
1,先在项目gitlab网站上添加sshkey。然后再把这个key添加到部署机上。
2,配置git clone http下载模式,不使用代理
go env -w GO111MODULE=on && go env -w GOPROXY=https://goproxy.cn,direct
go env -w GOPRIVATE=gitlab.westhpc.net
3,将git clone 的http下载方式改为 ssh下载
git config --global url.ssh://git@gitlab.westhpc.net:端口号/.insteadOf http://gitlab.westhpc.net/
4,/etc/ssh/ssh_config 或 $HOME/.ssh/config 文件添加

Host *
    StrictHostKeyChecking no
mkdir ~/.ssh
chmod 600 ~/.ssh

cat >> ~/.ssh/id_rsa <<EOF
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn
NhAAAAAwEAAQAAAYEAnrg3p7DFEp8UNw4+UsqTm0lYES683bAz1gnyqi1GKtfem9flV9jh
-----END OPENSSH PRIVATE KEY-----
EOF


cat >> ~/.ssh/id_rsa.pub <<EOF
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCeuDensMUSnxQ3Dj5SypObSVgRLrzdsDPWCfKqLUYq196b1+VX2OH0Wc9NnMJOW+FNiQ1f0a2EX2gWd04cBvHGS1UvyOsc5h4+UtRBmtAMs+uB33xRcDMh2Jy0shf/
EOF

chmod 600 ~/.ssh/*
echo "    StrictHostKeyChecking no" >> /etc/ssh/ssh_config

go env -w GOPRIVATE=gitlab.westhpc.net
export GOPRIVATE=gitlab.westhpc.net
git config --global credential.helper store
git config --global url.ssh://git@gitlab.westhpc.net:端口号/.insteadOf http://gitlab.westhpc.net/

英雄之旅
8 声望1 粉丝