Skip to content

Instantly share code, notes, and snippets.

@waday
Last active January 15, 2017 02:39
Show Gist options
  • Select an option

  • Save waday/3964d31ef9b366fa0976845743fc4454 to your computer and use it in GitHub Desktop.

Select an option

Save waday/3964d31ef9b366fa0976845743fc4454 to your computer and use it in GitHub Desktop.

Revisions

  1. waday revised this gist Jan 15, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -32,9 +32,9 @@ git config --global credential.UseHttpPath true
    git config --global http.proxy http://認証ID:認証PW@プロキシサーバのURL:ポート番号
    git config --global https.proxy http://認証ID:認証PW@プロキシサーバのURL:ポート番号

    # jqコマンドインストール
    ## jqコマンドインストール
    sudo curl -o /usr/bin/jq http://stedolan.github.io/jq/download/linux64/jq && sudo chmod +x /usr/bin/jq

    # sync_codecommit.shを任意の場所に配置して定期実行設定
    ## sync_codecommit.shを任意の場所に配置して定期実行設定
    chmod 755 /path/to/sync_codecommit.sh
    crontab -e
  2. waday revised this gist Jan 8, 2017. 1 changed file with 0 additions and 4 deletions.
    4 changes: 0 additions & 4 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -35,10 +35,6 @@ git config --global https.proxy http://認証ID:認証PW@プロキシサーバ
    # jqコマンドインストール
    sudo curl -o /usr/bin/jq http://stedolan.github.io/jq/download/linux64/jq && sudo chmod +x /usr/bin/jq

    # プロキシ設定
    git config --global http.proxy http://proxy.example.com:8080
    git config --global https.proxy http://proxy.example.com:8080

    # sync_codecommit.shを任意の場所に配置して定期実行設定
    chmod 755 /path/to/sync_codecommit.sh
    crontab -e
  3. waday revised this gist Jan 8, 2017. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -23,6 +23,15 @@ aws_access_key_id = AKI〜
    aws_secret_access_key = 〜
    ```

    # gitの設定
    ## HTTPSでPUSHする場合
    git config --global credential.helper '!aws --profile CodeCommitProfile codecommit credential-helper $@'
    git config --global credential.UseHttpPath true

    ## Proxy配下からPUSHする場合
    git config --global http.proxy http://認証ID:認証PW@プロキシサーバのURL:ポート番号
    git config --global https.proxy http://認証ID:認証PW@プロキシサーバのURL:ポート番号

    # jqコマンドインストール
    sudo curl -o /usr/bin/jq http://stedolan.github.io/jq/download/linux64/jq && sudo chmod +x /usr/bin/jq

  4. waday revised this gist Jan 8, 2017. No changes.
  5. waday renamed this gist Jan 8, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  6. waday revised this gist Jan 8, 2017. 2 changed files with 22 additions and 1 deletion.
    23 changes: 22 additions & 1 deletion README
    Original file line number Diff line number Diff line change
    @@ -3,12 +3,33 @@ yum install epel-release
    yum install python-pip
    pip install awscli

    cat ~/.aws/config
    ```
    [default]
    output = json
    region = ap-northeast-1
    [profile CodeCommitProfile]
    region = us-east-1
    output = json
    ```

    cat ~/.aws/credentials
    ```
    [default]
    aws_access_key_id = AKI〜
    aws_secret_access_key = 〜
    [CodeCommitProfile]
    aws_access_key_id = AKI〜
    aws_secret_access_key = 〜
    ```

    # jqコマンドインストール
    sudo curl -o /usr/bin/jq http://stedolan.github.io/jq/download/linux64/jq && sudo chmod +x /usr/bin/jq

    # プロキシ設定
    git config --global http.proxy http://proxy.example.com:8080
    git config --global https.proxy http://proxy.example.com:8080

    # create_repolinks_for_codecommit.sh配置して定期実行設定
    # sync_codecommit.shを任意の場所に配置して定期実行設定
    chmod 755 /path/to/sync_codecommit.sh
    crontab -e
    File renamed without changes.
  7. waday revised this gist Jan 8, 2017. 1 changed file with 43 additions and 0 deletions.
    43 changes: 43 additions & 0 deletions create_repolinks_for_codecommit.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    #!/bin/bash
    # pip install awscli
    # curl -o /usr/bin/jq http://stedolan.github.io/jq/download/linux64/jq && sudo chmod +x /usr/bin/jq
    HOST_INFO="This is mirror repository of `hostname`. Changes are automatically reflected."
    MIRROR_URL_BASE=https://git-codecommit.us-west-2.amazonaws.com/v1/repos
    AWSCLI_PROFILE_OPT='--profile CodeCommitProfile'
    gitlab_repo_dir_list=`find /srv/docker/gitlab/gitlab/repositories/ -mindepth 2 -maxdepth 2 -type d`
    aws_repo_arr=(`aws ${AWSCLI_PROFILE_OPT} codecommit list-repositories | jq -r '.repositories[].repositoryName'`)

    function print_log() {
    aws_reponame=$1
    msg=$2
    date_txt=`date '+%Y/%m/%d-%H:%M:%S'`
    echo "${date_txt} ${aws_reponame}: $msg"
    }

    function search_repo_from_aws() {
    IFS_BAK=$IFS
    IFS=$'\n'
    echo "${aws_repo_arr[*]}" | grep -q $1
    rc=$?
    IFS=$IFS_BAK
    echo $rc
    }

    for glrepopath in $gitlab_repo_dir_list; do
    user_repo_arr=(`echo $glrepopath | awk -F'repositories/' '{print $2}' | awk -F'/' '{print $1" "$2}'`)
    user=${user_repo_arr[0]}
    repo=`echo ${user_repo_arr[1]} | cut -d'.' -f1`
    aws_reponame=${user}_${repo}

    if [ "$(search_repo_from_aws $aws_reponame)" != "0" ]; then
    print_log "${aws_reponame}" "AWSにリポジトリがありません"
    print_log "${aws_reponame}" "リポジトリを作成します"
    aws ${AWSCLI_PROFILE_OPT} codecommit create-repository --repository-name "${aws_reponame}" --repository-description "${HOST_INFO}"
    print_log "${aws_reponame}" "RC=$?"
    fi

    cd $glrepopath
    print_log "${aws_reponame}" "AWSにpushします"
    git push --mirror ${MIRROR_URL_BASE}/${aws_reponame}
    print_log "${aws_reponame}" "RC=$?"
    done
  8. waday created this gist Jan 8, 2017.
    14 changes: 14 additions & 0 deletions README
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    # awscliインストール
    yum install epel-release
    yum install python-pip
    pip install awscli

    # jqコマンドインストール
    sudo curl -o /usr/bin/jq http://stedolan.github.io/jq/download/linux64/jq && sudo chmod +x /usr/bin/jq

    # プロキシ設定
    git config --global http.proxy http://proxy.example.com:8080
    git config --global https.proxy http://proxy.example.com:8080

    # create_repolinks_for_codecommit.sh配置して定期実行設定
    crontab -e