- Change your secrets.yml file as following:
default: &default
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
devise_secret: <%= ENV["DEVISE_SECRET"] %>
development:
<<: *default
test:
<<: *default
staging:
<<: *default
production:
<<: *default
And your database.yml as following:
postgresql: &postgresql
adapter: postgresql
encoding: unicode
pool: 5
default: &default
database: <%= ENV['DB_NAME'] %>
username: <%= ENV['DB_USERNAME'] %>
password: <%= ENV['DB_PASSWORD'] %>
development:
<<: *postgresql
<<: *default
test:
<<: *postgresql
username: test
password:
database: your_app_name_test
staging:
<<: *postgresql
<<: *default
production:
<<: *postgresql
<<: *default
Create a .rbenv-vars with all the data for development and add it to your .gitignore.
- Set up your DNS zones
- Install the packages you need your server! (nginx, ruby, rbenv, rbenv-vars, monit, postgresql, libpq-dev, postgresql-contrib)
- Create a new user with
adduser deploy --disabled-password
. Share a SSH key (ssh-keygen -t rsa -b 4096
) with your server and another for the repository. Create a new postgresql usersu - postgres
psql
CREATE ROLE deploy LOGIN PASSWORD 'my_password' SUPERUSER; CREATE DATABASE deploy WITH OWNER = deploy;
- Add
gem 'capistrano-3-rails-template', git: 'https://github.com/n-studio/capistrano-3-rails-template.git', group: :development, branch: 'passenger'
to your Gemfile. You will probably need to addpg
,unicorn
andtherubyracer
. Runbundle update
. Commit and push to your repository. - run
rails g capistrano:rails_template
- set
set :application, 'name_of_application'
set :repo_url, '[email protected]:username/my_repository.git'
set :secret_keys, [:secret_key_base, :db_name, :db_username, :db_password] # all the keys in your .rbenv-vars
- set
server 'example.com', user: 'deploy', roles: %w{web app db}
set :server_name, "mywebsite.com"
set :deploy_user, "deploy"
- If you deploy on a custom environment like staging, don't forget to create a staging.rb file
cap staging before_deploy:sudo_conf
Add the generated lines to your sudoer- run
cap staging deploy:setup_config
cap staging deploy:setup_secrets
cap staging deploy:first_deploy
And the website is live!
- Add
worker
in your roles. - Uncomment the sidekiq related lines in
sudo.cap
, runcap staging before_deploy:sudo_conf
and edit your sudoer file with the generated lines - Set
:sidekiq_queue
- Add
config/sidekiq.yml
in:linked_files
- Add
sidekiq.yml
in:config_files
- Run
cap staging deploy:setup_config
again - Run
cap staging sidekiq:enable
- Add
ws
in your roles. - Uncomment the action cable related lines in
sudo.cap
, runcap staging before_deploy:sudo_conf
and edit your sudoer file with the generated lines - Add
actioncable.service
in:config_files
- Run
cap staging deploy:setup_config
again - Run
cap staging cable:enable
Whenever you update your Ruby version, don't forget to run cap staging deploy:setup_config
again.
Most of the scripts come from:
- Open issues!
- Send pull requests!