Panter Rails Deploy
This gem sets up everything you need to deploy your application on the Panter Rails hosting:
- Capistrano 3 setup for:
- unicorn-rails
- dotenv-rails
- mini_racer for ExecJS, used for asset compilation on the server
How to use
-
Add to your Gemfile (globally, not in a group):
gem 'panter-rails-deploy'
Note: Also remove these gems if already present:
-
unicorn,unicorn-rails -
dotenv,dotenv-rails -
capistrano,capistrano-ext,capistrano-rails,capistrano-bundler,capistrano-rbenv therubyracermini_racer
-
-
Capify your project (
bundle execis required here, unless you use rbenv-binstubs):bundle exec cap install -
Load the gem in your
Capfilewith one of these lines:For a standard Rails project with asset compilation:
require 'panter-rails-deploy'
For a Rails project that doesn't use asset compilation:
require 'panter-rails-deploy/without-assets'
For other Rack applications:
require 'panter-rails-deploy/without-rails'
-
Set
:applicationand:repo_urlinconfig/deploy.rb(note that in previous Capistrano versions it was called:repositoryinstead) -
Set up your stages in
config/deployfolder (e.g.config/deploy/production.rb):server 'my-server.example.com', roles: %w[ web app db ] set :branch, 'master' set :rails_env, 'staging' # 'production' by default for all stages
-
Profit:
bundle exec cap production deploy
dotenv setup
Using dotenv is the recommended approach to store sensitive configuration in the environment instead of code repositories.
-
Add a file on your servers in
/home/app/app/shared/.envwith your keys:RAILS_SECRET_KEY_BASE: 89d20f0...
- You can add any other key-value pairs, they'll simply be injected into
ENV - You can use
rake secret/rails secret(Rails 5) to generate a new secure key - Rails uses
SECRET_KEY_BASEby default, but adding aRAILS_prefix is recommended sincedotenvitself is framework-agnostic
- You can add any other key-value pairs, they'll simply be injected into
-
If you need keys in development as well, add
.envlocally and add it to.gitignore -
Replace your keys in
config/secrets.ymland other places with references toENV:production: secret_key_base: <%= ENV["RAILS_SECRET_KEY_BASE"] %>
-
Update
config/deploy.rbto symlink the.envfile during deploy:append :linked_files, '.env'