gitlab高级功能之mirroring - push mirroring(一)

今天给大家介绍一个gitlab很高级也是非常有用的功能 - gitlab的mirroring,你可以将仓库镜像到外部或从外部镜像仓库过来,从而可以实现分支、标签和提交的自动同步。

文章目录

    • [1. mirroring的实现方式](#1. mirroring的实现方式)
    • [2. push mirroring](#2. push mirroring)
      • [2.1 简介](#2.1 简介)
      • [2.2 说明](#2.2 说明)
    • [3. 配置推送镜像](#3. 配置推送镜像)
      • [3.1 基于https的方式](#3.1 基于https的方式)
        • [step1: 选择被推送的仓库所在的项目](#step1: 选择被推送的仓库所在的项目)
        • [step2: 选择需要推送的仓库所在的项目:](#step2: 选择需要推送的仓库所在的项目:)
      • [3.2 基于ssh方式](#3.2 基于ssh方式)
        • [step1: 选择被推送的仓库所在的项目](#step1: 选择被推送的仓库所在的项目)
        • [step2: 选择需要推送的仓库所在的项目](#step2: 选择需要推送的仓库所在的项目)
        • [step3: 在上一步的基础上查看ssh公钥](#step3: 在上一步的基础上查看ssh公钥)
        • [step4: 选择被推送的仓库所在的项目](#step4: 选择被推送的仓库所在的项目)
        • [step5: 选择需要推送的仓库所在的项目](#step5: 选择需要推送的仓库所在的项目)
        • [step6: 查看](#step6: 查看)

1. mirroring的实现方式

有以下几种mirroring的方法:

  • 推送:将仓库从 GitLab 镜像到另一个位置。
  • 拉取:将仓库从其他位置镜像到 GitLab 实例(专业版以上)。
  • 双向镜像:彼此相互镜像,但可能会导致冲突。

2. push mirroring

  • Gitlab 13.5引入,基于https支持lfs(大文件存储)
  • 参考:push-mirroring

2.1 简介

  • 推送镜像是一个下游存储库,用于镜像对上游存储库所做的提交。

  • 推送镜像被动接收对上游存储库所做的提交的副本。

  • 为防止镜像与上游存储库分流,请勿将提交直接推送到下游镜像。改为将提交推送到上游存储库。

2.2 说明

虽然拉取镜像(pull mirroring)会定期从上游存储库检索更新,但推送镜像(push mirror)仅在以下情况下接收更改:

  • 提交被推送到上游 GitLab 存储库。
  • 管理员强制更新镜像。

当更改推送到上游存储库时,推送镜像会收到它:

  • 五分钟内。
  • 在一分钟内,如果启用了仅镜像保护的分支。

如果是不同的分支,"镜像存储库"部分中会显示错误。

3. 配置推送镜像

3.1 基于https的方式

step1: 选择被推送的仓库所在的项目

如果需要通过某个用户来完成镜像推送,需要在协议后加上被推送仓库的username@,如https://renliting@docker.bdeet.top/test/aaa.git,对应的密码就是renliting用户的密码。改用户的权限至少是maintainer权限。

step2: 选择需要推送的仓库所在的项目:

Main menu -> Projects -> Settings > Repository -> **Mirroring repositories **-> input Git repository URL -Mirror direction(Push)-Authentication method(Password)-`Mirror repository

看到这种现象就说明已经ok了,当然你也可以测试下

3.2 基于ssh方式

参考链接:https://docs.gitlab.com/ee/user/project/repository/mirror/#get-your-ssh-public-key

step1: 选择被推送的仓库所在的项目

ssh的方式是将被推送的仓库的clone地址复制过来,然后需要url地址中的:改为/。如将git@docker.bdeet.top:mirror/ccc.git改为git@docker.bdeet.top/mirror/ccc.git

step2: 选择需要推送的仓库所在的项目

Main menu -> Projects -> Settings > Repository -> **Mirroring repositories **-> input Git repository URL -Mirror direction(Push)-Authentication method(SSH)-Mirror repository

step3: 在上一步的基础上查看ssh公钥
step4: 选择被推送的仓库所在的项目

Main menu -> Projects -> Settings > Repository -> **Mirroring repositories **-> Deploy keys

step5: 选择需要推送的仓库所在的项目

点击同步

显示已经同步完成

step6: 查看


可以发现,推送后两边的提交次数一致,说明推送成功。

相关推荐
向往风的男子14 小时前
【devops】devops-gitlab之部署与日常使用
运维·gitlab·devops
soaring012114 小时前
Gitlab实现多项目触发式自动CICD
pipeline·gitlab·triggers·access tokens
cn_newer21 小时前
gitlab/极狐-离线包下载地址
gitlab·devops·极狐·离线包下载
Roc-xb2 天前
Centos7安装gitlab-ce(rpm安装方式)
centos·gitlab
爱吃香蕉的阿豪2 天前
828华为云征文|Flexus X实例Docker+Jenkins+gitee实现CI/CD自动化部署-解放你的双手~
ci/cd·docker·gitee·华为云·jenkins
慕羽★2 天前
Git常用指令整理【新手入门级】【by慕羽】
linux·git·ubuntu·gitlab·github·仓库·分布式协作
心之所想,行之将至3 天前
记录一下gitlab社区版的安装教程
linux·服务器·gitlab
极小狐3 天前
2024 年 GitLab Global DevSecOps 报告解读
gitlab·devsecops·devops·极狐gitlab·安全合规
极小狐3 天前
极狐GitLab DevSecOps 功能合集(七大安全功能)
安全·gitlab·devsecops·极狐gitlab·安全合规
iRayCheung3 天前
Gitlab pre-receive hooks适配java p3c-pmd和python pycodestyle
java·python·gitlab·pre-receive