LoginSignup
21
21

More than 5 years have passed since last update.

capistrano+werckerで複数の環境に自動デプロイ

Last updated at Posted at 2014-08-19

capistrano自体はcapistrano-ext使えばproductionとかstagingとか複数環境へのデプロイができるようになるけど、それをwercker使って複数環境に自動デプロイできるようにした。

こちらを事前に見ておくと良いかもです。
Rails+postgresql+capistrano環境のwercker設定

wercker.ymlファイル

$WERCKER_DEPLOYTARGET_NAME という環境変数がdeploy先の名前として使える(後述の管理画面から指定するやつ)ので下記のようにymlファイルを作成する。

wercker.yml
deploy:
    steps:
        - bundle-install
        - script:
            name: make .ssh directory
            code: mkdir -p "$HOME/.ssh"
        - create-file:
            name: write ssh key
            filename: $HOME/.ssh/id_rsa
            overwrite: true
            hide-from-log: true
            content: $WERCKER_SSH_KEY_PRIVATE
        - script:
            name: set permissions for ssh key
            code: chmod 0400 $HOME/.ssh/id_rsa
        - cap:
            stage: $WERCKER_DEPLOYTARGET_NAME
            tasks: deploy

werckerの管理画面からDeploy targetsを設定

下記サムネイルの例はmasterブランチにmergeされたらproduction環境にデプロイしたい場合。stagingブランチにmergeされたらstaging環境にデプロイしたければ両方stagingと書けばいい。

スクリーンショット 2014-08-19 18.17.55.png

いくつか環境があればその分だけ管理画面から作成してあげればそれだけ自動デプロイされるようになります。

21
21
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
21
21