0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Gitlabのミラーリング機能を利用せずにGithubをミラーリング

Posted at

はじめに

Github上のOSSプロジェクトをベースに、とあるソフトウェアを開発する。
ソースコードの管理は、オンプレに構築するGitlab CEを利用する。

原則、Github上のOSSプロジェクトから、Gitlab側のソースのコピーは一回のみとするが、深刻な脆弱性が見つかった場合などは、その修正を取り込みたい。
しかし、Gitlab CEでは、プルミラーリングは利用できない。このため、Gitlabのミラーリング機能を使用せずに、Gitlab上でGithub上のリポジトリをミラーリングし、必要に応じて最新のソースコードをGitlab側の開発ブランチに取り込める手順を整理した。

■イメージ図
image.png

1. Gitlabで空のプロジェクトを作成

Gitlabにログインし、空のプロジェクトを作成する。

2. GitlabにGithubのリポジトリをミラーリング

github上のプロジェクトの情報をgitlabにすべてコピーする。
この時点でgitlab上のmainブランチでは、github上のプロジェクトのソースが参照可能となる。
またた、github上で行われたすべての変更履歴を確認することも可能。

Git clone --mirror https://github.com/oss_comunity/oss_project.git
cd oss_project.git
git push --mirror https://gitlab.on-premises.com/my-project.git

3. リモートリポジトリ登録

githubのプロジェクトをリモートリポジトリとして、githubという名前で登録する。
こうしておくことで、gitlabのプロジェクトのgitの作業ディレクトリから、githubのリポジトリが参照できるようになる。

cd ../
git clone https://gitlab.on-premises.com/my-project.git
cd my-project
# githubのプロジェクトをリモートリポジトリとしてついあk
git remote add github https://github.com/oss_comunity/oss_project.git

4. mirrorブランチを作成

リモートリポジトリ(github)のmainブランチをcheckoutし、それをgitlabにmirrorというブランチ名称で登録する。
このmirrorリポジトリは、github側のmainブランチを追跡するように設定しておくのがポイント

# GitHubから最新の変更を取得
git fetch github
# github側のmainブランチを追跡するmirrorブランチを作成
git checkout -b mirror github/main
# gitlab側にpush
git push -u origin mirror          

ここまでで基本的な設定は完了。

5. Githubの変更を定期的に取り込む

あとは以降の手順を必要に応じて実行することで、github上の最新の情報をオンプレのgitlabに反映することができる。

5.1 githubのmainブランチの最新情報をmirrorブランチに取り込み

githubのmainブランチから最新の情報を持ってきて、mirrorブランチにマージする。

# GitHubから最新の変更を取得
git fetch github 
# mirrorブランチに切り替え
git checkout mirror
git merge github/main --ff-only
# GitLabに変更をプッシュ
git push origin mirror

5.2 mirrorブランチをgitlab側のmasterブランチにマージ

最新のgithubの情報が反映されたmirrorブランチをgitlab側のmainにマージする

# mainブランチに切り替え
git checkout main
git merge mirror --no-ff
# GitLabに変更をプッシュ
git push origin main

- 以上 -

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?