LoginSignup
0
1

More than 5 years have passed since last update.

CircleCI v2 にするときに、デバッグで試したこと

Posted at

前提

originupstream の remote を持っています。

git push origin hoge して、その後 GitHub からプルリクをつくって、CircleCI が回ります。

そのときに、 Rebuid with SSH していろいろ動きをみていました。

スクリーンショット 2018-03-13 13.42.01.png

今回は、 staging サーバにデプロイするという設定です。

SSH Permissions

スクリーンショット 2018-03-13 13.46.06.png

これは、ローカル Mac で適当に鍵をつくって、 id_rsa_hoge.pub を staging サーバに登録して、 id_rsa_hoge を CircleCI に登録しました。

これで、CircleCi コンテナから、staging サーバへ ssh できるようになりました。

Checkout SSH keys

これ、ちょっと謎。勉強しないと。

結局よくわからなくて、staging から git clone できるようにするために、鍵をつくって GitHub に登録しなおした。

だから staging の .ssh/config は以下のような感じ

[ec2-user@release_server ~]$ cat .ssh/config
Host github.com
    HostName github.com
    IdentityFile ~/.ssh/id_rsa_staging
    TCPKeepAlive yes
    IdentitiesOnly yes
    User git

CircleCI の環境変数

ここに一覧があります。便利です。
https://circleci.com/docs/1.0/environment-variables/

特定のユーザー配下へのマージのときだけ deploy を動かしたい

今回、ざっくり以下のようなデプロイコマンドを書いていました。

.circleci/config.yml_抜粋
- deploy:
    name: Deploy
    command: |
      if [ "${CIRCLE_BRANCH}" == "staging" ]; then
        bundle exec cap staging deploy
      elif [ "${CIRCLE_BRANCH}" == "master" ]; then
        bundle exec cap production deploy
      fi

これだと、 mochizukikotaro/project_name へのマージでも company_name/project_name へのマージでも staging ブランチへのマージだと、デプロイが動いてしまいます。

これは辛いです。 company_name/ のときだけデプロイをしたいです。

ということで、環境変数の CIRCLE_PROJECT_USERNAME を使います。

if [ "${CIRCLE_PROJECT_USERNAME}" == "basicinc" ]; then

としました。この辺は workflow つかったりして、コードを綺麗にしたい気持ちなりました。(まだしてない)

0
1
2

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
1