PLEASE NOTE, THIS PROJECT IS NO LONGER BEING MAINTAINED
Evrone collection of Capistrano recipes
We deploy a lot of Rails applications and our developers have to solve similar problems each time during the deployment: how to run workers, how to generate crontab, how to precompile assets faster and so on. This collection of recipes helps us to solve them.
Getting Started
Prerequisites
Recipe use:
-
foreman
+foreman_export_runitu
to generate runit scripts with the Procfile -
whenever
to generate crontab -
unicorn
to run the application
It also consider that you use system wide rbenv on the server.
Installation
gem 'capistrano_evrone_recipes', :require => false
require "capistrano_evrone_recipes/capistrano"
Capistrano default variables:
logger.level = Capistrano::Logger::DEBUG
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
set :bundle_cmd, "rbenv exec bundle"
set :bundle_flags, "--deployment --quiet --binstubs --shebang ruby-local-exec"
set :rake, -> { "#{bundle_cmd} exec rake" }
set :keep_releases, 7
set :scm, "git"
set :user, "deploy"
set :deploy_via, :unshared_remote_cache
set :copy_exclude, [".git"]
set :repository_cache, -> { "#{deploy_to}/shared/#{application}.git" }
set :normalize_asset_timestamps, false
To enable silent mode, add ENV['CAP_SILENT_MODE']
before the require 'capistrano_evrone_recipes/capistrano'
in your Capfile
Usage
Capfile example:
set :repository, "git@github.com:..."
set :application, "my_cook_application"
task :production do
role :web, "web.example.com"
role :app, "app.example.com"
role :crontab, "app.example.com"
role, :db, "db.example.com", :primary => true
role, :worker, "workers.example.com"
end
task :staging do
server "stage.example.com", :web, :app, :crontab, :db, :worker
end
As you can see, we use use roles to bind the tasks, and there are some additions to roles and additional roles:
web compiles assets if content of app/assets
was changed since last deploy (add FORCE=1 to force the assets compilation)
app all files from shared/config
is being symlinked to current/config
like:
shared/config/database.yml -> current/config/database.yml
shared/config/settings/production.yml -> current/config/settings/production.yml
crontab generates crontab with whenever
gem, only if the content of config/schedule.rb
was changed
(add FORCE=1 to force the crontab generation)
db run migrations only if db/migrate
was changed (add FORCE=1 to force migrations or SKIP_MIGRATION=1 to skip them)
worker Procfile exports runit configs to deploy_to/application/services
On deploy:restart unicorn and runit workers is being restarted.
You can use some extra cap
tasks:
-
rails:console
to launchrails console
on remote server -
rails:dbconsole
to launchrails dbconsole
on remote server -
login
to open SSH session under userdeploy
and switch catalog to Capistrano'scurrent_path
Important
To run succesfully together with system wide rbenv, all you tasks in Procfile must be started with rbenv exec
Contributing
Please read Code of Conduct and Contributing Guidelines for submitting pull requests to us.
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
Authors
- Dmitry Galinsky - Initial work
See also the list of contributors who participated in this project.
License
This project is licensed under the MIT License.