├── .gitignore ├── Gemfile ├── LICENSE ├── LICENSE.txt ├── README.md ├── Rakefile ├── capistrano-composer.gemspec └── lib ├── capistrano-composer.rb └── capistrano ├── composer.rb └── tasks └── composer.rake /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | .bundle 3 | Gemfile.lock 4 | pkg/* 5 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in capistrano-bundler.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Capistrano, your one stop deployment shop. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 swalkinshaw 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Capistrano::Composer 2 | 3 | Composer support for Capistrano 3.x 4 | 5 | ## Installation 6 | 7 | Add this line to your application's Gemfile: 8 | 9 | ```ruby 10 | gem 'capistrano', '~> 3.1.0' 11 | gem 'capistrano-composer' 12 | ``` 13 | 14 | And then execute: 15 | 16 | $ bundle 17 | 18 | Or install it yourself as: 19 | 20 | $ gem install capistrano-composer 21 | 22 | ## Usage 23 | 24 | Require the module in your `Capfile`: 25 | 26 | ```ruby 27 | require 'capistrano/composer' 28 | ``` 29 | 30 | `capistrano/composer` comes with 5 tasks: 31 | 32 | * composer:install 33 | * composer:install_executable 34 | * composer:dump_autoload 35 | * composer:self_update 36 | * composer:run 37 | 38 | The `composer:install` task will run before deploy:updated as part of 39 | Capistrano's default deploy, or can be run in isolation with: 40 | 41 | ```bash 42 | $ cap production composer:install 43 | ``` 44 | 45 | By default it is assumed that you have the composer executable installed and in your 46 | `$PATH` on all target hosts. 47 | 48 | ### Configuration 49 | 50 | Configurable options, shown here with defaults: 51 | 52 | ```ruby 53 | set :composer_install_flags, '--no-dev --no-interaction --quiet --optimize-autoloader' 54 | set :composer_roles, :all 55 | set :composer_working_dir, -> { fetch(:release_path) } 56 | set :composer_dump_autoload_flags, '--optimize' 57 | set :composer_download_url, "https://getcomposer.org/installer" 58 | set :composer_version, '1.0.0-alpha8' #(default: not set) 59 | ``` 60 | 61 | ### Installing composer as part of a deployment 62 | 63 | Add the following to `deploy.rb` to manage the installation of composer during 64 | deployment (composer.phar is install in the shared path). 65 | 66 | ```ruby 67 | SSHKit.config.command_map[:composer] = "php #{shared_path.join("composer.phar")}" 68 | 69 | namespace :deploy do 70 | after :starting, 'composer:install_executable' 71 | end 72 | ``` 73 | 74 | ### Accessing composer commands directly 75 | 76 | This library also provides a `composer:run` task which allows access to any 77 | composer command. 78 | 79 | From the command line you can run 80 | 81 | ```bash 82 | $ cap production composer:run['status','--profile'] 83 | ``` 84 | 85 | Or from within a rake task using capistrano's `invoke` 86 | 87 | ```ruby 88 | task :my_custom_composer_task do 89 | invoke "composer:run", :update, "--dev --prefer-dist" 90 | end 91 | ``` 92 | 93 | ### Removing the default install task 94 | 95 | If you do not want to run the default install task on `deploy:updated`, (for 96 | example, if you do not have root level dependencies stored in a `composer.json` 97 | you can remove it by adding the following line to your `config/deploy.rb`: 98 | 99 | ```ruby 100 | Rake::Task['deploy:updated'].prerequisites.delete('composer:install') 101 | ``` 102 | 103 | You can then call `composer.install` task within your own defined tasks, at an 104 | appropriate juncture. 105 | 106 | ## Contributing 107 | 108 | 1. Fork it 109 | 2. Create your feature branch (`git checkout -b my-new-feature`) 110 | 3. Commit your changes (`git commit -am 'Add some feature'`) 111 | 4. Push to the branch (`git push origin my-new-feature`) 112 | 5. Create new Pull Request 113 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler/gem_tasks' 2 | -------------------------------------------------------------------------------- /capistrano-composer.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | 5 | Gem::Specification.new do |spec| 6 | spec.name = 'capistrano-composer' 7 | spec.version = '0.0.6' 8 | spec.authors = ['Scott Walkinshaw', 'Peter Mitchell'] 9 | spec.email = ['scott.walkinshaw@gmail.com', 'peterjmit@gmail.com'] 10 | spec.description = %q{Composer support for Capistrano 3.x} 11 | spec.summary = %q{Composer support for Capistrano 3.x} 12 | spec.homepage = 'https://github.com/capistrano/composer' 13 | spec.license = 'MIT' 14 | 15 | spec.files = `git ls-files`.split($/) 16 | spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } 17 | spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) 18 | spec.require_paths = ['lib'] 19 | 20 | spec.add_dependency 'capistrano', '>= 3.0.0.pre' 21 | 22 | spec.add_development_dependency 'bundler', '~> 1.3' 23 | spec.add_development_dependency 'rake', '~> 10.1' 24 | end 25 | -------------------------------------------------------------------------------- /lib/capistrano-composer.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/capistrano/composer/876298adcf56dacecedb37732a21d0057e001600/lib/capistrano-composer.rb -------------------------------------------------------------------------------- /lib/capistrano/composer.rb: -------------------------------------------------------------------------------- 1 | load File.expand_path('../tasks/composer.rake', __FILE__) 2 | -------------------------------------------------------------------------------- /lib/capistrano/tasks/composer.rake: -------------------------------------------------------------------------------- 1 | namespace :composer do 2 | desc <<-DESC 3 | Installs composer.phar to the shared directory 4 | In order to use the .phar file, the composer command needs to be mapped: 5 | SSHKit.config.command_map[:composer] = "\#{shared_path.join("composer.phar")}" 6 | This is best used after deploy:starting: 7 | namespace :deploy do 8 | after :starting, 'composer:install_executable' 9 | end 10 | DESC 11 | task :install_executable do 12 | on release_roles(fetch(:composer_roles)) do 13 | within shared_path do 14 | composer_version = fetch(:composer_version, nil) 15 | composer_version_option = composer_version ? "-- --version=#{composer_version}" : "" 16 | if test "[", "!", "-e", "composer.phar", "]" 17 | execute :curl, "-s", fetch(:composer_download_url), "|", :php, composer_version_option 18 | elsif composer_version 19 | current_version = capture(:php, "composer.phar", "-V", strip: false) 20 | unless current_version.include? "Composer version #{composer_version} " 21 | execute :curl, "-s", fetch(:composer_download_url), "|", :php, composer_version_option 22 | end 23 | end 24 | end 25 | end 26 | end 27 | 28 | task :run, :command do |t, args| 29 | args.with_defaults(:command => :list) 30 | on release_roles(fetch(:composer_roles)) do 31 | within fetch(:composer_working_dir) do 32 | execute :composer, args[:command], *args.extras 33 | end 34 | end 35 | end 36 | 37 | desc <<-DESC 38 | Install the project dependencies via Composer. By default, require-dev \ 39 | dependencies will not be installed. 40 | 41 | You can override any of the defaults by setting the variables shown below. 42 | 43 | set :composer_install_flags, '--no-dev --no-interaction --quiet --optimize-autoloader' 44 | set :composer_roles, :all 45 | DESC 46 | task :install do 47 | invoke "composer:run", :install, fetch(:composer_install_flags) 48 | end 49 | 50 | task :dump_autoload do 51 | invoke "composer:run", :dumpautoload, fetch(:composer_dump_autoload_flags) 52 | end 53 | 54 | desc <<-DESC 55 | Run the self-update command for composer.phar 56 | 57 | You can update to a specific release by setting the variables shown below. 58 | 59 | set :composer_version, '1.0.0-alpha8' 60 | DESC 61 | task :self_update do 62 | invoke "composer:run", :selfupdate, fetch(:composer_version, '') 63 | end 64 | 65 | before 'deploy:updated', 'composer:install' 66 | before 'deploy:reverted', 'composer:install' 67 | end 68 | 69 | namespace :load do 70 | task :defaults do 71 | set :composer_install_flags, '--no-dev --prefer-dist --no-interaction --quiet --optimize-autoloader' 72 | set :composer_roles, :all 73 | set :composer_working_dir, -> { release_path } 74 | set :composer_dump_autoload_flags, '--optimize' 75 | set :composer_download_url, "https://getcomposer.org/installer" 76 | end 77 | end 78 | --------------------------------------------------------------------------------