4

I'm trying to "translate" the Capistrano recipe to deploy dynamic_sitemaps to work with Capistrano 3.

The snippet suggested in the readme looks like this:

after "deploy:update_code", "sitemaps:create_symlink"

namespace :sitemaps do
  task :create_symlink, roles: :app do
    run "mkdir -p #{shared_path}/sitemaps"
    run "rm -rf #{release_path}/public/sitemaps"
    run "ln -s #{shared_path}/sitemaps #{release_path}/public/sitemaps"
  end
end

But this doesn't work with Capistrano 3. I pasted this code into config/deploy.rb and the first error I got was: Don't know how to build task 'sitemaps:create_symlink'`.

I read somewhere that in Capistrano 3 the namespaces have to be defined before the calls so I reversed the order of the blocks, defining the namespace first and having the after call last. I got NoMethodError: undefined method `map' for :roles:Symbol`.

So I rewrote the namespace block to:

namespace :sitemaps do
  task :create_symlink do 
    on roles(:web) do
      run "mkdir -p #{shared_path}/sitemaps"
      run "rm -rf #{release_path}/public/sitemaps"
      run "ln -s #{shared_path}/sitemaps #{release_path}/public/sitemaps"
    end
  end
end

And now I'm getting Don't know how to build task 'deploy:update_code' and I'm at loss.

janosrusiczki
  • 1,920
  • 2
  • 20
  • 41

1 Answers1

0

While I couldn't solve precisely the issue I posted above, the solution is actually very simple. If using Capistrano 3 just add public/sitemaps to your :linked_dirs setting as such:

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

This will create a symbolic link between #{release_path}/public/sitemaps and #{shared_path}/public/sitemap creating the latter if needed.

janosrusiczki
  • 1,920
  • 2
  • 20
  • 41