Ruby ENV

Servers

Deploying

Enviroments

  1. Development
  2. Production
  3. Test
# precompile assest for production 
$ RAILS_ENV=production bundle exec rake assets:precompile

# run migrate for development
$ RAILS_ENV=development bundle exec rake db:migrate

# run rails in production mode
$ rails s -e=production

# run rails console in development mode
$ rails c RAILS_ENV=development

...

Ruby servers

PASSENGER

WebRICK

Deploying

Deploying

  • config
  • integration
  • upgrating
  • stability
  • trial
  • dear
  • limitation
  • dear
  • very dear!!

 

  • integration
  • upgrating
  • stability
  • trial

 

  • limitation
  • config

Capistrano + Unicorn

group :development do
  gem 'capistrano'
  gem 'capistrano-rails'
  gem 'capistrano-bundler'
  gem 'capistrano-rvm'
end
require 'capistrano/deploy'
require 'capistrano/rvm'
require 'capistrano/bundler'
require 'capistrano/rails'

Gemfile

Capfile

group :production do
  gem 'unicorn'
end

deploy.rb

set :application, "coaxsoft.com"
set :domain, "deploy@coaxsoft.com"
set :deploy_to, "/home/deploy/#{application}"
set :use_sudo, false
set :unicorn_conf, "#{deploy_to}/current/config/unicorn.rb"
set :unicorn_pid, "#{deploy_to}/shared/pids/unicorn.pid"

set :scm, :git
set :repository,  "git@bitbucket.org:coax_soft/coax.git"
set :branch, "master"
set :deploy_via, :remote_cache

role :web, domain
role :app, domain
role :db,  domain, :primary => true

after "deploy", "deploy:cleanup" # keep only the last 5 releases

set :shared_children, shared_children + %w{public/uploads}

namespace :carrierwave do
  task :symlink, roles: :app do
    run "ln -nfs #{shared_path}/public/uploads/ #{release_path}/public/uploads"
  end
  after "deploy:finalize_update", "carrierwave:symlink"
end

deploy.rb

...
namespace :deploy do
  task :restart do
    run "if [ -f #{unicorn_pid} ] && [ -e /proc/$(cat #{unicorn_pid}) ]; 
        then kill -9 `cat #{unicorn_pid}`; 
        cd #{deploy_to}/current && 
        bundle exec unicorn_rails -E production -c #{unicorn_conf} -D; 
    else cd #{deploy_to}/current && 
        bundle exec unicorn_rails -E production -c #{unicorn_conf} -D; fi"
    run "cd #{deploy_to}/current && 
        RAILS_ENV=production bundle exec rake sitemap:refresh"
    run "cd #{deploy_to}/current/public && 
        rm -f sitemap.xml && gunzip sitemap.xml.gz"
  end
  task :start do
    run "cd #{deploy_to}/current/ && 
        bundle exec unicorn_rails -E production -c #{unicorn_conf} -D"
    run "cd #{deploy_to}/current && 
        RAILS_ENV=production bundle exec rake sitemap:refresh"
    run "cd #{deploy_to}/current/public && 
        rm -f sitemap.xml && gunzip sitemap.xml.gz"
  end
  task :stop do
    run "if [ -f #{unicorn_pid} ] && [ -e /proc/$(cat #{unicorn_pid}) ]; 
    then kill -9 `cat #{unicorn_pid}`; fi"
  end
end

Commands

# run your deploy
$ cap production deploy

# stop your server
$ cap production deploy:stop

# start server
$ cap production deploy:start

# reboot
$ cap production deploy:restart
$ heroku create

$ git config --list | grep heroku
# remote.heroku.url=https://git.heroku.com/safe-mesa-35727.git
# remote.heroku.fetch=+refs/heads/*:refs/remotes/heroku/*

# deploy your app
$ git push heroku master

# restart your app
$ heroku restart -a app_name

DigitalOceane

Heroku

Commands

# entering by ssh
$ ssh deploy@app_domain.com

# console
$ > rails c

# migration
$ > rake db:migrate

# assets
$ > rake assets:precompile

$ > ...
# console
$ heroku run rails console

# migrate
$ heroku run rake db:migrate

# list of logs
$ heroku logs

# run rake tasks
$ heroku run rake ...

$ ...

DigitalOceane

Heroku

Sources

  1. https://devcenter.heroku.com/articles/getting-started-with-rails4
  2. https://habrahabr.ru/post/213269/
  3. https://www.digitalocean.com/community/tutorials/how-to-use-the-ruby-on-rails-one-click-application-on-digitalocean
Made with Slides.com