When deploying, Capistrano puts a REVISION file into your application's release directory. It contains the hash of the commit which was deployed. If you want to know the currently...
...deployed release, simply SSH to a server and view that file. $ cat /var/www/my-project/current/REVISION cf8734ece3938fc67262ad5e0d4336f820689307 Capistrano task When your application is deployed to multiple servers, you probably want to see a...
...restart-app /path/to/app You should not need to know which one to use. Instead, the capistrano-passenger gem will choose the appropriate restart mechanism automatically based on your installed the...
...passenger version. Installation Add to your Gemfile: gem 'capistrano-passenger', require: false Add to your Capfile: require 'capistrano/passenger' Declare which server role should be restarted (optional). Usually passenger tries to...
...are sensitive and must not be stored on your machine. Instead, put the attached capistrano task into lib/capistrano/tasks/ of your application. It expects environment specific keys to live in :shared...
...path/config/credentials/:stage.key. If you have a single master.key (e.g. on Rails < 7.2), edit the Capistrano task to find the key at :shared_path/config/master.key instead. Usage cap credentials:edit
...using Webpacker and Capistrano, there are a few configuration tweaks that optimize the experience. Using capistrano-rails capistrano-rails is a Gem that adds Rails specifics to Capistrano, i.e. support...
...here, but add the Webpacker cache dir (see link below) set :linked_dirs, %w[… tmp/cache/webpacker] # capistrano-rails config set :assets_roles, %i[webpack] # Give the webpack role to a single...
Using Capistrano, we usually have some array configurations in the config/deploy.rb file, like set :linked_files, %w[config/database.yml], so in this case we don't have to manage the database...
...but not every deploy target has this feature activated. Here comes a nice handy Capistrano feature, which lets us modify the default configuration for individual environments, instead of copying the...
This Capistrano task runs a command on all servers. bundle exec cap production app:run cmd='zgrep -P "..." RAILS_ROOT/log/production.log' Code # lib/capistrano/tasks/app.rake namespace :app do # Use e.g. to grep logs...
end else puts 'x Canceled.' end end Make sure you require custom Capistrano task files: # Capfile Dir.glob('lib/capistrano/tasks/*.rake').each do |r| # `import r` calls Rake.application.add_import(r...
In Capistrano 3, your Capfile requires 'capistrano/rails/migrations', which brings two Capistrano tasks: deploy:migrate and deploy:migrating. The former checks whether migrations should be performed. If so, the latter is...
Capistrano is by default configured to exclude the gems of the groups development and test when deploying to the stages production and staging. Whenever you create custom groups in your...
Remember How to skip Sprockets asset compile during Capistrano deployment and Automatically skipping asset compilation when assets have not changed? Turns out there is an even better way to speed...
...up Capistrano deployments with asset compilation – and it's even simpler. Adding the asset cache directory to symlinked directories Popular asset managers for Rails are Sprockets and Webpacker. Both keep...
Whenever requires you to set the application attribute in your Capistrano configuration. Otherwise your cronjobs are created multiple times. Example entry in config/deploy.rb: set :application, 'some-app' # allows "set :whenever...
Capistrano 3 has a doctor task that will print information about Environment: Ruby, Rubygems and Bundler versions List of Capistrano gems and whether an update is available All config variables...
...and their values Capistrano server config $ bundle exec cap staging doctor
...to install some tasks only for a given Rails environment or for a given Capistrano stage ("deployment target"). Installing jobs only for a given Rails environment In your schedule.rb you...
...environment=staging bundle exec whenever --set environment=production Installing jobs only for a given Capistrano stage In some apps we have custom capistrano stages like this: customer1-staging customer1-production...
When deploying with capistrano it's possible you get this "error" message: *** [err :: example.com] There are no Phusion Passenger-served applications running whose paths begin with '/var/www/example.com'. *** [err :: example.com]
...this error, the configuration option --ignore-app-not-running is not set. We recommend using capistrano-passenger which has this option set as default. See How to let passenger restart...
You can hook into Slack when using Capistrano for deployment. The slackistrano gem does most of the heavy lifting for you. Its default messages are unobtrusive and can be adjusted...
...it posts to a Slack channel like this: How to integrate Integrating Slackistrano with Capistrano 3 is fairly simple. In your Slack, open menu → Administration → Manage apps, and add an...
...you say... before 'deploy:update_code', 'db:dump' after 'deploy:symlink', 'craken:install' # Capistrano 2.9.0 after 'deploy:create_symlink', 'craken:install' # Capistrano 2.12.0 after 'deploy:restart', 'db:show_dump...
In newer passenger versions the output of passenger -v has changed. capistrano-passenger tries to parse the version and now causes the error undefined method '[]' for nil:NilClass. To fix...
...this you only need to upgrade the capistrano-passenger gem. Therefore run bundle update capistrano-passenger --conservative. The version change of passenger from 6.0.7 to 6.0.8 has triggered this problem...
Issue: You have an app using jsbundling-rails and esbuild. After deploy, the assets built by esbuild are missing in...
When deploying code with Capistrano (depending on your configuration) at some point Capistrano tries to check out code from your repository. In order to do so, Capistrano connects to your...
Capistrano 2 brings the shell command which allows you to run commands on your deployment targets. There is also invoke to run a command directly from your terminal.
...allow running Capistrano tasks or shell commands, and scope to individual machines or machine roles. Unfortunately Capistrano 3 does not include these commands any more. cap shell Basics
SSHKit 1.9.0 might fail with the following error, when trying to deploy a Rail application. Upgrading the gem to version...
...not found. This happens inside the deploy:assets:backup_manifest task. This task comes from capistrano-rails. It is build for Sprockets and does not work with Webpacker out of...
Solution Configure capistrano-rails to work with Webpacker Alternative If you are using capistrano-rails, but don't want to configure it for Webpacker, you can as well...
When you have a hook in your Capistrano file that dumps your remote database, you might not want it to dump each time you deploy (say, you're experimenting with...
...staging and don't want ten dumps an hour). How to skip dump creation: Capistrano 2 In your Capistrano file: before 'deploy:update_code', 'db:dump' unless fetch(:skip_dump...
...deploy:after_deploy_tasks' # Keep this last Deploy with bundle exec. Now, when deploying, Capistrano will first check if there are any pending before deploy tasks. If so, it will...
Capistrano 3 is a major rework of the framework and requires several adjustments to your deploy configuration files. The biggest change is that they moved away from their custom DSL...
Step 1: Upgrade guide For migration from 2 to 3, follow this tutorial: Capistrano 3 Upgrade Guide. Step 2: More changes Task syntax has changed. desc 'Run script'