俺のアウトプット

調べたこと、試したことを書きます

Bitbucket上のリポジトリをAWS CodeCommit上へ移行する

普段、趣味で書くコードはBitbucketを利用しています。
5ユーザーまでの制限はあるけれど、プライベートリポジトリを無料で利用できるのは嬉しいですね。

bitbucket.org

AWS CodeCommit にも無料枠があります。 これは期間限定ではなく常に無料です。

  • 無制限のリポジトリ
  • 5人のアクティブユーザー/ 月
  • 50 GB のストレージ/月
  • 10,000 回の Git リクエスト/月

個人で利用するには十分ではないでしょうか。

今回はこのBitbucket上のリポジトリをAWS CodeCommit上に移行します。

https://docs.aws.amazon.com/ja_jp/codecommit/latest/userguide/images/codecommit-migrate-existing.png

  1. AWS CodeCommitリポジトリを作成
  2. Bitbucketリポジトリをクローン
  3. AWS CodeCommitリポジトリにプッシュ

AWS CodeCommitの準備は、前回のエントリを参考にしてください。

1. AWS CodeCommitリポジトリを作成

まずはリポジトリを作成します。

マネジメントコンソールの場合

  • サービス [開発者用ツール] - [CodeCommit] を選択
  • リポジトリを作成するリージョンを選択(CodeCommitはリージョン単位のサービスです)
  • [リポジトリの作成]ボタンをクリック(はじめての場合は[今すぐ始める]ボタンをクリック)

f:id:kitsugi:20180905073301p:plain

[リポジトリの作成]ボタンをクリックします。

f:id:kitsugi:20180907055400p:plain

[スキップ]ボタンをクリックします。([設定] - [通知] からいつでも設定できます)

AWS-CLI の場合

作成

$ aws codecommit create-repository --repository-name MyRepository --repository-description "私のリポジトリ"
{
    "repositoryMetadata": {
        "cloneUrlSsh": "ssh://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/MyRepository",
        "repositoryId": "a95590a1-9d4f-4e09-b562-1234567890ab",
        "repositoryDescription": "私のリポジトリ",
        "lastModifiedDate": 1536095543.38,
        "repositoryName": "MyRepository",
        "accountId": "123456789012",
        "cloneUrlHttp": "https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/MyRepository",
        "creationDate": 1536095543.38,
        "Arn": "arn:aws:codecommit:ap-northeast-1:123456789012:MyRepository"
    }
}

削除(参考)

$ aws codecommit delete-repository --repository-name MyRepository
{
    "repositoryId": "a95590a1-9d4f-4e09-b562-1234567890ab"
}

2. Bitbucketリポジトリをクローン

gitコマンドを利用して、Bitbucketリポジトリをローカル上にクローンします。

SSHの場合

$ git clone --mirror git@bitbucket.org:<account_name>/<repo_name>.git <ローカルリポジトリ名>

HTTPSの場合

git clone --mirror https://<username>@bitbucket.org/<account_name>/<repo_name>.git <ローカルリポジトリ名>

3. AWS CodeCommitリポジトリにプッシュ

クローンを作成したディレクトリに移動してgitコマンドでプッシュします。

$ cd <ローカルリポジトリ名>
$ git push ssh://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/<AWS CodeCommitリポジトリ名> --all

上の例では、東京リージョンap-northeast-1になっています。
各リージョンのエンドポイントURLは、AWS CodeCommit のリージョンと Git 接続エンドポイントを参照してください。

Counting objects: 354, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (146/146), done.
Writing objects: 100% (354/354), 306.89 KiB | 38.36 MiB/s, done.
Total 354 (delta 203), reused 354 (delta 203)
To ssh://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/OrenoRepository
 * [new branch]      develop -> develop
 * [new branch]      master -> master

Compressing objects: 100% (完了件数/全体件数), done.

と表示されていれば移行完了です。

AWS CodeCommit UIの確認

AWS CodeCommit ダッシュボードから作成したリポジトリを選択します。

f:id:kitsugi:20180907064628p:plain

シンプル過ぎて逆に清々しさを感じるUI。
そこにはかわいいタコ猫キモい狸はいませんでした。

f:id:kitsugi:20180905075455p:plain

f:id:kitsugi:20180907065226p:plain

参考