Capistrano and Carrierwave

2019-04-12 21:01发布

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!

4条回答
祖国的老花朵
2楼-- · 2019-04-12 21:13

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!

查看更多
贪生不怕死
3楼-- · 2019-04-12 21:34

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.

查看更多
▲ chillily
4楼-- · 2019-04-12 21:37

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

查看更多
劫难
5楼-- · 2019-04-12 21:40

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
查看更多
登录 后发表回答