5

I'm an absolute noob with Capistrano (v 3.2.1), so please forgive my, err, uselessness. I'm deploying a PHP app and wish to run composer install before the deploy:symlink:release task (only when not running a rollback)

I'm having trouble accessing the newly created release directory as I need it to be able to cd into it and run composer (and run a few other items, too). I currently have;

namespace :deploy do

    namespace :symlink do

        desc 'Run composer'
        task :runcomposer do
            on roles :all do

                execute "cd '#{current_release}' && composer install"
                execute "cd '#{current_release}' && ln -s /sites/shared/index.php index.php"
            end
        end

        before :release, :runcomposer

    end

end

The {current_release} variable doesn't seem to exist at this point (which is weird as the directory where the git pull is run has definitely been created within the /releases/ directory (with the appropriate timestamp) but I get 'undefined local variable or method "current_release"'

Is there a way I can determine this new release directory before the 'current' symlink is pointed at it? Thank you so much in advance.

RichardTape
  • 20,865
  • 5
  • 24
  • 29

2 Answers2

2

Use composer extension

# Capfile
require 'capistrano/composer'

And by default there will be two tasks planned

before 'deploy:updated', 'composer:install'
before 'deploy:reverted', 'composer:install'

Removing one of the default tasks

Rake::Task['deploy:reverted'].prerequisites.delete('composer:install')

Read more on the official doc page.

Jekis
  • 4,274
  • 2
  • 36
  • 42
0

I had left this as a comment to my question, but at the moment, it's the only answer I can find, so I'm promoting it to an answer;

OK, so I've determined a possible way to do it, but it seems horrible. Even for an absolute beginner like me:

newreleasedir = capture('ls -t /sites/releases | head -1')

then

execute "cd /sites/releases/#{newreleasedir} && composer install"

Someone please tell me that's horrible and how I should be doing it :)

RichardTape
  • 20,865
  • 5
  • 24
  • 29