LoginSignup
15
13

More than 5 years have passed since last update.

GitlabからGCP Cloud Source Repositories へ連携する

Last updated at Posted at 2019-01-06

はじめに

Gitlab から Cloud Source Repositories へソースコードを同期します。
同期したあとは、Cloud Source Repositories から Cloud Buildに連携して、デプロイ自動化を行ったりできます!

※ プロバイダが、GitHubかBitBucketであれば、GCP標準で外部リポジトリ接続のサービスが提供されています。

手順

【GCP側操作】 リポジトリ作成

  • コンソール > Cloud Source Repositories で 新しいリポジトリを作成します
  • ここでは、 新しいリポジトリを作成 を選択します。 (Gitlabは外部リポジトリ連携が標準で不可のため)

image.png

  • 以下を指定
    • リポジトリ名
    • プロジェクト: GCPのプロジェクトを指定

image.png

【GCP側操作】 Gitlabからのアクセスするための user/passを発行

  • リポジトリにコードを追加 ページで以下を選択
    • ローカル Git リポジトリからコードを push
    • 手動で生成した認証情報

image.png

  • Git 認証情報を生成して保存します。 をクリック
    • アカウント確認があるので、OKして進む
    • Google Cloud Developer からの権限承認がでるので、OKしてすすむ

image.png

  • コピー&ペーストできるコマンドを ターミナルで実行 (※ bashでやるのがよいです。私はzshだとうまく行かなかったので)
eval 'set +o history' 2>/dev/null || setopt HIST_IGNORE_SPACE 2>/dev/null
 touch ~/.gitcookies
 chmod 0600 ~/.gitcookies

 git config --global http.cookiefile ~/.gitcookies

 tr , \\t <<\__END__ >>~/.gitcookies
source.developers.google.com,FALSE,/,TRUE,****************************************************
__END__
eval 'set -o history' 2>/dev/null || unsetopt HIST_IGNORE_SPACE 2>/dev/null
  • ~/.gitcookies にパスワードが生成されています。 これを後ほど Gitlab側の操作で使用します
    • サンプル: (= で区切られています)
    • [user].gmail.com : user
    • [password] : password
$ cat .gitcookies 
source.developers.google.com    FALSE   /   TRUE    2147483647  o   [user].gmail.com=[password]

【Gitlab側操作】 同期設定を行う

  • Setting > Repository を選択
  • 以下を設定して、 Mirror repository をクリック

image.png

項目
Git repository URL https://[user].gmail.com@source.developers.google.com/p/[project]/r/[repositry] "@の前にuser (例はgmail)" URLは
Mirror direction Push Gitlab → GCP
Authentication method Password
Password [password]
  • くるくるマークをクリックして、Errorが発生せず、 Last update の時間が表示されれば、ソースは同期完了です!

image.png

15
13
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
15
13