Skip to content

Instantly share code, notes, and snippets.

@kirankarki
Last active August 11, 2017 11:00
Show Gist options
  • Save kirankarki/c6217ebbe531206e72d343cedcd7e31c to your computer and use it in GitHub Desktop.
Save kirankarki/c6217ebbe531206e72d343cedcd7e31c to your computer and use it in GitHub Desktop.
Deploying with Puma, Capistrano and Nginx
<< Deploying with Capistrano and Capistrano3-puma >>
1. Install following gems
> capistrano, capistrano-rails, capistrano-rbenv, capistrano-bundler, capistrano3-puma
2. Generate capistrano config files
> run the following command to generate your capistrano configuration
> cap install STAGES=production
3. Require the capistrano-rails
> Add following code to 'Capfile' file
> require 'capistrano/rails'
4. Set configuration for capistrano-rbenv
> Add following codes to 'Capfile' file
require 'capistrano/rbenv'
set :rbenv_type, :user
set :rbenv_ruby, '2.3.1'
* Optionally, the above set codes can be kept in 'config/deploy/proudction.rb'
5. Configuration for the config/deploy.rb
> Add following codes to 'config/deploy.rb' file
set :application, "my_app_name"
set :repo_url, "git@example.com:me/my_repo.git"
set :deploy_to, '/home/deploy/my_app_name'
append :linked_files, "config/database.yml", "config/secrets.yml"
append :linked_dirs, "log", "pids", "tmp/cache", "sockets", "public/system", "vendor/bundle", "public/uploads"
6. Configuration for 'config/deploy/production.rb' file
> Add following codes to 'config/deploy/production.rb' file
server '127.0.0.1', user: 'deploy', roles: %w{app db web}
7. SSH configuration
> Add follwoing codes to 'config/deploy/production.rb' file
set :ssh_options, {
keys: %w(~/.ssh/id_rsa),
forward_agent: true
}
8. Configuration for 'capistrano-bundler'
> require 'capistrano-bundler' in 'Capfile' file
require 'capistrano/bundler'
9. Configuration for 'capistrano-puma'
> require 'capistrano-puma' in 'Capfile' file.
require 'capistrano/puma'
install_plugin Capistrano::Puma # Default puma tasks
> Add following codes to 'config/deploy.rb'
# Configurations for Puma
set :puma_threads, [0, 16]
set :puma_workers, 0
set :puma_jungle_conf, '/etc/puma.conf'
set :puma_run_path, '/usr/local/bin/run-puma'
set :puma_bind, "unix://#{shared_path}/sockets/puma.sock"
set :puma_init_active_record, true
set :puma_state, "#{shared_path}/pids/puma.state"
set :puma_pid, "#{shared_path}/pids/puma.pid"
set :puma_access_log, "#{shared_path}/log/puma.error.log"
set :puma_error_log, "#{shared_path}/log/puma.access.log"
set :puma_preload_app, false
set :puma_worker_timeout, nil
set :puma_role, :app
set :puma_env, fetch(:rack_env, fetch(:rails_env, 'production'))
> Create database.yml and secrets.yml in 'shared/config' folder of server
> Run 'cap production deploy:check' to check the configs
< References >
https://gorails.com/deploy/ubuntu/16.04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment