Code Monkey home page Code Monkey logo

rails's Introduction

Capistrano::Rails

Rails specific tasks for Capistrano v3:

  • cap deploy:migrate
  • cap deploy:compile_assets

Installation

Add these Capistrano gems to your application's Gemfile using require: false:

group :development do
  gem "capistrano", "~> 3.10", require: false
  gem "capistrano-rails", "~> 1.6", require: false
end

Run the following command to install the gems:

bundle install

Then run the generator to create a basic set of configuration files:

bundle exec cap install

Usage

Require everything (bundler, rails/assets and rails/migrations):

# Capfile
require 'capistrano/rails'

Or require just what you need manually:

# Capfile
require 'capistrano/bundler' # Rails needs Bundler, right?
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'

Please note that any requires should be placed in Capfile, not in config/deploy.rb.

You can tweak some Rails-specific options in config/deploy.rb:

# If the environment differs from the stage name
set :rails_env, 'staging'

# Defaults to :db role
set :migration_role, :db

# Defaults to the primary :db server
set :migration_servers, -> { primary(fetch(:migration_role)) }

# Defaults to `db:migrate`
set :migration_command, 'db:migrate'

# Defaults to false
# Skip migration if files in db/migrate were not modified
set :conditionally_migrate, true

# Defaults to [:web]
set :assets_roles, [:web, :app]

# Defaults to 'assets'
# This should match config.assets.prefix in your rails config/application.rb
set :assets_prefix, 'prepackaged-assets'

# Defaults to ["/path/to/release_path/public/#{fetch(:assets_prefix)}/.sprockets-manifest*", "/path/to/release_path/public/#{fetch(:assets_prefix)}/manifest*.*"]
# This should match config.assets.manifest in your rails config/application.rb
set :assets_manifests, ['app/assets/config/manifest.js']

# RAILS_GROUPS env value for the assets:precompile task. Default to nil.
set :rails_assets_groups, :assets

# If you need to touch public/images, public/javascripts, and public/stylesheets on each deploy
set :normalize_asset_timestamps, %w{public/images public/javascripts public/stylesheets}

# Defaults to nil (no asset cleanup is performed)
# If you use Rails 4+ and you'd like to clean up old assets after each deploy,
# set this to the number of versions to keep
set :keep_assets, 2

Symlinks

You'll probably want to symlink Rails shared files and directories like log, tmp and public/uploads. Make sure you enable it by setting linked_dirs and linked_files options:

# deploy.rb
append :linked_dirs, 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', '.bundle', 'public/system', 'public/uploads'
append :linked_files, 'config/database.yml', 'config/secrets.yml'

In capistrano < 3.5, before append was introduced, you can use fetch and push to get the same result.

Recommendations

While migrations looks like a concern of the database layer, Rails migrations are strictly related to the framework. Therefore, it's recommended to set the role to :app instead of :db like:

set :migration_role, :app

The advantage is you won't need to deploy your application to your database server, and overall a better separation of concerns.

Uploading your master.key

You can use the below configuration to upload your master.key to the server if it isn't already present.

append :linked_files, "config/master.key"

namespace :deploy do
  namespace :check do
    before :linked_files, :set_master_key do
      on roles(:app) do
        unless test("[ -f #{shared_path}/config/master.key ]")
          upload! 'config/master.key', "#{shared_path}/config/master.key"
        end
      end
    end
  end
end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

rails's People

Contributors

0rca avatar aliismayilov avatar annaswims avatar brendon avatar caius avatar chulkilee avatar craigmcnamara avatar defeated avatar dmytro-zakharov avatar enthrops avatar ernetas avatar ershad avatar fire-dragon-dol avatar gdott9 avatar gurgeous avatar harimohanraj89 avatar kirs avatar kronn avatar leehambley avatar littldr avatar masone avatar mattbrictson avatar paracycle avatar seenmyfate avatar taratatach avatar tenzan avatar teohm avatar umhan35 avatar uniisland avatar will-in-wi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rails's Issues

Asset touch optimization

As @whitequark wrote, current asset timestamps normalization is not optimized:

execute :find, "#{assets} -exec touch -t #{asset_timestamp} {} ';'; true"

Instead of doing dozens of touches, it's possible to do just one with file list in arguments, for example

touch `find assets`

Manifest file with a multi-server setup

Thank you for all the good work on this gem.

I'm using capistrano-unicorn-nginx for deployment to multiple servers: 1 web + 2 app + 1db on digital ocean.

  • With no configuration what-so-ever, assets are nicely pre-compiled on the web node.
  • Unfortunately, the manifest file is not automatically copied/transferred from web to app servers so unicorn is not aware of the assets. As a result generated references to javascript and css files do not contain md5 hashes and those files are not served.
  • I fixed the problem by manually copying manifest file from the web to app nodes (as shown in this stackoverflow answer) and restarting the unicorn processes. Everything works great now.

I searched through all the issues in this project and noone seems to have this problem. Is it me doing something wrong or people are using some other strategy for this?

If the above described approach is good, would you consider accepting a pull req with a task that automates that for multi-server setup?

public/assets in linked_dirs by default?

Am I correct that public/assets is in linked_dirs by default? I'm now using v3.3.3 and I'm not sure when this was introduced.

Not all Rails apps will by using the Asset Pipeline. Shouldn't this still be set explicitly by deploy.rb?

For now my linked_dirs statement in deploy.rb looks something like this.

set :linked_dirs, fetch(:linked_dirs, [])
  .push("bin", "log", "tmp/pids", "tmp/cache", "tmp/sockets")
  .reject {|dir| dir == "public/assets" }

assets_roles ignored

I'm using this GEMs for my deployment

gem 'capistrano', '3.0.1'
gem 'capistrano-rails', '1.1.0'
gem 'capistrano-bundler', '1.1.1'

In config/deploy/production.rb I defined only 1 single role

role :app, %w{capi@aws-7}

In config/deploy.rb I re defined the assets_roles:

set :assets_roles, [:app]   # Defaults to [:web]

I'm deploying like this:

cap production deploy

And somehow I got always this message and assets:precompile was skipped every time:

WARN [SKIPPING] No Matching Host for bundle exec rake assets:precompile

I could fix it by adding this line to config/deploy/production.rb:

role :web, %w{capi@aws-7}

Somehow this line in my deploy.rb is totally ignored.

set :assets_roles, [:app]   # Defaults to [:web]

Not sure if this is a bug or maybe I misconfigured something.

Symlinking log and tmp subdirectories

I seem to remember previous versions of Capistrano symlinking the log directory and subdirectories of tmp:

  • cache
  • pids
  • sessions
  • sockets

It seems like capistrano-rails symlinks public/assets but doesnโ€™t do automatically add log or any of the tmp subdirectories to linked_dirs.

Is this on purpose? It seems like you would always want log symlinked. Iโ€™m having a hard time finding any official information on whichโ€”if anyโ€”of these tmp subdirectories should be symlinked. If theyโ€™re supposed to be, then this gem should be doing so. If not, if someone can give me a quick explanation I can add some documentation so other people with the same question wonโ€™t be confused.

Run set_rails_env task after stage defining

Hello!

What about setting RAILS_ENV before all tasks after invoking stage?

Capistrano::DSL.stages.each do |stage|
  after stage, 'deploy:set_rails_env'
end

It'l be useful in other gems using RAILS_ENV for transparent support, ex. capistrano3-rails etc.

log migrations output with the info log level

Currently rake db:migrate output is only shown when the debug log level is on. I think which migrations actually get run and what changes they do is important enough to be logged with at least the info level.

Deploy fails unless bundle_bins is defined

First of, let me say I'm new to Capistrano v3 so perhaps the fault is my own.

It seems I need to explicitly define bundle_bins in order for cap to run.

 set :bundle_bins, %w{gem rake ruby}

I run into the following error when I try to deploy without the line above:

# cap production deploy --trace
** Invoke production (first_time)
** Execute production
** Invoke load:defaults (first_time)
** Execute load:defaults
** Invoke bundler:map_bins (first_time)
** Execute bundler:map_bins
cap aborted!
undefined method `each' for nil:NilClass
/usr/local/lib/ruby/gems/2.0.0/gems/capistrano-bundler-1.1.1/lib/capistrano/tasks/bundler.cap:30:in `block (2 levels) in <top (required)>'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:236:in `call'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:236:in `block in execute'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:231:in `each'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:231:in `execute'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:175:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:168:in `invoke_with_call_chain'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:161:in `invoke'
/usr/local/lib/ruby/gems/2.0.0/gems/capistrano-3.0.1/lib/capistrano/dsl.rb:14:in `invoke'
/usr/local/lib/ruby/gems/2.0.0/gems/capistrano-3.0.1/lib/capistrano/dsl/task_enhancements.rb:11:in `block in after'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:236:in `call'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:236:in `block in execute'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:231:in `each'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:231:in `execute'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:175:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:168:in `invoke_with_call_chain'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:161:in `invoke'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:149:in `invoke_task'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:106:in `each'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:106:in `block in top_level'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:115:in `run_with_threads'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:100:in `top_level'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:78:in `block in run'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:75:in `run'
/usr/local/lib/ruby/gems/2.0.0/gems/capistrano-3.0.1/lib/capistrano/application.rb:12:in `run'
/usr/local/lib/ruby/gems/2.0.0/gems/capistrano-3.0.1/bin/cap:3:in `<top (required)>'
/usr/local/bin/cap:23:in `load'
/usr/local/bin/cap:23:in `<main>'
Tasks: TOP => bundler:map_bins

Is this by design?

Best way to handle uncompiled assets?

I store a few files in public/assets that I don't want compiled.

In previous versions of capistrano, these files were preserved when capistrano compiled the other assets. Currently, it seems that they do not appear in the public/assets after deploy.

What is the best way to ensure that these assets are preserved after deploy?

Thanks!

assets:precompile issue

Hello,

i'm stuck on this issue with capistrano 3 :

#Command: 
cd /home/rails/myapp/releases/20140706030801 && ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.0.0-p481 RAILS_ENV=production RBENV_ROOT=~/.rbenv RBENV_VERSION=2.0.0-p481 ~/.rbenv/bin/rbenv exec bundle exec rake assets:precompile )

=> LoadError: libruby.so.2.0: cannot open shared object file: No such file or directory - /home/rails/myapp/shared/bundle/ruby/2.0.0/gems/therubyracer-0.12.1/lib/v8/init.so

works on my dev machine (rvm), and was working too on the staging server when i was using rvm (i rvm implode --force)

Any idea ? thanks in advance !

assets:precompile emits error messages that aren't errors

For Rails 4 and Capistrano, when assets:precompile runs, I see a lot of red lines like the following:
*** [err :: rackspace] cp public/assets/screenshots/screenshots-configure-device-9ff7a5ae03932f6c69191a07428783e1.png public/assets/screenshots/screenshots-configure-device.png
*** [err :: rackspace]
*** [err :: rackspace] cp public/assets/screenshots/screenshot-alert-locked-032e26c81654eb8691c38a60328e1e52.png public/assets/screenshots/screenshot-alert-locked.png
*** [err :: rackspace]
*** [err :: rackspace] cp public/assets/screenshots/screenshot-filters-2b048421ca24d78bdf0babb21fe3ff00.png public/assets/screenshots/screenshot-filters.png
*** [err :: rackspace]
*** [err :: rackspace] cp public/assets/active_admin-ae69b579a86accad7e86edf1e69d1f91.css public/assets/active_admin.css
*** [err :: rackspace]
*** [err :: rackspace] cp public/assets/fotorama-4.4.9/example-b11329b87f68efeada02eb07f066bf41.html public/assets/fotorama-4.4.9/example.html
*** [err :: rackspace]

These aren't really errors and they don't break the deploy, so should be emitted as info/notices rather than errors.

Run assets:precompile only when assets change in capistrano v3

After long time researching how to skip assets compilation, I found this issue. With the solution discussed there, we can manually disable assets compilation.

I would like make this default, as I do on another project using capistrano v2 using the solution explained here.

I tried to change source code of assets:precompile task, but in v3 I don't have the source method.

How to make the solution above to work on capistrano v3?

hosts filter doesn't work for deploy:migrate tasks

server 'alpha', roles: %{db web app }
server 'gamma', roles: %{web app }
server 'delta', roles: %{web app }

when trying to do HOSTS=gamma cap production deploy it fails with

...
/Users/.rvm/gems/ruby-1.9.3-p448@rp2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:66:in `execute'
/Users/.rvm/gems/ruby-1.9.3-p448@rp2/gems/sshkit-1.5.1/lib/sshkit/backends/abstract.rb:71:in `within'
/Users/.rvm/gems/ruby-1.9.3-p448@rp2/gems/capistrano-rails-1.1.2/lib/capistrano/tasks/migrations.rake:14:in `block (3 levels) in <top (required)>'
/Users/.rvm/gems/ruby-1.9.3-p448@rp2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/Users/.rvm/gems/ruby-1.9.3-p448@rp2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `run'
/Users/.rvm/gems/ruby-1.9.3-p448@rp2/gems/sshkit-1.5.1/lib/sshkit/runners/parallel.rb:13:in `block (2 levels) in execute'
....
The deploy has failed with an error: #<SSHKit::Runner::ExecuteError: Exception while executing on host alpha: if test ! -d /home/deploy/app/releases/20140930200114; then echo "Directory does not exist '/home/deploy/app/releases/20140930200114'" 1>&2; false; fi exit status: 1

so looks like it ignores HOSTS filter and tries to run deploy:migrate on alpha :(

any idea?

versions

    capistrano (3.2.1)
    capistrano-bundler (1.1.3)
    capistrano-rails (1.1.2)
    capistrano-rvm (0.1.1)

Missing public/system symlink

Hi,

I'm missing public/system symlink after deploy task. Do I have to set something in configuration or it's just missing in the task?

-q flag does not affect output

According to help:

    -q, --quiet                      Do not log messages to standard output.

However, when using this flag the output appears to be exactly the same as the standard output. Am I doing something wrong or is this a bug in Capistrano?

Migrations fail to run on deployment -> looking for 'current' path before the link is created

Hello,
I am trying to run a new installation with capistrano 3.
While deploying everything works fine untill the migrations are run. I think it is failing because is trying to access the 'current' symlink when it is not created yet.

cap staging deploy --trace fails with this message:

** Invoke deploy:migrate (first_time)
** Invoke deploy:set_rails_env.
** Execute deploy:migrate
 INFO [0e5afd89] Running ~/.rvm/bin/rvm 2.0.0-p247@MyProject do rake db:migrate on <mi.server.ip>                                                                                                                   
cap aborted!
rake stdout: Nothing written
rake stderr: Nothing written
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/sshkit-1.2.0/lib/sshkit/command.rb:94:in `exit_status='
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/sshkit-1.2.0/lib/sshkit/backends/netssh.rb:138:in `block (4 levels) in _execute'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:551:in `call'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:551:in `do_request'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:561:in `channel_request'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:221:in `preprocess'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:205:in `process'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `block in loop'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:269:in `wait'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/sshkit-1.2.0/lib/sshkit/backends/netssh.rb:160:in `block (2 levels) in _execute'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:514:in `call'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:514:in `do_open_confirmation'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:545:in `channel_open_confirmation'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:221:in `preprocess'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:205:in `process'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `block in loop'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/sshkit-1.2.0/lib/sshkit/backends/netssh.rb:162:in `block in _execute'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/sshkit-1.2.0/lib/sshkit/backends/netssh.rb:119:in `tap'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/sshkit-1.2.0/lib/sshkit/backends/netssh.rb:119:in `_execute'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/sshkit-1.2.0/lib/sshkit/backends/netssh.rb:66:in `execute'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/bundler/gems/rails-d01216c4092b/lib/capistrano/tasks/migrations.rake:10:in `block (5 levels) in <top (required)>'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/sshkit-1.2.0/lib/sshkit/backends/abstract.rb:89:in `with'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/bundler/gems/rails-d01216c4092b/lib/capistrano/tasks/migrations.rake:9:in `block (4 levels) in <top (required)>'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/sshkit-1.2.0/lib/sshkit/backends/abstract.rb:81:in `within'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/bundler/gems/rails-d01216c4092b/lib/capistrano/tasks/migrations.rake:8:in `block (3 levels) in <top (required)>'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/sshkit-1.2.0/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/sshkit-1.2.0/lib/sshkit/backends/netssh.rb:54:in `run'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/sshkit-1.2.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Tasks: TOP => deploy:migrate
translation missing: en.capistrano.deploy_failed
** Invoke deploy:failed (first_time)
** Execute deploy:failed

Running cap staging deploy:migrate --trace gives more info:

cap staging deploy:migrate --trace                                                                                                                                                                                  
** Invoke staging (first_time)
** Execute staging
** Invoke load:defaults (first_time)
** Execute load:defaults
** Invoke rvm:hook (first_time)
** Execute rvm:hook
** Invoke rvm:check (first_time)
** Execute rvm:check
rvm 1.23.13 (master) by Wayne E. Seguin <[email protected]>, Michal Papis <[email protected]> [https://rvm.io/]
ruby-2.0.0-p247
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]
** Invoke deploy:migrate (first_time)
** Invoke deploy:set_rails_env (first_time)
** Execute deploy:set_rails_env
** Execute deploy:migrate
cap aborted!
if test ! -d /my_project_path/staging/current; then echo "Directory does not exist '/my_project_path/staging/current'" 1>&2; false; fi stdout: Nothing written
if test ! -d /my_project_path/staging/current; then echo "Directory does not exist '/my_project_path/staging/current'" 1>&2; false; fi stderr: Nothing written
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/sshkit-1.2.0/lib/sshkit/command.rb:94:in `exit_status='
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/sshkit-1.2.0/lib/sshkit/backends/netssh.rb:138:in `block (4 levels) in _execute'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:551:in `call'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:551:in `do_request'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:561:in `channel_request'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:221:in `preprocess'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:205:in `process'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `block in loop'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:269:in `wait'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/sshkit-1.2.0/lib/sshkit/backends/netssh.rb:160:in `block (2 levels) in _execute'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:514:in `call'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:514:in `do_open_confirmation'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:545:in `channel_open_confirmation'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:221:in `preprocess'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:205:in `process'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `block in loop'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/sshkit-1.2.0/lib/sshkit/backends/netssh.rb:162:in `block in _execute'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/sshkit-1.2.0/lib/sshkit/backends/netssh.rb:119:in `tap'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/sshkit-1.2.0/lib/sshkit/backends/netssh.rb:119:in `_execute'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/sshkit-1.2.0/lib/sshkit/backends/netssh.rb:66:in `execute'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/sshkit-1.2.0/lib/sshkit/backends/abstract.rb:75:in `within'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/bundler/gems/rails-d01216c4092b/lib/capistrano/tasks/migrations.rake:8:in `block (3 levels) in <top (required)>'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/sshkit-1.2.0/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/sshkit-1.2.0/lib/sshkit/backends/netssh.rb:54:in `run'
/home/ruben/.rvm/gems/ruby-2.0.0-p247@MyProject/gems/sshkit-1.2.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Tasks: TOP => deploy:migrate

Relevant part of Gemfile:

group :development do                                                                                                                                                                                               
  gem 'capistrano', github: 'capistrano/capistrano'
  gem 'capistrano-rvm', '~> 0.1.0'
  gem 'capistrano-rails', github: 'capistrano/rails'
end

Capfile:

# Load DSL and Setup Up Stages
require 'capistrano/setup'

# Includes default deployment tasks
require 'capistrano/deploy'

require 'capistrano/rvm'

require 'capistrano/rails'

# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }

Could you help me find out what I am doing wrong, please?

EDIT:

My deploy.rb:

# encoding: utf-8
set :user,"myuser"

# options for capistrano -bundle
set :bundle_gemfile, -> { release_path.join('Gemfile') }
set :bundle_dir, -> { shared_path.join('bundle') }
set :bundle_flags, '--deployment --quiet'
set :bundle_without, %w{development test}.join(' ')
set :bundle_binstubs, -> { shared_path.join('bin') }
set :bundle_roles, :all

set :application, 'my_project'
set :repo_url, '[email protected]:myuser/myproject.git'
set :rvm_ruby_version, '2.0.0-p247@MyProject'

ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }

set :scm, :git

set :format, :pretty
set :log_level, :info

set :linked_files, %w{config/database.yml config/application.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle}

set :keep_releases, 5

set :ssh_options, {
  user: "myuser",
  keys: [File.join(ENV["HOME"], ".ssh", "id_rsa")],                                                                                                                                                                 
  forward_agent: true,
  auth_methods: %w(publickey)
} 

namespace :deploy do      

  desc 'Restart application'
  task :restart do        
    on roles(:app), in: :sequence, wait: 5 do
      # Your restart mechanism here, for example:
      execute :touch, release_path.join('tmp/restart.txt')
    end
  end

  after :restart, :clear_cache do
    on roles(:web), in: :groups, limit: 3, wait: 10 do
      # Here we can do anything such as:
      # within release_path do
      #   execute :rake, 'cache:clear'
      # end
    end
  end

  after :finishing, 'deploy:cleanup'
end

My staging.rb file:

set :stage, :staging                                                                                                                                                                                                
ENV["RAILS_ENV"] = "staging"
require File.expand_path('../../environment',  __FILE__)
set :deploy_to, ENV["APPLICATION_DIR"]
# Simple Role Syntax
# ==================
# Supports bulk-adding hosts to roles, the primary
# server in each group is considered to be the first
# unless any hosts have the primary property set.
role :app, [ENV["SERVER_IP"]]
role :web, [ENV["SERVER_IP"]]
role :db,  [ENV["SERVER_IP"]], :primary => true

/usr/bin/env rake assets:precompile fails

I can run the following manually on my server but it fails within cap production deploy:

cd /home/deploy/edawebdesign/releases/20140217194158 && ( RAILS_ENV=production /usr/bin/env rake assets:precompile )

INFO [c095467d] Running /usr/bin/env rake assets:precompile on 162.243.102.243
DEBUG [c095467d] Command: cd /home/deploy/edawebdesign/releases/20140217194158 && ( RAILS_ENV=production /usr/bin/env rake assets:precompile )
DEBUG [c095467d] /usr/bin/env:
DEBUG [c095467d] rake
DEBUG [c095467d] : No such file or directory
DEBUG [c095467d]

Handling rails_relative_url_root

Is there any reason I shouldn't put together a pull request adding an option to set the rails_relative_url_root. I'm overriding the task to do it now (not fun doing that in rake btw.) I was thinking about just setting a variable like this would do it:

In your file, do this:

set(:rails_relative_url_root, '/app_name')

Let the plugin do this:

 namespace :assets do
    task :precompile do
      on roles(fetch(:assets_roles)) do
        within release_path do
          with rails_env: fetch(:rails_env), rails_relative_url_root: fetch(:rails_relative_url_root): do
            execute :rake, "assets:precompile"
          end
        end
      end
    end

I don't believe having and empty param will do anything harmful.

Error on asset_manifest_backup

Commit bfd01c9 removed the .json suffix from the assets_manifest_backup. This produces an error when deploying on my Ubuntu environment. Suggest changing assets_manifest_backup to assets_manifest.backup

DEBUG [7813d7de] Command: cd /home/deployer/discourse-production/releases/20131115183147 && ( RAILS_ENV=production cp /home/deployer/discourse-production/releases/20131115183147/public/assets/manifest* /home/deployer/discourse-production/releases/20131115183147/assets_manifest_backup )
DEBUG [7813d7de] cp:
DEBUG [7813d7de] target `/home/deployer/discourse-production/releases/20131115183147/assets_manifest_backup' is not a directory

New gem?

Hi there :) Is there any possibility of releasing a new gem version? The conditional migrations feature sounds great for our multi-tenant app. Saves a lot of time.

Roles filter for migration task?

For example if I have one server with two roles:

server 'example.com', user: 'example', roles: %w{app db}, primary: true

How do I deploy without running migration? The following won't work:

cap production deploy ROLES=app

The deploy:migrate task is triggered, regardless of the roles filter.

Looking at capistrano-rails's code:

  desc 'Runs rake db:migrate if migrations are set'
  task :migrate => [:set_rails_env] do
    on primary fetch(:migration_role) do # <= here
      ...

It seems that the migration task uses primary(), which doesn't invoke roles filtering.

So:

  • How do I deploy without running migration?
  • Can I do it using roles filtering? (which doesn't seem possible seeing from capistrano-rails's code, if I'm understanding it correctly?)

Any help is appreciated, thanks!

Bundle not found on assets:precompile and db:migrate

Just trying to upgrade to capistrano 3, I am using capistrano-rails together with capistrano-rvm and I have bash: bundle: command not found problem on assets:precompile task.

Running ~/.rvm/bin/rvm ruby-1.9.3-p484@xbox do bundle --gemfile /home/deployer/deploy/xbox/releases/20140105171910/Gemfile --path /home/deployer/deploy/xbox/shared/bundle --deployment --quiet --binstubs /home/deployer/deploy/xbox/shared/bin --without development test on vienna.baijii.com
DEBUG [2b5cc856] Command: cd /home/deployer/deploy/xbox/releases/20140105171910 && ~/.rvm/bin/rvm ruby-1.9.3-p484@xbox do bundle --gemfile /home/deployer/deploy/xbox/releases/20140105171910/Gemfile --path /home/deployer/deploy/xbox/shared/bundle --deployment --quiet --binstubs /home/deployer/deploy/xbox/shared/bin --without development test
 INFO [2b5cc856] Finished in 2.161 seconds with exit status 0 (successful).
DEBUG [b70b2985] Running if test ! -d /home/deployer/deploy/xbox/releases/20140105171910; then echo "Directory does not exist '/home/deployer/deploy/xbox/releases/20140105171910'" 1>&2; false; fi on vienna.baijii.com
DEBUG [b70b2985] Command: if test ! -d /home/deployer/deploy/xbox/releases/20140105171910; then echo "Directory does not exist '/home/deployer/deploy/xbox/releases/20140105171910'" 1>&2; false; fi
DEBUG [b70b2985] Finished in 0.251 seconds with exit status 0 (successful).
 INFO [338df889] Running bundle exec rake db:migrate on vienna.baijii.com
DEBUG [338df889] Command: cd /home/deployer/deploy/xbox/releases/20140105171910 && ( RAILS_ENV=production bundle exec rake db:migrate )
DEBUG [338df889]    bash: bundle: command not found

The following is my Capfile:

require "capistrano/setup"
require "capistrano/deploy"

require "capistrano/bundler"
require "capistrano/rvm"
require "capistrano/rails/migrations"

# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }

deploy.rb:

set :pty, true

set :application, "xbox"
set :deploy_to, "/home/deployer/deploy/#{fetch(:application)}"
set :keep_releases, 5

set :rvm_type, :user
set :rvm_ruby_version, 'ruby-1.9.3-p484@xbox'

set :application, 'xbox'
set :repo_url, '[email protected]:larryzhao/xbox.git'
set :deploy_via, :remote_cache
set :scm_username, "larryzhao"
set :scm, :git
set :scm_verbose, "true"

set :user, 'deployer'
set :runner, 'deployer'

set :format, :pretty

set :ssh_options, {
  forward_agent: true
}

set :unicorn_config, File.join(releases_path, 'config', 'unicorn.rb')
set :unicorn_pid, File.join(releases_path, 'tmp', 'pids', 'unicorn.rb')

namespace :deploy do

  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      run "if [ -f #{fetch(:unicorn_pid)} ]; then kill -s USR2 `cat #{fetch(:unicorn_pid)}`; fi"
    end
  end

  task :start do
    on roles(:app), in: :sequence, wait: 5 do
      run "cd #{current_path} && RAILS_ENV=production bundle exec unicorn_rails -c #{fetch(:unicorn_config)} -D"
    end
  end

  task :stop do
    on roles(:app), in: :sequence, wait: 5 do
      run "if [ -f #{fetch(:unicorn_pid)} ]; then kill -QUIT `cat #{fetch(:unicorn_pid)}`; fi"
    end
  end

  after :restart, :clear_cache do
    on roles(:web), in: :groups, limit: 3, wait: 10 do
      # Here we can do anything such as:
      # within release_path do
      #   execute :rake, 'cache:clear'
      # end
    end
  end

  after :finishing, 'deploy:cleanup'
end

I passed cap deploy:check and cap rvm:check, Where have I done wrong here?

Thank you very much.

cap production deploy just stupidly failed.

When cap production deploy

DEBUG [0f55e18f] Command: ( GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/blog/git-ssh.sh /usr/bin/env git ls-remote --heads git@host:/var/git/blog )
DEBUG [0f55e18f]    Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).

"rake db:migrate" gives "fe_sendauth: no password supplied" error

I am getting this error while running Capistrano command when it tries to run "rake db:migrate"

INFO[c03035dd] Running ~/.rvm/bin/rvm default do bundle exec rake db:migrate on 128.199.211.80
DEBUG[c03035dd] Command: cd /home/deploy/my_app/releases/20140723173643 && ( RAILS_ENV=production ~/.rvm/bin/rvm default do bundle exec rake db:migrate )
DEBUG[c03035dd]   rake aborted!
DEBUG[c03035dd]   PG::ConnectionBad: fe_sendauth: no password supplied
DEBUG[c03035dd]   /home/deploy/my_app/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:881:in `initialize'
DEBUG[c03035dd]   /home/deploy/my_app/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:881:in `new'
DEBUG[c03035dd]   /home/deploy/my_app/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:881:in `connect'
DEBUG[c03035dd]   /home/deploy/my_app/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:568:in `initialize'
DEBUG[c03035dd]   /home/deploy/my_app/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
DEBUG[c03035dd]   /home/deploy/my_app/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
DEBUG[c03035dd]   /home/deploy/my_app/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:435:in `new_connection'
DEBUG[c03035dd]   /home/deploy/my_app/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:445:in `checkout_new_connection'
DEBUG[c03035dd]   /home/deploy/my_app/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `acquire_connection'
DEBUG[c03035dd]   /home/deploy/my_app/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:351:in `block in checkout'
DEBUG[c03035dd]   /home/deploy/my_app/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:350:in `checkout'
DEBUG[c03035dd]   /home/deploy/my_app/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
DEBUG[c03035dd]   /home/deploy/my_app/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
DEBUG[c03035dd]   /home/deploy/my_app/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:541:in `retrieve_connection'
DEBUG[c03035dd]   /home/deploy/my_app/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
DEBUG[c03035dd]   /home/deploy/my_app/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_handling.rb:87:in `connection'
DEBUG[c03035dd]   /home/deploy/my_app/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:910:in `initialize'
DEBUG[c03035dd]   /home/deploy/my_app/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:807:in `new'
DEBUG[c03035dd]   /home/deploy/my_app/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:807:in `up'
DEBUG[c03035dd]   /home/deploy/my_app/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:785:in `migrate'
DEBUG[c03035dd]   /home/deploy/my_app/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
DEBUG[c03035dd]   Tasks: TOP => db:migrate
DEBUG[c03035dd]   (See full trace by running task with --trace)

RAILS_ENV not prefix when run rake db:migrate

I'm afraid I've got an issue with migrate with Cap 3.1

set :rails_env, 'test'
set :migrate_env, 'test'

run deploy

cap test deploy

When i change the db from SQLite3 to MySQL, i got this error:

[ca4b1ad3] Running `RBENV_ROOT=~/.rbenv RBENV_VERSION=2.1.1 ~/.rbenv/bin/rbenv exec bundle exec rake db:migrate` on xxxxx
cap aborted!
SSHKit::Command::Failed: rake stdout: Nothing written
rake stderr: Nothing written

I try to run this line under release path on server

$ RBENV_ROOT=~/.rbenv RBENV_VERSION=2.1.1 ~/.rbenv/bin/rbenv exec bundle exec rake db:migrate

then get the error

rake aborted!
ActiveRecord::NoDatabaseError: Unknown database 'highlander_dev'Run `$ bin/rake db:create db:migrate` to create your database
/home/ares/apps/highlander_test/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.0.rc2/lib/active_record/connection_adapters/mysql2_adapter.rb:23:in `rescue in mysql2_connection'

Seems it caused by not set the prefix RAILS_ENV=test and not create db first? is it by design, or somethings wrong with my config?

UPDATE:

I run these commands below and successed

RAILS_ENV=test RBENV_ROOT=~/.rbenv RBENV_VERSION=2.1.1 ~/.rbenv/bin/rbenv exec bundle exec rake db:create

RAILS_ENV=test RBENV_ROOT=~/.rbenv RBENV_VERSION=2.1.1 ~/.rbenv/bin/rbenv exec bundle exec rake db:migrate

public/assets not symlinked if :linked_dirs set by deploy.rb

#30 changed the point in capistrano's execution where :linked_dirs is set to a value that includes public/assets. It is now set in the load:defaults task, which lib/capistrano/setup.rb invokes before loading deploy.rb. So if deploy.rb contains a line saying

set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}

as per the deploy.rb template, it will overwrite the system's definition and :linked_dirs will not include public/assets. This seems like a regression compared to previous behaviour.

Can't rewrite precompile tasks

Hi, I'm trying to rewrite the asset precompile task like this...
The idea of re-write the task is because if there aren't any changes of assets you haven't precompile. So... (the file is required because i use other task in the same file and it works)

Some idea?

A hug

# in lib\capistrano\tasks\assets.cap
namespace :deploy do
  namespace :assets do
    desc '[Assets] Precompile'
      task :precompile do
        on roles(fetch(:assets_roles)) do
          within release_path do
            with rails_env: fetch(:rails_env) do
              from = source.next_revision(current_revision)
              assets_dir =  'vendor/assets/ app/assets/ lib/assets'
              asset_diff = `#{source.local.log(from)} #{assets_dirs} | wc -l`.to_i

              if asset_diff > 0
                info 'Precompiling...'
                execute :rake, asset_env, 'assets:precompile'
              else
                info 'Nothing to precompile'
                execute "mkdir -p #{latest_release}/tmp/cache"
              end
            end
          end
        end
      end
    end
  end
end

assets:precompile freezes after 10 minutes

I have a problem with assets:precompile. It freezes after 10 minutes of precompiling assets. Process ends but it still waits for something and no response given.

INFO [2fc05e34] Running ~/.rvm/bin/rvm 2.0.0-p247@apptamers do bundle exec rake assets:precompile on x12s2.staging.apptamers.com
DEBUG [2fc05e34] Command: cd /home/webservice/project/20140129075713 && ( RAILS_ENV=production ~/.rvm/bin/rvm 2.0.0-p247@apptamers do bundle exec rake assets:precompile )
DEBUG [2fc05e34]    /home/webservice/.rvm/rubies/ruby-2.0.0-p247/bin/ruby /home/webservice/project/shared/bundle/ruby/2.0.0/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets

CPU is 100% usage but it's normal when I precompile assets on this server.

I have set up ssh_config entries to make sure that it's not a ssh problem. So it's not a timeout problem.

$ cat ~/.ssh/config 
Host *
   ServerAliveInterval 15

I wonder if it's not a sshkit problem and maybe someone has the same issue.

capistrano-rails 1.1.0
capistrano       3.0.1
sshkit           1.3.0

When I do CTR+C after 1h, i get:

/home/user/.rvm/gems/ruby-2.0.0-p247@apptamers/gems/sshkit-1.3.0/lib/sshkit/runners/parallel.rb:15:in `join'
/home/user/.rvm/gems/ruby-2.0.0-p247@apptamers/gems/sshkit-1.3.0/lib/sshkit/runners/parallel.rb:15:in `map'
/home/user/.rvm/gems/ruby-2.0.0-p247@apptamers/gems/sshkit-1.3.0/lib/sshkit/runners/parallel.rb:15:in `execute'
/home/user/.rvm/gems/ruby-2.0.0-p247@apptamers/gems/sshkit-1.3.0/lib/sshkit/coordinator.rb:21:in `each'
/home/user/.rvm/gems/ruby-2.0.0-p247@apptamers/gems/sshkit-1.3.0/lib/sshkit/dsl.rb:8:in `on'
/home/user/.rvm/gems/ruby-2.0.0-p247@apptamers/gems/capistrano-rails-1.1.0/lib/capistrano/tasks/assets.rake:60:in `block (3 levels) in <top (required)>'
...

This runners/parallel.rb looks interesting, maybe this is a sshkit runner problem?

Using capistrano-bundler, rake should be prefixed with bundle exec?

Hi,

rake is used without prefix in the assets task. I've seen the other closed issues about it, saying that it shouldn't be prefixed with bundle exec or bin/ directly in the rails plugin.

My question is I was checking the source of the bundler plugin (now called auto. by rails plugin), and I noticed this line:

https://github.com/capistrano/bundler/blob/master/lib/capistrano/tasks/bundler.cap#L50

Shouldn't rake automatically be prefixed by bundle exec by the task :map_bins ? in my case, I still have to overwrite it in my deploy.rb using this line : SSHKit.config.command_map[:rake] = 'bin/rake', but from what I can understand the map_bins task in the bundler plugin does something similar, isn't?

See, rake isn't prefixed without the command_map I manually put in my deploy.rb:

DEBUG [99085d0b] Command: cd /home/deployer/apps/chiro/releases/20131208194347 && ( PATH=$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH RAILS_ENV=staging /usr/bin/env rake db:migrate )

Thank you!

Handling override of 'after' calls

The committers have been pretty clear on how they feel about having sub directories for root of rails apps (See: capistrano/capistrano#615) so I've gone down the path of deleting tasks from the @tasks variable and replacing them with my own which is all works fine until you get to deploy:migrate (a capistrano/rails gem.) I went to do my normal delete and replace and no matter what I did, the capistrano/rails migrate call was used. After hours of digging I figured out that when I delete the task from the @tasks, it does not live there (silently doesn't delete annoyingly enough) since the after call is implemented using the @actions list. The @actions list is a list of procs with the same line as the src location and no other obvious way to identify the proc because of the dsl wrapper.

Is there a way that anyone proposes removing/replacing that proc besides guessing at the index till the right one goes away? I have a polyglot program and don't have the luxury of having rails at the root. I'd propose a patch to support the subdir but after the previous one was closed I think that'd be the wrong direction. Thanks for the help, and a great project.

Assets do not compile with Capistrano 3 (Sprockets::FileOutsidePaths)

I posted this to Rails at first, rails/rails#14742 but it turns out the issue is related to Capistrano 3. The exact same branch deploys just fine with my old Capistrano 2 deploy.rb.

Just to reiterate:

  • Assets are compiling just fine when I launch rake assets:precompile manually. Both in development and production.
  • It works with Capistrano 2

The actual compile command is as follows:

cd /home/rails/apps/milk/releases/20140414063744 && ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.1.1 RAILS_ENV=production RBENV_ROOT=~/.rbenv RBENV_VERSION=2.1.1 ~/.rbenv/bin/rbenv exec bundle exec rake assets:precompile )

It always fails on fsm.css from actionpack

Sprockets::FileOutsidePaths: /home/rails/apps/milk/releases/20140414063744/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.0/lib/action_dispatch/journey/visualizer/fsm.css isn't in paths: /home/rails/apps/milk/releases/20140414063744/app/assets/images, /home/rails/apps/milk/releases/20140414063744/app/assets/javascripts, /home/rails/apps/milk/releases/20140414063744/app/assets/stylesheets, /home/rails/apps/milk/releases/20140414063744/vendor/assets/javascripts, /home/rails/apps/milk/releases/20140414063744/vendor/assets/stylesheets, /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/ckeditor_rails-4.3.4/lib/assets/javascripts, /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/ckeditor_rails-4.3.4/vendor/assets/images, /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/ckeditor_rails-4.3.4/vendor/assets/javascripts, /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/ckeditor_rails-4.3.4/vendor/assets/stylesheets, /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/remotipart-1.2.1/vendor/assets/javascripts, /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/twitter-bootstrap-rails-2.2.8/app/assets/fonts, /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/twitter-bootstrap-rails-2.2.8/app/assets/images, /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/twitter-bootstrap-rails-2.2.8/app/assets/javascripts, /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/twitter-bootstrap-rails-2.2.8/app/assets/stylesheets, /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/twitter-bootstrap-rails-2.2.8/vendor/assets/stylesheets, /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/font-awesome-rails-4.0.3.1/app/assets/fonts, /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/font-awesome-rails-4.0.3.1/app/assets/stylesheets, /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/neat-1.5.1/app/assets/stylesheets, /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/bourbon-3.1.8/app/assets/stylesheets, /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/mousetrap-rails-1.4.6/app/assets/stylesheets, /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/mousetrap-rails-1.4.6/vendor/assets/javascripts, /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/turbolinks-2.2.2/lib/assets/javascripts, /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/jquery-ui-rails-4.2.0/app/assets/images, /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/jquery-ui-rails-4.2.0/app/assets/javascripts, /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/jquery-ui-rails-4.2.0/app/assets/stylesheets, /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/jquery-rails-3.1.0/vendor/assets/javascripts, /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/coffee-rails-4.0.1/lib/assets/javascripts
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.0/lib/sprockets/asset_attributes.rb:49:in `logical_path'
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.0/lib/sprockets/base.rb:268:in `find_asset'
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.0/lib/sprockets/index.rb:61:in `find_asset'
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.0/lib/sprockets/processed_asset.rb:111:in `block in resolve_dependencies'
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.0/lib/sprockets/processed_asset.rb:105:in `each'
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.0/lib/sprockets/processed_asset.rb:105:in `resolve_dependencies'
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.0/lib/sprockets/processed_asset.rb:97:in `build_required_assets'
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.0/lib/sprockets/processed_asset.rb:16:in `initialize'
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.0/lib/sprockets/base.rb:374:in `new'
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.0/lib/sprockets/base.rb:374:in `block in build_asset'
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.0/lib/sprockets/base.rb:395:in `circular_call_protection'
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.0/lib/sprockets/base.rb:373:in `build_asset'
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.0/lib/sprockets/index.rb:94:in `block in build_asset'
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.0/lib/sprockets/caching.rb:58:in `cache_asset'
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.0/lib/sprockets/index.rb:93:in `build_asset'
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.0/lib/sprockets/base.rb:287:in `find_asset'
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.0/lib/sprockets/index.rb:61:in `find_asset'
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.0/lib/sprockets/bundled_asset.rb:16:in `initialize'
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.0/lib/sprockets/base.rb:377:in `new'
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.0/lib/sprockets/base.rb:377:in `build_asset'
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.0/lib/sprockets/index.rb:94:in `block in build_asset'
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.0/lib/sprockets/caching.rb:58:in `cache_asset'
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.0/lib/sprockets/index.rb:93:in `build_asset'
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.0/lib/sprockets/base.rb:287:in `find_asset'
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.0/lib/sprockets/index.rb:61:in `find_asset'
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.0/lib/sprockets/manifest.rb:211:in `block in find_asset'
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.0/lib/sprockets/manifest.rb:257:in `benchmark'
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.0/lib/sprockets/manifest.rb:210:in `find_asset'
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.0/lib/sprockets/manifest.rb:119:in `block in compile'
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.0/lib/sprockets/manifest.rb:118:in `each'
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.0/lib/sprockets/manifest.rb:118:in `compile'
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-rails-2.0.1/lib/sprockets/rails/task.rb:60:in `block (3 levels) in define'
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.0/lib/rake/sprocketstask.rb:146:in `with_logger'
DEBUG [de802fe2]    /home/rails/apps/milk/shared/vendor/bundle/ruby/2.1.0/gems/sprockets-rails-2.0.1/lib/sprockets/rails/task.rb:59:in `block (2 levels) in define'
DEBUG [de802fe2]    Tasks: TOP => assets:precompile
DEBUG [de802fe2]    (See full trace by running task with --trace)

deploy fail when using "require 'capistrano/rails'" on capistrano 3 with rails 4

When requiring 'capistrano/rails' in my deploy.rb, I get this on cap production deploy.

DEBUG [1181fe04] Running /usr/bin/env [ -L /usr/local/www/repos/myapp/releases/20131118105650/public/assets ] on myserver
DEBUG [1181fe04] Command: [ -L /usr/local/www/repos/myapp/releases/20131118105650/public/assets ]
DEBUG [1181fe04] Finished in 0.054 seconds with exit status 1 (failed).
....
cap aborted!
undefined methodto_sym' for nil:NilClass`

Everything else runs successful. When I delete require 'capistrano/rails' it deploys successful in all steps

Full Log: https://gist.github.com/anonymous/65ec19fd4261a2287db2

deploy:assets:precompile not getting environment.

Under config/deploy/production.rb the stage is set as follows:

set :stage, :production

Then I have the following uncommented in the Capfile:

require 'capistrano/bundler'
require 'capistrano/rails/assets'

However, when I run cap production deploy:assets:precompile the task does not pick up that it is the "production" environment. The following command is run:

cd /home/deployer/apps/sample/current && ( RAILS_ENV= /usr/bin/env rake assets:precompile )

As you can see the RAILS_ENV is blank. Is there something I am missing here?

temporally disable rake assets:precompile

Hi, sometimes when I deploy, I know I didn't make any changes to assets(css js or fonts), and I found rake assets:precompile is really time consuming. How do you temporally disable rake assets:precompile?

rake db:migrate is not performing

Gemfile:

group :development do 
  ...
  gem 'capistrano', '~> 3.2.0', require: false
  gem 'capistrano-rails',   '~> 1.1', require: false
  gem 'capistrano-bundler', '~> 1.1', require: false
end

Capfile:

# Load DSL and Setup Up Stages
require 'capistrano/setup'

# Includes default deployment tasks
require 'capistrano/deploy'

require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'

# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }

But when I run cap staging deploy rake db:migrate task is not triggered. Even if I try to cap staging deploy:migrate nothing happens.

Am I missing anything?

Always running deploy:migrate after deploy:updated

Greetings and thanks for your Gem.

I am running into restrictions due to the following line:

`after 'deploy:updated', 'deploy:migrate'

https://github.com/capistrano/rails/blob/master/lib/capistrano/tasks/migrations.rake#L16

I can see how to skip therake db:migrate command from being invoked, by simply not defining a migration_role or db role anywhere in your deploy.rb or related stage files. However, I believe that the deploy:migrate task should not be invoked at all, unless called out explicitly.

It is desirable for me to use before and after hooks on deploy:migrate to put up a maintenance page, for example. With the line after 'deploy:updated', 'deploy:migrate' embedded in the Gem, my hooks will be invoked regardless if rake db:migrate is ever run.

Has anyone else run into this issue using this gem? Is there a standard work-around?

Thanks!

cap compile_assets bombs out not seemingly doing anything

% cap staging deploy:compile_assets --trace
** Invoke staging (first_time)
** Execute staging
** Invoke load:defaults (first_time)
** Execute load:defaults
** Invoke rbenv:validate (first_time)
** Execute rbenv:validate
DEBUG[f5879fab] Running /usr/bin/env [ ! -d ~/.rbenv/versions/2.1.4 ] on server.com
DEBUG[f5879fab] Command: [ ! -d ~/.rbenv/versions/2.1.4 ]
DEBUG[f5879fab] Finished in 0.633 seconds with exit status 1 (failed).
** Invoke rbenv:map_bins (first_time)
** Execute rbenv:map_bins
** Invoke bundler:map_bins (first_time)
** Execute bundler:map_bins
** Invoke deploy:compile_assets (first_time)
** Invoke deploy:set_rails_env (first_time)
** Execute deploy:set_rails_env
** Execute deploy:compile_assets
** Invoke deploy:assets:precompile (first_time)
** Execute deploy:assets:precompile
** Invoke deploy:assets:backup_manifest (first_time)
** Execute deploy:assets:backup_manifest

doesn't seem like it's actually doing anything -- this completes in a few seconds, and nothing appears to happen on the server. not sure where to begin to look at for this... is it rbenv, bundler, rails or cap? :(

The deploy:compile_assets task is not failing, but the assets are missing after deploy.

The task is getting run, even the logs of created assets appear, but they really aren't. When I run the same command, I see during capistrano task, I get the same output, but the assets appear this time.
If I run the capistrano task for a second time in a row, it swallows logs of created assets, just like it would have done it if they were created already.

Deploy cold a Rails app with old migrations

This is more of a comment/concern and some asking for advice/bringing up an enhancement. Before, I was using 2.x series of Capistrano for deployment and I hacked deploy:cold to load schema.rb, rather than use rake db:migrate, cause old migration files referenced some classes in migrations that were not present anymore in the application.

Is there a way that we can check to see if the application wasn't deployed before, and if it was, then run rake db:migrate, and if it wasn't then we run rake db:schema:load instead?

Asset compilation is taking 12+ minutes on remote server!

If I run "rake assets:precompile" on my local machine, it takes about 4 seconds.

During the capistrano deployment (cap staging deploy), the "rake assets:precompile" step consistently takes over 12 minutes! I'm deploying to an Ubuntu 13.10 server that is handling all "roles" (nginx + passenger, postgresql).

Gemfile
gem 'capistrano', '> 3.0'
gem 'capistrano-rails', '
> 1.1'
gem 'capistrano-rbenv', '~> 2.0'

Capfile
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rbenv'
require 'capistrano/rails'
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }

deploy/staging.rb
set :stage, :staging
server 'dev.example.com', user: 'deployer', roles: %w{web app db}
set :branch, 'master'
set :rails_env, 'staging'
set :user, 'deployer'
set :rbenv_type, :system
set :rbenv_ruby, '2.0.0-p353'
set :deploy_to, "/home/#{fetch(:user)}/www/#{fetch(:application)}"

Assets manifest backup fails if manifests folder exists

In lib / capistrano / tasks / assets.rake line 69, the task tries to cp manifest* to the backup file assets_manifest_backup.

This will fail for projects having a manifests folder in app / assets / javascripts (I suppose the same happens if the folder is in stylesheets) with:

Tasks: TOP => deploy:assets:backup_manifest
(See full trace by running task with --trace)
The deploy has failed with an error: #<SSHKit::Runner::ExecuteError: Exception while executing on host xxx.xxx.xxx.xxx: cp exit status: 1
cp stdout: Nothing written
cp stderr: cp: target โ€˜/home/deploy/xxxx/releases/20141114002603/assets_manifest_backupโ€™ is not a directory

assets:precompile failed on rails 4

When I deploy my rails 4 app, I get the following error:

Running bundle exec rake assets:precompile on localhost
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host localhost: rake exit status: 1
rake stdout: Nothing written
rake stderr: Nothing written

What's going wrong?

Thanks!

set rails_env is failing

Hi!

Im using the capistrano/rails gem version 1.1.

Everytime i do a deployment with cap production deploy it will run the assets and migrations against both development and production. This means i have to add all the environments in my database.yml, and everytime i deploy, all migrations are ran.

This are the logs for the assets:

 INFO [c68cfdfb] Running RBENV_ROOT=~/.rbenv RBENV_VERSION=2.0.0-p353
 ~/.rbenv/bin/rbenv exec bundle exec rake assets:precompile on redacted
DEBUG [c68cfdfb] Command: cd /home/deployer/apps/redacted/releases/20131230091654 && ( PATH=/opt/ruby/bin:$PATH RAILS_ENV=production RBENV_ROOT=~/.rbenv RBENV_VERSION=2.0.0-p353
 ~/.rbenv/bin/rbenv exec bundle exec rake assets:precompile )
 INFO [c68cfdfb] Finished in 5.734 seconds with exit status 0 (successful).

This are the logs for the migration:

 INFO [c743fb28] Running RBENV_ROOT=~/.rbenv RBENV_VERSION=2.0.0-p353
 ~/.rbenv/bin/rbenv exec bundle exec rake db:migrate on redacted
DEBUG [c743fb28] Command: cd /home/deployer/apps/redacted/releases/20131230091654 && ( PATH=/opt/ruby/bin:$PATH RAILS_ENV=production RBENV_ROOT=~/.rbenv RBENV_VERSION=2.0.0-p353
 ~/.rbenv/bin/rbenv exec bundle exec rake db:migrate )

Things i've tried:

  1. adding config.assets.initialize_on_precompile = false to my config/application.rb
  2. Requiring capistrano/rails in the Capfile, instead of the migration and assets
  3. adding set :rails_env, 'production' and set :stage, :production to my config/deploy.rb
  4. uncomment fetch(:default_env).merge!(rails_env: :production) in deploy/production.rb

Hope this is enough information ๐Ÿ˜„

bundle command not found, no rvm hook

I use capistrano 3.0.1, bundler, rvm and want to precompile assets. Everything is set ok but i can't precompile assets because of missing rvm hook.

INFO [2d201a4a] Running bundle exec rake assets:precompile on x12.staging.apptamers.com
DEBUG [2d201a4a] Command: cd /opt/apptamers/releases/20140102093457 && ( RAILS_ENV=production bundle exec rake assets:precompile )
DEBUG [2d201a4a]    bash: bundle: command not found

Now, it's:

RAILS_ENV=production bundle exec rake assets:precompile

But it should be:

~/.rvm/bin/rvm 2.0.0-p247@apptamers RAILS_ENV=production bundle exec rake assets:precompile

For examples rvm hook is already set when bundle runs.

cd /opt/apptamers/20140102093457 && (   RAILS_ENV=production ~/.rvm/bin/rvm 2.0.0-p247@apptamers do bundle --gemfile /opt/apptamers/releases/20140102093457/Gemfile --path /opt/apptamers/shared/bundle --deployment --quiet --binstubs /opt/apptamers/shared/bin --without development test )

support a task for db:seed

Hi,

I would like to see the following task as part of the gem

task :seed do
    on primary fetch(:migration_role) do
      within release_path do
        with rails_env: fetch(:rails_env)  do
          execute :rake, 'db:seed'
        end
      end
    end
  end

It would allow me to seed databases out of the box via capistrano

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.