LoginSignup
6
6

More than 5 years have passed since last update.

EC2+Mercurial+Rails環境でcapistranoを使ったデプロイ方法

Last updated at Posted at 2013-08-22

EC2+Mercurial+Railsという少し限定的な環境でのデプロイ設定方法。

[前提条件]
リポジトリが存在する。
デプロイサーバーが存在する。
デプロイ先のサーバーが存在する。
デプロイサーバーにmercurialがインストールされている。
(mercurialのバージョンは1.7以上)

デプロイユーザー作成

SSHで接続可能なdeployユーザーを作成する。
http://qiita.com/dahugani/items/e1fc5c212bf6a7365f8f

capistranoのインストール

gemからcapistranoする。
ついでに色を変えたり、環境先を変えたり、railsアプリ以外をデプロイできるなど設定ができるgemも入れる。

gem 'capistrano'
gem 'capistrano-ext'

capistranoはコメントインでもいい。

AWS-SDKインストール

Gemfileにaws-sdkを追加

gem 'aws-sdk'
bundle install

capistranoの設定

設定ファイルの作成

capify .

EC2+bitbucket+rails用に書き換える(全てを書き換える)。

deploy.rb
require 'rubygems'

#AWSdefine
set :aws_access_key_id,     ENV['アクセスキー']
set :aws_secret_access_key, ENV['シークレットキー']

set :application, "linknet"
set :deploy_to, "/var/www/apps/#{application}"
set :repository,  "リポジトリのURL"
# set :scm, :git # You can set :scm explicitly or Capistrano will make an intelligent guess based on known version control directory names
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
set :scm ,:mercurial
set :deploy_via, :copy

# The address of the remote host on EC2 (the Public DNS address)
set :location, "EC2のホスト名"

set :user, "デプロイ用ユーザー名"
set :use_sudo, false
ssh_options[:forward_agent] = true
ssh_options[:keys] = ["デプロイ用ユーザーの秘密鍵"]
default_run_options[:pty] = true

# setup some Capistrano roles
role :app, location
role :web, location
role :db,  location, :primary => true

セットアップのコマンドを実行する。

cap deploy:setup
6
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
6
6