capistrano / composer

Capistrano extension for Composer tasks
MIT License
183 stars 48 forks source link

Run multiple time the hook #54

Closed flohw closed 6 years ago

flohw commented 6 years ago

Hello there,

I hope the project is not as abandoned as it looks like. I have a project with multiple subproject (two in this case) and I want to run composer install inside this two directories. Is there a way to do so ? I can't find a solution for now. I can run composer install in one of the two directory but not in the second. Event if I create another custom task wich reset composer_ variables then invoke composer:run, :install (I think the implementation is good, see below) Thanks.

Here is a representation of my architecture:

my_root_project
|__ symfony_projecet_1 # I want to run composer install here
|   |__ composer.lock
|   |__ composer.json
|__ symfony_project_2 # I want to run composer install here too
    |__ composer.lock
    |__ composer.json

Implementation of my custom_task:

namespace :portal do

  task :composer do
    on roles fetch(:composer_roles) do
      # Before this set, composer_working_dir is defined like this in the global configuration:
      # set :composer_working_dir, -> { File.join(fetch(:release_path), 'server') }
      set :composer_working_dir, -> { File.join(fetch(:release_path), 'portal') }
      within fetch(:composer_target_path, release_path) do
        invoke 'composer:run', :install, fetch(:composer_install_flags)
      end
    end
  end
end
will-in-wi commented 6 years ago

This gem (along with capistrano-bundler) makes the assumption that you have one composer.json file at the root for the entire project, since this is by far the most common case.

You are on the right track, although I'd probably dump the capistrano-composer gem for your case entirely, and just manually call composer. You have a specialized case that is beyond the scope of this Gem.

If you wanted to rework your project to fit these assumptions, you could split your project into two repos and deploy them separately. However, I'm sure you have a good reason for doing it the way you are.

flohw commented 6 years ago

Thank you for your response. It's not possible to split the project into multiple parts as these parts are dependent.

I switched to deployer as it is written in PHP, I am more confortable to explore and understand the code. The behavior is the same as capistrano-composer but I can rewrite the hooks and run composer as many time as I want.

If someone find this issue, I think we can do the same with capistrano but as I am not a ruby developer, I can't provide any example or track to do the same.