A sample application to demonstrate deployment of Capistrano driven Rails apps in Dockbit. 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 with the following components:
- Unicorn Web server with an init script and zero-downtime configuration
- Nginx Proxy with a production like settings and optional SSL
- Log rotation with sane defaults
- Capistrano recipes for Rails applications
Open config/deploy/production.rb and set :host_name
to FQDN of your target server.
useradd deployer -m -s /bin/bash
passwd deployer # Remember password, you'll need it later
echo 'deployer ALL=NOPASSWD: ALL' >> /etc/sudoers
su - deployer
sudo apt-get -y update
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
sudo add-apt-repository -y ppa:chris-lea/node.js
sudo apt-get -y update
sudo apt-get -y install nodejs
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
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
rbenv install -v 2.2.2
rbenv global 2.2.2
gem install bundler --no-ri --no-rdoc
rbenv rehash
Finally, you need to provide Rails secret key base as an environment variable. Run this command from within your Rails application on your machine:
echo "export SECRET_KEY_BASE=\"$(bundle exec rake secret)\"" | ssh deployer@FQDN_OF_YOUR_SERVER 'cat >> ~/.bash_profile'
You now have a target server and can proceed adding it to your deployment pipeline in Dockbit.
See the LICENSE file for license rights and limitations (MIT).