1

I have created a droplet on digital ocean of ruby on rails with already configured nginx and unicorn server.

How can i deploy my already created rails app to that server.

Should I use capistrano to deploy? Or is there any other way to deploy?

I have been to digital ocean guide for deployment but it is very confusing for a beginner like me.

Tutorial used for creating droplet.

I have the same droplet created

1
  • The one-click install does not use Capistrano, nor Unicorn. It's a very basic Rails install using Webbrick as the server. If you can get your app running within their very simple config, that's a good step one, then add complications once you confirmed your app launches in Webbrick. Commented Apr 22, 2015 at 16:32

3 Answers 3

8

I will try to explain it step by step. Use Ubuntu 12 or 14. You need Nginx, RoR, Capistrano, git, passenger.

0. Log int to server

ssh root@server_ip

You can find ip here https://cloud.digitalocean.com/droplets

1. Create a user (if needed)

adduser deployer

2. Move user to sudo users

visudo
deployer ALL=(ALL:ALL) ALL

3. Install bash for him

nano /etc/passwd
Change /bin/sh to /bin/bash

4. Change ssh-port for security

nano /etc/ssh/sshd_config
Change Port 22 on Port XXXX (where XXXX is any number)

5. reload ssh

6. Enter by ssh with our new user

ssh -p XXXX [email protected]

7. Update system if needed

sudo apt-get update 
sudo apt-get upgrade
sudo apt-get install curl

8. Install rvm:

curl -L get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm requirements

9. Install ruby, postgres, etc..

rvm install [version of ruby similar to app]

sudo apt-get install postgresql

If cluster was not created, do it manually:

sudo pg_createcluster [postgresql_version] main --start

sudo apt-get install language-pack-en-base
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
locale-gen en_US.UTF-8
sudo dpkg-reconfigure locales

Create postgres user

sudo -u postgres psql 
alter user postgres with password '[password]';

To quit from psql press \q

sudo apt-get install git-core

10. Install gem passenger:

gem install passenger

11. Install nginx using passenger

rvmsudo passenger-install-nginx-module

12. Set swap if needed

sudo dd if=/dev/zero of=/swap bs=1M count=1024
sudo mkswap /swap
sudo swapon /swap

13. Change config of nginx (server section):

server {
      listen 80;
      server_name www.yourhost.com;
      root /somewhere/public;   # <--- be sure to point to 'public'!
      passenger_enabled on;
      location ^~ /assets/ 
           { gzip_static on; 
           expires max; 
           add_header Cache-Control public; 
      }
 }

14. Clone good script for nginx start/stop/restart if Ubuntu:

git clone https://github.com/vkurennov/rails-nginx-passenger-ubuntu.git
sudo cp nginx/nginx.conf /etc/init.d/nginx.conf
sudo chmod +x /etc/init.d/nginx/conf

15. Run nginx:

sudo /etc/init.d/nginx start

BOYA!! Check your browser!

Let's go to our app!

1. gem ‘capistrano’ for depoly

group :development do
  gem 'capistrano'
  gem 'rvm-capistrano'
  gem 'net-ssh’, ‘2.7.0'
end

2. Run:

capify .

Open deploy.rb and set:

set :application, 'app_title'
set :repository,  'app_repo'

5. add:

require 'bundler/capistrano'
require "rvm/capistrano"

load 'deploy/assets’

set :port, XXXX
set :use_sudo, false

set :rails_env, :production
set :branch, "master"
set :deploy_to, "/home/deployer/app_title"
set :user, 'deployer'

role :web, "XXX.XXX.XXX.XXX"                          # Your HTTP server, Apache/etc
role :app, "XXX.XXX.XXX.XXX"                          # This may be the same as your `Web` server
role :db,  "XXX.XXX.XXX.XXX", :primary => true # This is where Rails migrations will run

6. cap deploy:check

7. cap deploy:setup

set :bundle_cmd, "/home/deployer/.rvm/gems/ruby-2.0.0-p451@global/bin/bundle"
set :bundle_dir, "/home/deployer/.rvm/gems/ruby-2.0.0-p451"

set :rvm_type, :user
set :rvm_ruby_string, 'ruby-2.0.0-p451@global'

8. Recipes for deploy:

namespace :deploy do
  task :start do ; end
  task :stop do ; end
  task :restart, :roles => :app, :except => { :no_release => true } do
    run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
  end
end

9. Clone ssh-key on server and add to repo

ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub

10. Add gem ‘therubyracer’

11. cap deploy:cold

Boya! I opened for questions if smth is not clear.

Sign up to request clarification or add additional context in comments.

1 Comment

I know about this process and have done for one of my project successfully. but currently I have droplet created with auto installed rails. digitalocean.com/community/tutorials/…
0

Yes you can use Capistrano for deployment, it is best practice to use Capistrano you can refer http://robmclarty.com/blog/how-to-deploy-a-rails-4-app-with-git-and-capistrano.

let me know if you face any issue.

5 Comments

digitalocean.com/community/tutorials/… I have this image and want to use this only. Can you guide me?
Means you need to configure application with nginx and Unicorn?
Yes I need to deploy and configure my application with currently installed nginx and unicorn
Thanks but currently of no use. can you please explain link this
0

Or you can also use mina for deployment. It is like capistrano but it is easier and much more faster than capistrano.

Take a look at: https://www.digitalocean.com/community/tutorials/how-to-use-mina-to-deploy-a-ruby-on-rails-application

1 Comment

I want to deploy my app and configure it with currently installed nginx and unicorn.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.