|
| 1 | +# Rails with Capistrano |
| 2 | + |
| 3 | +A sample application to demonstrate deployment of Capistrano driven Rails apps in [Dockbit](https://dockbit.com). The guide below describes how to prepare a target server and also may be used as a starter kit for running Rails applications in a single server environment. It is built upon [Ubuntu 14.04](http://releases.ubuntu.com/14.04/) with the following components: |
| 4 | + |
| 5 | +* [Unicorn](http://unicorn.bogomips.org/) Web server with an init script and zero-downtime configuration |
| 6 | +* [Nginx](http://nginx.org/) Proxy with a production like settings and optional SSL |
| 7 | +* [Log rotation](http://www.linuxcommand.org/man_pages/logrotate8.html) with sane defaults |
| 8 | +* [Capistrano](http://capistranorb.com/) recipes for Rails applications |
| 9 | + |
| 10 | +## Preparing target server |
| 11 | + |
| 12 | +### Update server info |
| 13 | + |
| 14 | +Open [config/deploy/production.rb](./config/deploy/production.rb) and ```set :host_name``` to FQDN of your target server. |
| 15 | + |
| 16 | +### Create deployment user |
| 17 | + |
| 18 | + useradd deployer -m -s /bin/bash |
| 19 | + passwd deployer # Remember password, you'll need it later |
| 20 | + echo 'deployer ALL=NOPASSWD: ALL' >> /etc/sudoers |
| 21 | + su - deployer |
| 22 | + |
| 23 | +### Install dependencies |
| 24 | + |
| 25 | + sudo apt-get -y update |
| 26 | + sudo apt-get -y install nginx git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev |
| 27 | + |
| 28 | +### Install Javascript Runtime |
| 29 | + |
| 30 | + sudo add-apt-repository -y ppa:chris-lea/node.js |
| 31 | + sudo apt-get -y update |
| 32 | + sudo apt-get -y install nodejs |
| 33 | + |
| 34 | +### Install Rbenv |
| 35 | + |
| 36 | + cd |
| 37 | + git clone git://github.com/sstephenson/rbenv.git .rbenv |
| 38 | + echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile |
| 39 | + echo 'eval "$(rbenv init -)"' >> ~/.bash_profile |
| 40 | + |
| 41 | + git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build |
| 42 | + echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bash_profile |
| 43 | + source ~/.bash_profile |
| 44 | + |
| 45 | +### Install Ruby and Bundler |
| 46 | + |
| 47 | + rbenv install -v 2.2.2 |
| 48 | + rbenv global 2.2.2 |
| 49 | + gem install bundler --no-ri --no-rdoc |
| 50 | + rbenv rehash |
| 51 | + |
| 52 | +### Set up credentials |
| 53 | + |
| 54 | +Finally, you need to provide Rails secret key base as an environment variable. Run this command from within your Rails application on your machine: |
| 55 | + |
| 56 | + echo "export SECRET_KEY_BASE=\"$(bundle exec rake secret)\"" | ssh deployer@FQDN_OF_YOUR_SERVER 'cat >> ~/.bash_profile' |
| 57 | + |
| 58 | +You now have a target server and can proceed adding it to your deployment pipeline in Dockbit. |
| 59 | + |
| 60 | + |
0 commit comments