Rad80
Rad80

Reputation: 833

How do I get the path for the release being deployed in Capistrano 3?

During my deploy process, I need to create a symbolic link to the correct version of a configuration file, which depends on the environment. While I expected that to be trivial, I could not find anywhere how to get the current path.

I need to operate on the release directory before the current symbolic link is switched to it. release_path yields the path to the current directory, rather than something like releases/20170131090326/.

namespace :deploy do
    desc 'Link daemon configuration file'
    task :link_daemon_config do
        on roles(:batch) do
            execute "ln -s #{release_path}/app/config/daemon_prod.config #{release_path}/app/config/daemon.config"
        end
    end
    after :updated, :link_daemon_config
end

I do have ideas for a workaround; the question is just about how could I refer to the current directory and where can I find information like this in the future.

Thank you

Upvotes: 1

Views: 807

Answers (1)

Web Assembler
Web Assembler

Reputation: 31

I managed to solve this in a similar use-case. Make sure keep-releases is set to a number higher than 2. e.g set :keep_releases, 3

Try this:

namespace :deploy do
    desc 'Link daemon configuration file'
    task :link_daemon_config do
        on roles(:batch) do
            last_release = capture(:ls, "-xt", releases_path).split[1]
            last_release_path = releases_path.join(last_release)
            execute "ln -s #{last_release_path}/app/config/daemon_prod.config #{release_path}/app/config/daemon.config"
        end
    end
    after :updated, :link_daemon_config
end

Useful links: https://github.com/capistrano/capistrano/blob/master/lib/capistrano/tasks/deploy.rake#L184

Similar topic: https://stackoverflow.com/a/26267220/15500541

Upvotes: 1

Related Questions