gitlab远程镜像仓库

gitlab remote mirror repository

我已经设置了两个 gitlab 服务器,一个主服务器和一个镜像我所有项目存储库的服务器。 我正在寻找命令行 tool/method 来配置每个项目的 "Remote mirror repository" 设置,这可能吗?如何实现?

感谢大家的支持。

存储库镜像

某些版本的 Gitlab 支持存储库镜像。 您可以通过存储库的设置或在导入存储库时启用它。
Settings > Pull from a remote repository > Mirror repository

这是文档:https://docs.gitlab.com/ee/workflow/repository_mirroring.html


GitlabCI

如果这对您不可用,您可以设置 Gitlab CI 来完成它。
在存储库的根目录中创建一个 gitlab-ci.yml 文件,它可能看起来像这样:

mirror:
  script: 
  - git clone http://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.mycompany.home/developers/master_project.git &> /dev/null
  - git config --global user.name "${GITLAB_USER_NAME}"
  - git config --global user.email "${GITLAB_USER_EMAIL}"
  - git add --all
  - git commit -m "Push to mirrored repo"
  - git push http://${YOUR_USERNAME}:${PERSONAL_ACCESS_TOKEN}@gitlab.mycompany.home/developers/mirrored_project.git HEAD:master

您可以在 Settings > CI / CD > Variables

中设置变量

我没有测试过这个,只是为了引导你朝着一个可能的方向前进。

以下是 CI 的文档:https://docs.gitlab.com/ee/ci/yaml/README.html#jobs

我手动配置了所有内容。

从 GitLab 12.9(2020 年 3 月)开始,您可以使用 GitLab API 配置“远程镜像”;见 https://docs.gitlab.com/ee/api/remote_mirrors.html#create-a-remote-mirror

curl --request POST --data "url=https://username:token@example.com/gitlab/example.git" --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/42/remote_mirrors"