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