Capistrano and Carrierwave

2019-04-12 21:32发布

问题:

I'm deploying a Ruby on Rails and NodeJS application using Capistrano. The uploads folder gets removed on every deploy.

This popped up on several places but it doesn't seem to work:

# Keep File Uploads
  task :symlink_uploads do
    run "ln -nfs #{shared_path}/rails/uploads  #{release_path}/rails/public/uploads"
  end

  after 'deploy:update_code', 'deploy:symlink_uploads'

the repo:

  repo:
    /node
    /rails

Thanks!

回答1:

Make sure you remove the existing public/uploads folder, passing -f to ln doesn't cover removing target directories (or at least hasn't done so portably for me)

My symlink directories tasks normally look like

task :symlink_uploads do
  run "rm -rf #{release_path}/rails/public/uploads} && ln -nfs #{shared_path}/rails/uploads  #{release_path}/rails/public/uploads"
end

Obviously make sure there is nothing in the checked in version of public/uploads that you need!



回答2:

There is another solution to this problem. You can add your uploads dir to Capistrano's shared_children and it will do all the magic automatically. You can find more details in this answer: https://stackoverflow.com/a/9710542/835935



回答3:

Did you try

after 'deploy:update_code', ':symlink_uploads'

Your :symlink_uploads task is not in a namespace, so rather do the above or put it in a namespace

namespace :deploy do
  task :symlink_uploads do
    # ...
  end
end


回答4:

I have similar problem with uploaded file with my RoR app. This is my capistrano tasks:

...
task :link_public_folder, :roles => [:app, :web] do
    run "mv -u #{release_path}/public/* #{shared_path}/public"
    run "rm -rf #{release_path}/public"
    run "ln -s #{shared_path}/public #{release_path}/public"
  end
  after "deploy:update", "deploy:link_public_folder"

  task :setup_config, :roles => :app do
    sudo "ln -nfs #{current_path}/config/apache.conf /etc/apache2/sites-available/#{application}"
    run "mkdir -p #{shared_path}/config"
    run "mkdir -p #{shared_path}/public"
    put File.read("config/database.yml"), "#{shared_path}/config/database.yml"
    puts "Now edit the config files in #{shared_path}."
  end
  after "deploy:setup", "deploy:setup_config"
...

Maybe help you

Edit: I use Carrierwave too.