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

add options for composer and php binaries #48

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
32 changes: 13 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Capistrano's default deploy, or can be run in isolation with:
$ cap production composer:install
```

By default it is assumed that you have the composer executable installed and in your
By default it is assumed that you have the Composer executable installed and in your
`$PATH` on all target hosts.

### Configuration
Expand All @@ -54,39 +54,33 @@ set :composer_install_flags, '--no-dev --no-interaction --quiet --optimize-autol
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"
set :composer_version, '1.0.0-alpha8' #(default: not set)
set :composer_download_url, 'https://getcomposer.org/installer'
set :composer_version, '1.0.0-alpha8' # (default: not set)
set :composer_bin, 'bin/composer.phar' # (default: not set)
set :composer_php, 'php5' # (default: not set)
```

### Installing composer as part of a deployment
### Installing Composer as part of a deployment

Add the following to `deploy.rb` to manage the installation of composer during
deployment (composer.phar is install in the shared path).
To install Composer as part of the deployment, set `:composer_bin` to `:local`.
This ensures installation of a local `composer.phar` in the shared path.

```ruby
SSHKit.config.command_map[:composer] = "php #{shared_path.join("composer.phar")}"

namespace :deploy do
after :starting, 'composer:install_executable'
end
```

### Accessing composer commands directly
### Accessing Composer commands directly

This library also provides a `composer:run` task which allows access to any
composer command.
Composer command.

From the command line you can run

```bash
$ cap production composer:run['status','--profile']
$ cap production composer:run[status,--profile]
```

Or from within a rake task using capistrano's `invoke`
Or from within a rake task using Capistrano's `invoke`

```ruby
task :my_custom_composer_task do
invoke "composer:run", :update, "--dev --prefer-dist"
invoke 'composer:run', :update, '--dev --prefer-dist'
end
```

Expand Down
74 changes: 50 additions & 24 deletions lib/capistrano/tasks/composer.rake
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
namespace :composer do
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")}"
This is best used after deploy:starting:
namespace :deploy do
after :starting, 'composer:install_executable'
task :validate do
on release_roles(fetch(:composer_roles)) do
composer_php = fetch(:composer_php, capture(:which, 'php'))
if composer_php.nil?
error 'composer: php not found and composer_php is not set'
exit 1
end

composer_bin = fetch(:composer_bin, capture(:which, 'composer'))
if composer_bin.nil?
error 'composer: composer not found and composer_bin is not set'
exit 1
end

if composer_bin === :local
composer_bin = shared_path.join('composer.phar')
end

SSHKit.config.command_map[:composer] = "#{composer_php} #{composer_bin}"
end
end

desc <<-DESC
Installs composer.phar to the shared directory.

When `:composer_bin` is set to `:local`, this task is automatically invoked.
DESC
task :install_executable do
on release_roles(fetch(:composer_roles)) do
within shared_path do
unless test "[", "-e", "composer.phar", "]"
unless test "[ -f #{shared_path.join('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
composer_version_option = composer_version ? "-- --version=#{composer_version}" : ''
execute :curl, '-s', fetch(:composer_download_url),
'|', fetch(:composer_php, 'php'), composer_version_option
end
end
end
Expand All @@ -30,43 +49,50 @@ namespace :composer do
end

desc <<-DESC
Install the project dependencies via Composer. By default, require-dev \
dependencies will not be installed.
Install the project dependencies via Composer. By default, require-dev \
dependencies will not be installed.

You can override any of the defaults by setting the variables shown below.
You can override any of the defaults by setting the variables shown below.

set :composer_install_flags, '--no-dev --no-interaction --quiet --optimize-autoloader'
set :composer_roles, :all
DESC
set :composer_install_flags, '--no-dev --no-interaction --quiet --optimize-autoloader'
set :composer_roles, :all
DESC
task :install do
invoke "composer:run", :install, fetch(:composer_install_flags)
invoke 'composer:run', :install, fetch(:composer_install_flags)
end

task :dump_autoload do
invoke "composer:run", :dumpautoload, fetch(:composer_dump_autoload_flags)
invoke 'composer:run', :dumpautoload, fetch(:composer_dump_autoload_flags)
end

desc <<-DESC
Run the self-update command for composer.phar
Run the self-update command for composer.phar

You can update to a specific release by setting the variables shown below.
You can update to a specific release by setting the variables shown below.

set :composer_version, '1.0.0-alpha8'
DESC
set :composer_version, '1.0.0-alpha8'
DESC
task :self_update do
invoke "composer:run", :selfupdate, fetch(:composer_version, '')
invoke 'composer:run', :selfupdate, fetch(:composer_version, '')
end

before 'deploy:updated', 'composer:install'
before 'deploy:reverted', 'composer:install'
end

Capistrano::DSL.stages.each do |stage|
after stage, 'composer:validate'
after stage, 'composer:auto_install_executable' do
invoke 'composer:install_executable' if fetch(:composer_bin) === :local
end
end

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"
set :composer_download_url, 'https://getcomposer.org/installer'
end
end