capistrano / composer

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

PHP binary with arguments #46

Open scuben opened 8 years ago

scuben commented 8 years ago

On the Task composer:install_executable which executes

task :install_executable do
    on release_roles(fetch(:composer_roles)) do
      within shared_path do
        unless test "[", "-e", "composer.phar", "]"
          composer_version = fetch(:composer_version, nil)
          composer_version_option = composer_version ? "-- --version=#{composer_version}" : ""
          execute :curl, "-s", fetch(:composer_download_url), "|", :php, composer_version_option
        end
      end
    end
  end

I need to change the php binary including its arguments.

The default commend which is being executed looks like this: curl -s https://getcomposer.org/installer | php

What I need is: curl -s https://getcomposer.org/installer | php56 -d allow_url_fopen=On

What I already know does not work:

The only viable solution I see is the change the lib code :php to fetch(:php) (or similar) to be able to define the php binary (with its argument) with set :php, 'php -d allow_url_fopen=On'. Is this true or am I missing something?

guillaumelecerf commented 7 years ago

Can't use the command_map because only the first argument of a execute statement gets resolved with the command_map

Why?

SSHKit.config.command_map[:php] = "php -d allow_url_fopen=Off" should work.

require 'sshkit'
require 'sshkit/dsl'
include SSHKit::DSL

SSHKit.config.command_map[:php] = "php"

on 'localhost' do
  puts capture :php, "-i | grep allow_url_fopen"

  SSHKit.config.command_map[:php] = "php -d allow_url_fopen=Off"

  puts capture :php, "-i | grep allow_url_fopen"
end

outputs:

allow_url_fopen => On => On
allow_url_fopen => Off => Off
fuegas commented 7 years ago

@guillaumelecerf this does not reproduce the issue stated by @scuben. The issue is that the first argument is resolved with the command_map. The code to install composer states:

execute :curl, "-s", fetch(:composer_download_url), "|", :php, composer_version_option

So only :curl gets mapped and :php does not, so overriding :php in the command_map has zero effect on the execute that pipes it to :php.

As example:

require 'sshkit'
require 'sshkit/dsl'
include SSHKit::DSL

SSHKit.config.command_map[:php] = "php -d allow_url_fopen=Off"

on 'localhost' do
  puts capture :php, '-i | grep allow_url_fopen'
  puts capture :echo, '""', '|', :php, '-i | grep allow_url_fopen'
end

outputs:

allow_url_fopen => Off => Off
allow_url_fopen => On => On