Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override composer task parameters from your environment (stage|production) config file #41

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

t0k4rt
Copy link

@t0k4rt t0k4rt commented Sep 28, 2015

Hi, I ran into the same problems as described here #39 #22
In the composer task, shared_path and release_path are not evaluated accordingly to the environment.
The bug is simple to reproduce:
When you override deploy_to path in your stage|production ruby file with a path different from your deploy.rb file, the composer task will run with the deploy.rb deploy_topath so that both release and shared path will be wrong when launching composer tasks.
The workaround I found is to load default paths using lambdas:

namespace :load do
  task :defaults do
    ...
    # use ruby global variables in a lambda
    set :composer_working_dir, -> { "#{release_path}" }
    set :composer_path, -> { "#{shared_path}" }
    set :composer_use_global, false
  end
end

I added the variable composer_path so that I can override the SSHKit command_map with a lambda (since SSHkit.config.command_map = ->{ fetch(:myvar) } doesn't seem to work).
Also, instead of overriding the command in the deploy.rb, I override the variable directly in the rake tasks so that the variable is set accordingly to the environment we are deploying in.

With these changes, you can do whatever you want:

  • override the deploy_to path
  • override the composer_path
  • override the composer_working_dir
    From your stage or deploy.rb files

I also added other stuffs:

  • I added a check which checks whether composer is installed globally or not
  • In case composer is not installed, I trigger composer:install_executable task (with a ask)
  • This check is triggered whenever a composer task is triggered
    (before 'composer:run', 'composer:check')
  • I added a flag which indicate that we prefer to use a globally installed composer instead of a locally installed version of composer

What do you thing about this ?

@t0k4rt
Copy link
Author

t0k4rt commented Nov 6, 2015

Any feedback ?

@swalkinshaw
Copy link
Member

This PR caught me while I was away on vacation so it got lost in the shuffle. Despite this being a limitation of Capistrano, I'd be open to potentially including a solution for it in this extension.

But I'd prefer if the code changes could be limited to only addressing that problem for one. There seems to be other changes going on in this PR. Can it be reduced to the minimum required to fix the original issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants