production環境 未完

環境

Rails4
Capistrano3
Unicorn
Nginx
EC2
RDS
GitHub
http://genestream.hatenablog.com/entry/2014/12/17/212508
真似ます。

EC2

セットアップ。
自動バックアップまでセット。

rootパスワード設定。

$ sudo yum update
$ sudo yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison git
rbenvインストール

真似。

cd
git clone git://github.com/sstephenson/ruby-build.git
cd ruby-build
sudo ./install.sh
cd
git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
source ~/.bashrc
exec $SHELL -l
rbenv install -l
ちなみにrbenv削除は以下。

$ rm -rf ~/.rbenv
$ rm -rf /usr/local/bin/rbenv
$ rm -rf /usr/local/Cellar/rbenv
$ rm -rf ruby-build
.bash_profileからパス削除

rubyインストール

development環境とバージョンを合わせる。

rbenv install 2.1.2;rbenv rehash
rbenv global 2.1.2
  • p95が無かったので指定無し。

確認

$ git --version
$ ruby -v
2.1.2p95が入ってた。
$ which gem
$ which ruby
Railsインストール

bundlerインストール

$ gem install bundler --no-rdoc --no-ri
$ rbenv rehash

Railsインストール、バージョン合わせる

$ gem install rails -v 4.1.0
$ rbenv rehash
デプロイするディレクトリを作成

作成。

RDS

作成。

capistrano

Gemfile

group :development do
  gem 'capistrano', '~> 3.1.0'
  gem 'capistrano-rails', '~> 1.0.0'
  gem 'capistrano-bundler', '~> 1.1.2'
end

インストール

$ bundle exec bundle install
$ bundle exec cap install STAGES=production
├── Capfile
├── config
│   ├── deploy
│   │   ├── production.rb
│   │   └── staging.rb
│   └── deploy.rb
└── lib
    └── capistrano
            └── tasks
Capfileの編集

編集

config/deploy.rbを編集

編集

config/deploy/producution.rbの編集

編集

config/database.ymlの編集

編集

unicorn

Gemfile

gem 'unicorn'

config/unicorn.rb作成

GitHub

GitHubリポジトリを作成する。
git remote add origin url
git pull
git merge origin/master
git push -u origin master

デプロイ

チェック

$ bundle exec cap production deploy:check