Skip to content

Commit

Permalink
Merge pull request #91 from mattclegg/issue-90
Browse files Browse the repository at this point in the history
Change logic to only download if composer doesn't exist
  • Loading branch information
tPl0ch committed Feb 24, 2016
2 parents 463bc76 + ced3556 commit e0b07d0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
language: ruby
before_install:
- gem update bundler
rvm:
- 2.1.4
- 2.0.0
Expand Down Expand Up @@ -40,3 +42,4 @@ branches:
only:
- master
- /^release.*$/
- /^fix-.*$/
34 changes: 18 additions & 16 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
# download composer
case $download_method {
'curl': {
$download_command = "curl -sS https://getcomposer.org/installer | ${composer::php_bin}"
$download_command = "curl -sS https://getcomposer.org/installer | ${composer::php_bin} -- --install-dir=${tmp_path} --filename=${composer_file}"
$download_require = $suhosin_enabled ? {
false => [ Package['curl', $php_package] ],
default => [
Expand Down Expand Up @@ -136,21 +136,23 @@
}
}

if defined(File["${target_dir}/${composer_file}"]) == false {
exec { 'download_composer':
command => $download_command,
cwd => $tmp_path,
require => $download_require,
creates => "${tmp_path}/composer.phar",
logoutput => $logoutput,
}
# move file to target_dir
file { "${target_dir}/${composer_file}":
ensure => present,
source => "${tmp_path}/composer.phar",
require => [ Exec['download_composer'], File[$target_dir] ],
mode => '0755',
}
# download composer if target_file doesn't exist
exec { "download_composer":
command => $download_command,
cwd => $tmp_path,
require => $download_require,
creates => "${tmp_path}/${composer_file}",
logoutput => $logoutput,
onlyif => "test ! -f ${target_dir}/${composer_file}",
path => [ '/bin', '/usr/bin' ],
notify => Exec["move_composer_${target_dir}"],
environment => ["COMPOSER_HOME=${composer::composer_home}"]
}

# move downloaded file to target_dir
exec { "move_composer_${target_dir}":
command => "mv ${tmp_path}/${composer_file} ${target_dir}/${composer_file}; chmod 0755 ${target_dir}/${composer_file}",
refreshonly => true,
}

if $auto_update == true {
Expand Down
21 changes: 10 additions & 11 deletions spec/classes/composer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

shared_examples 'a composer module' do |params, ctx|
p = {
:php_package => 'php-cli',
:php_bin => 'php',
:curl_package => 'curl',
:target_dir => '/usr/local/bin',
:composer_file => 'composer',
:suhosin_enabled => true,
:tmp_path => '/tmp',
:php_package => 'php-cli',
:curl_package => 'curl',
:php_bin => 'php',
:suhosin_enabled => true
}

p.merge!(params) if params
Expand All @@ -31,9 +32,9 @@

it {
should contain_exec('download_composer').with({
:command => "curl -sS https://getcomposer.org/installer | #{p[:php_bin]}",
:cwd => '/tmp',
:creates => '/tmp/composer.phar',
:command => "curl -sS https://getcomposer.org/installer | #{p[:php_bin]} -- --install-dir=#{p[:tmp_path]} --filename=#{p[:composer_file]}",
:cwd => "#{p[:tmp_path]}",
:creates => "#{p[:tmp_path]}/#{p[:composer_file]}",
:logoutput => false,
})
}
Expand All @@ -43,10 +44,8 @@
it { should contain_file(p[:target_dir]).with_ensure('directory') }

it {
should contain_file(composer_path).with({
:source => 'present',
:source => '/tmp/composer.phar',
:mode => '0755',
should contain_exec("move_composer_#{p[:target_dir]}").with({
:command => "mv #{p[:tmp_path]}/#{p[:composer_file]} #{p[:target_dir]}/#{p[:composer_file]}; chmod 0755 #{p[:target_dir]}/#{p[:composer_file]}"
})
}

Expand Down

0 comments on commit e0b07d0

Please sign in to comment.