LoginSignup
19
20

More than 5 years have passed since last update.

Herokuでステージング環境を作成する

Last updated at Posted at 2015-08-02

はじめに

Herokuでは、既存のアプリケーションをフォークすることができます。フォークするとHeroku Postgresのデータやアドオンや設定値も含めてコピーされます。これでステージング環境を非常に簡単に作成することができます。普通はステージング環境を整えるのは非常に苦労をするので、この簡単さはHerokuの魅力ですね。

準備

Setup

Heroku Toolbeltを最新化してください。

既存のアプリケーションをフォークする

Forking Applications

heroku forkコマンドで既存のアプリケーションをフォークすることができます。
heroku fork --from sourceapp --to targetapp
sourceappは既存のアプリケーション名、targetappはフォーク時のアプリケーション名になります。

実行例:フォークしてステージング環境を作成しています。
MyAppNameは適宜読みかえてください。

$ heroku fork --from MyAppName --to MyAppName-st
Forking MyAppName... done. Forked to MyAppName-st
Setting buildpacks... done
Deploying 352f088 to MyAppName-st... done
Adding addon heroku-postgresql:hobby-dev to MyAppName-st... done
Transferring DATABASE to DATABASE...
Progress: done                      
Copying config vars:
  LANG
  RAILS_ENV
  RACK_ENV
  SECRET_KEY_BASE
  RAILS_SERVE_STATIC_FILES
  ... done
Fork complete. View it at https://MyAppName-st.herokuapp.com/

ステージング環境を更新する

Deploy

ステージング環境ができたら、次はステージング環境のGit URLをリモートリポジトリに登録しましょう。こうすることでデプロイができるようになります。

$ heroku info -a MyAppName-st
=== MyAppName-st
Addons:        heroku-postgresql:hobby-dev
Dynos:         1
Git URL:       https://git.heroku.com/MyAppName-st.git
Owner Email:   kimunny@example.com
Region:        us
Slug Size:     38M
Stack:         cedar-14
Web URL:       https://MyAppName-st.herokuapp.com/
Workers:       0

出てきたGit URLをリモートリポジトリとして登録します。
git remote add staging https://git.heroku.com/MyAppName-st.git

あとはこのリポジトリに対してgit pushすればデプロイできます。

以上です。

19
20
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
19
20