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
therubyracer
mini_racer
-
-
Capify your project (
bundle exec
is required here, unless you use rbenv-binstubs):bundle exec cap install
-
Load the gem in your
Capfile
with 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
:application
and:repo_url
inconfig/deploy.rb
(note that in previous Capistrano versions it was called:repository
instead) -
Set up your stages in
config/deploy
folder (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/.env
with 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_BASE
by default, but adding aRAILS_
prefix is recommended sincedotenv
itself 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
.env
locally and add it to.gitignore
-
Replace your keys in
config/secrets.yml
and other places with references toENV
:production: secret_key_base: <%= ENV["RAILS_SECRET_KEY_BASE"] %>
-
Update
config/deploy.rb
to symlink the.env
file during deploy:append :linked_files, '.env'