3
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

herokuのforkを利用してステージング環境を作成し、CircleCIで自動デプロイする

Posted at

概要

Rails4アプリの本番環境をherokuにデプロイしている。
今まではステージング環境を完全に別アプリとして構築していたが、
forkを使うといい感じにできるらしいので、改めて設定し直してみた。
また、既存のcircle.ymlもそれに合わせて設定し直す。

fork

今回はすでに本番環境があるので、そこからforkしてステージングを作る。
(下記のログを見ると、アドオンや環境変数もコピーされているのが分かる)

$ heroku fork --from (APP) --to (APP_FOR_STAGING)
Forking (APP)... done. Forked to (APP_FOR_STAGING)
Setting buildpacks... done
Deploying f4e5b0d to (APP_FOR_STAGING)... done
Adding addon papertrail:choklad to (APP_FOR_STAGING)... done
Adding addon newrelic:wayne to (APP_FOR_STAGING)... done
Adding addon heroku-postgresql:hobby-dev to (APP_FOR_STAGING)... done
Transferring DATABASE to DATABASE...
Progress: done                      
Copying config vars:
  LANG
  RAILS_ENV
  RACK_ENV
  SECRET_KEY_BASE
  RAILS_SERVE_STATIC_FILES
  MAILER_USER
  MAILER_PASSWORD
  NEW_RELIC_APP_NAME
  ... done
Fork complete. View it at https://(APP_FOR_STAGING).herokuapp.com/

以上!簡単すぎる!
今度からforkを活用しよう。

※ ちなみにfork元がなく新規に作成する場合は、createコマンドを利用する。

$ heroku create --remote (APP)

CircleCI設定

上記設定を元にcircle.ymlを書き直す。
以下、デプロイ部分を抜粋。

deployment:
  production:
    branch: master
    heroku:
      appname: (APP)
  staging:
    branch: staging #ステージングデプロイに紐付けたいgitのブランチ名
    heroku:
      appname: (APP_FOR_STAGING)

以上で自動デプロイも完了!

備考

本番環境は有料プラン(Hobby dynos)を利用しているので、forkしたステージングも同じく有料になってしまうか心配だったが、
herokuダッシュボードを確認したところ無料プランで設定されていた。
これで一安心 ε-(´∀`*)ホッ

参考資料

Managing Multiple Environments for an App | Heroku Dev Center
Forking Applications | Heroku Dev Center
Continuous Deployment with Heroku - CircleCI

3
6
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
3
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?