gitlab镜像同步代码失败

本地使用docker部署了两个gitlab A和B(15.4版本);然后再gitlab A上面创建仓库,想把仓库push到gitabB上面,没有成功。尝试了用户密码认证和ssh认证都没有成功。

用户密码的错误提示:
13:get remote references: create git ls-remote: exit status 128, stderr: “fatal: unable to access ‘http://gitlab.xxxxxxxx.com/jenkins/test-mirror-internal.git/’: The requested URL returned error: 302\n”.

ssh的错误信息:
13:get remote references: create git ls-remote: exit status 128, stderr: " connect to host gitlab.xxxxxxx.com port 23: Connection timed out\r\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.\n".

你是在使用push mirror的功能是不行?

我看你报错里面有个302的返回,你需要注意push mirror的功能不能作用于有重定向的地址,你是不是做了http–》https的重定向,如果是这样你直接填https的地址应该就好了。

采用http+IP地址(域名),用户密码认证,是可以同步成功的;
ssh+IP和ssh+域名的方式,都是失败的,猜测可能是采用docker的方式安装的gitlab有关系。

你使用ssh时是使用的docker gitlab自己封装的ssh还是宿主机的ssh?

docker安装的是需要将docker中的ssh映射出来的哦,而且如果你映射之后的端口不是默认的22端口,还需要更改配置文件的gitlab_rails['gitlab_shell_ssh_port'] 参数为对应的端口。

配置文件修改过了,使用ssh同步镜像数据的时候报错:
13:get remote references: create git ls-remote: exit status 128, stderr: “Host key verification failed.\r\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.\n”

您好,ssh同步的话,需要在同步才做完成后将ssh的公钥作为被推送仓库的deploy key,然后再点击同步按钮才可以的

参考https://forum.gitlab.cn/t/topic/1347哈

确实可以了,多谢多谢。
有个新问题,我发现mirror过来的镜像,是把分支用户权限也同步了过来。 能否控制用户只在上游仓库可以直接push,但是在下游的镜像不允许push呢。

下游应该不能push吧,如果下游push了,那上游给下游做mirror的话,就代码conflict了哦。

我这边看到的是,在下游镜像push成功;然后上游有更新,会自动覆盖下游写入的代码提交。

对于push mirror这种场景,是不建议下游做代码更新的,因为会导致代码conflict。

我现在已经可以实现两个gitlab的repo之间自动同步。但是每次操作步骤比较繁琐,需要在gitlab B新建repo,取消分支保护,然后在gitlabA设置同步方式,然后第一次触发同步。 有没有啥脚本可以参考的,简单输入repo名称就实现两个repo自动同步的初始化配置,谢谢。

您可以通过 api来完成呢?
1、通过api创建项目
2、通过api取消分支保护
2、最后再通过api创建mirror