投稿日
隔離環境へのコード連携方法
もくじ
はじめに
全体像
作業端末
GitLab
CodeCommit
隔離環境端末
構築方法
- dev
- VPC (VPC、サブネット、インターネットゲートウェイ、NATゲートウェイを作成します。)
- GitLab (セルフホストのGitLabを作成します。)
- prd
- CodeCommit (リポジトリ、IAMユーザー(push用/pull用)を作成します。)
説明や注意事項は各モジュール配下のREDME.mdを確認してください。各モジュールのversions.tfは以下のように設定しています。自身の環境に合わせてタグ等は修正してください。
provider "aws" {
region = "ap-northeast-1"
default_tags {
tags = {
pj = "mirror"
env = "dev"
owner = "mori"
}
}
}
1. terraform実行
2. CodeCommitユーザーの認証情報
3. GitLabのリポジトリでミラー設定
-
セルフホストGitLabのパブリックDNS名を使って作業端末からブラウザでアクセスします。アクセスはhttpを使用します。
-
ログイン画面でusernameはroot、passwordはEC2インスタンスのインスタンスIDを入力してログインします。
- New Projectからミラー対象のプロジェクト(リポジトリ)を作成します。作成するプロジェクト名は本番環境に作成したCodeCommitのリポジトリ名と同じ名前にします。例としてtest-repoという名前のプロジェクト(リポジトリ)作成します。
- ミラー対象リポジトリでSettings->Repository->Mirroring repositoriesを開きます。
-
Git repository URLの入力ボックスにてCodeCommitのクローン用URL入力します。入力は以下のように@の前は作成したCodeCommitモジュールで作成したpush用ユーザーのGit認証用のユーザー名を使います。
https://mirror-prd-codecommit_access_user-at-456247553902@git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/test-repo
- Mirror directionはPush、Authentication methodはPasswordのままにします。
- Passwordはpush用ユーザーのGit認証用のパスワードを使います。
- Mirror repositoryで設定を反映します。
- 追加するとMirrored repositoriesに追加されます。右はしのリロードマークを押すとミラーリングを手動で実行できます。Last update attemptとLast successful updateが両方ともjust nowになれば問題なくミラー出来ています。
- 上記をリポジトリ毎に実施します。
4. 隔離端末からCodeCommitをクローン
5. 動作確認
- 作業端末に開発環境のGitLabからリポジトリをクローンします。認証情報はGitLabのユーザー(特に作成してなければroot)を使用します。
$ git clone http://ec2-3-109-224-199.ap-northeast-1.compute.amazonaws.com/gitlab-instance-ece16e7e/test-repo.git Cloning into 'test-repo'... Username for 'http://ec2-3-109-224-199.ap-northeast-1.compute.amazonaws.com': root Password for 'http://root@ec2-3-109-224-199.ap-northeast-1.compute.amazonaws.com': <instance id>
- 修正を加えてpushします。
$ cd test-repo $ echo "mirror test" > mirror-test $ git add . $ git commit -m "mirror test" $ git push
- 隔離端末から本番環境のCodeCommitをpullし、変更が反映されていることを確認します。
$ cd test-repo $ git pull $ ll total 24 -rw-r--r-- 1 moriryota staff 6308 8 31 16:44 README.md -rw-r--r-- 1 moriryota staff 12 8 31 16:57 mirror-test
-
隔離端末からpushしようとしてもできません。
$ echo "push test" > push-test $ git add . $ git commit -m "push test" $ git push fatal: unable to access 'https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/test-repo/': The requested URL returned error: 403
(参考) フォワードプロキシの使用
1. フォワードプロキシ作成
2. GitLabにプロキシ設定
gitaly['env'] = {
"http_proxy" => "http://k8s-kubesyst-squid-f7f22160e9-214904599b63299c.elb.ap-northeast-1.amazonaws.com:3128",
"https_proxy" => "http://k8s-kubesyst-squid-f7f22160e9-214904599b63299c.elb.ap-northeast-1.amazonaws.com:3128"
}
gitlab-ctl stop
gitlab-ctl reconfigure
gitlab-ctl start
参考記事
本ドキュメントは以下の文書を基に作成しました。
Setting custom environment variables https://docs.gitlab.com/omnibus/settings/environment-variables.html