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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 43 additions & 8 deletions lib/capistrano/tasks/composer.rake
Original file line number Diff line number Diff line change
@@ -1,20 +1,44 @@
namespace :composer do

desc <<-DESC
Check wether composer is installed globally or not.
This test should be executed everytime.
DESC
task :check do
on release_roles(fetch(:composer_roles)) do
info "Testing if composer is installed globally"
if test "[[ -n `which composer` ]]"
invoke 'composer:install_executable'
end
end
end

desc <<-DESC
Installs composer.phar to the shared directory
In order to use the .phar file, the composer command needs to be mapped:
SSHKit.config.command_map[:composer] = "\#{shared_path.join("composer.phar")}"
Installs composer.phar to the composer_path directory
The advantage of using a variable is that we have better control on the path used in SSHKit.

In order to use the .phar file, the composer command is mapped using the composer_path variable:
SSHKit.config.command_map[:composer] = "php \#{fetch(composer_path)}/composer.phar"

This is best used after deploy:starting:
namespace :deploy do
after :starting, 'composer:install_executable'
end
DESC
task :install_executable do
on release_roles(fetch(:composer_roles)) do
within shared_path do

within fetch(:composer_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
set :should_install_composer, ask('Do you want to install composer locally ?', 'y|n')
unless fetch(:should_install_composer) != 'y'
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
else
error("You need composer in order to continue")
abort()
end
end
end
end
Expand All @@ -23,6 +47,13 @@ namespace :composer do
task :run, :command do |t, args|
args.with_defaults(:command => :list)
on release_roles(fetch(:composer_roles)) do
if fetch(:composer_use_global)
execute :echo, "Using globally installed composer at ", `which composer`
else
set :composer_exec_path, "php #{fetch(:composer_path)}/composer.phar"
execute :echo, fetch(:composer_exec_path)
SSHKit.config.command_map[:composer] = fetch(:composer_exec_path)
end
within fetch(:composer_working_dir) do
execute :composer, args[:command], *args.extras
end
Expand Down Expand Up @@ -57,6 +88,7 @@ namespace :composer do
invoke "composer:run", :selfupdate, fetch(:composer_version, '')
end

before 'composer:run', 'composer:check'
before 'deploy:updated', 'composer:install'
before 'deploy:reverted', 'composer:install'
end
Expand All @@ -65,8 +97,11 @@ namespace :load do
task :defaults do
set :composer_install_flags, '--no-dev --prefer-dist --no-interaction --quiet --optimize-autoloader'
set :composer_roles, :all
set :composer_working_dir, -> { fetch(:release_path) }
set :composer_dump_autoload_flags, '--optimize'
set :composer_download_url, "https://getcomposer.org/installer"
# 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