Rails-5 application deploy configuration using puma and nginx.
- Optional configuration of production and staging environments in same server.
- Embedded Nginx configuration.
- Embedded Puma init script and puma configuration.
- Log rotation.
Requires following gems.
gem 'puma'
group :development do
gem 'capistrano'
gem 'capistrano-bundler'
gem 'capistrano-rails'
gem 'capistrano-rails-console'
gem 'capistrano-rbenv'
end
- Copy following files in your application root maintaining the structure:
.
βββ Capfile
βββ config
β βββ deploy
β β βββ shared
β β β βββ application.yml.template.erb
β β β βββ database.yml.template.erb
β β β βββ log_rotation.erb
β β β βββ nginx.conf.erb
β β β βββ puma.rb.erb
β β β βββ puma_init.sh.erb
β β β βββ secrets.yml.template.erb
β β βββ production.rb
β β βββ staging.rb
β βββ deploy.rb
βββ lib
βββ capistrano
βββ substitute_strings.rb
βββ tasks
β βββ check_revision.cap
β βββ compile_assets_locally.cap
β βββ db.cap
β βββ logs.cap
β βββ monit.cap
β βββ nginx.cap
β βββ puma.cap
β βββ push_deploy_tag.cap
β βββ run_tests.cap
β βββ setup_config.cap
βββ template.rb
- Put rails project's git url under :repo_url in 'config/deploy.rb' file.
Example:
#config/deploy.rb
set :repo_url, '[email protected]:user/repo.git'
- Change application name under :application in 'config/deploy.rb' file.
Example:
#config/deploy.rb
set :application, 'demo_application'
- Define servers in 'config/deploy/production.rb' and 'config/deploy/staging.rb'
Example:
server '192.168.33.10', user: fetch(:deploy_user).to_s, roles: %w(app db), primary: true
server '192.168.33.11', user: fetch(:deploy_user).to_s, roles: %w(app), primary: true
server '192.168.33.12', user: fetch(:deploy_user).to_s, roles: %w(app), primary: true
-
Set server name in 'config/deploy/production.rb' and 'config/deploy/staging.rb'
Example:
# config/deploy/production.rb
set :server_names, {
'192.168.33.10': '192.168.33.10 node0.server',
'192.168.33.11': '192.168.33.11 node1.server',
'192.168.33.12': '192.168.33.12 node2.server',
}
- Set certificate and key path in 'config/deploy/production.rb' and 'config/deploy/staging.rb'g
set :nginx_certificate_path, "#{shared_path}/certificates/#{fetch(:stage)}.crt"
set :nginx_key_path, "#{shared_path}/certificates/#{fetch(:stage)}.key"
For different certificate and key name in different server
set :nginx_certificate_paths, {
'192.168.33.10': "/etc/certificates/192_168_33_10.crt",
'192.168.33.11': "/etc/certificates/192_168_33_11.crt",
'192.168.33.12': "/etc/certificates/192_168_33_12.crt",
}
set :nginx_key_paths, {
'192.168.33.10': "/etc/certificates/192_168_33_10.key",
'192.168.33.11': "/etc/certificates/192_168_33_11.key",
'192.168.33.12': "/etc/certificates/192_168_33_12.key",
}
Note: configuration key name changes from *_path
to *_paths
- Upload configurations
$ bundle exec cap production deploy:setup_config
- Deploy
$ bundle exec cap production deploy
Bug reports and pull requests are welcome on GitHub at puma-deploy repository. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
- Indrajit Roy - Owner - eendroroy
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE.md file for details