Add Composer, Mermaid extension
This commit is contained in:
		
							parent
							
								
									9c0ce30780
								
							
						
					
					
						commit
						af6fe37e0b
					
				@ -14,6 +14,7 @@ cookbook 'redis',
 | 
			
		||||
cookbook 'postfix',                '= 5.0.2'
 | 
			
		||||
cookbook 'php-fpm',                '= 0.7.9'
 | 
			
		||||
cookbook 'php',                    '= 4.2.0'
 | 
			
		||||
cookbook 'composer',               '~> 2.6.1'
 | 
			
		||||
cookbook 'poise-ruby-build',       '~> 1.1.0'
 | 
			
		||||
cookbook 'application',            '~> 5.2.0'
 | 
			
		||||
cookbook 'application_javascript', '~> 1.0.0'
 | 
			
		||||
 | 
			
		||||
@ -11,6 +11,7 @@ DEPENDENCIES
 | 
			
		||||
  chef_client_updater (= 1.1.1)
 | 
			
		||||
  chef_nginx (= 6.1.1)
 | 
			
		||||
  compat_resource (= 12.19.0)
 | 
			
		||||
  composer (~> 2.6.1)
 | 
			
		||||
  database (= 6.1.1)
 | 
			
		||||
  dmg (= 4.0.0)
 | 
			
		||||
  firewall (~> 2.6.3)
 | 
			
		||||
@ -96,6 +97,10 @@ GRAPH
 | 
			
		||||
    yum-epel (>= 0.0.0)
 | 
			
		||||
    zypper (>= 0.0.0)
 | 
			
		||||
  compat_resource (12.19.0)
 | 
			
		||||
  composer (2.6.1)
 | 
			
		||||
    apt (>= 0.0.0)
 | 
			
		||||
    php (>= 0.0.0)
 | 
			
		||||
    windows (>= 0.0.0)
 | 
			
		||||
  database (6.1.1)
 | 
			
		||||
    postgresql (>= 1.0.0)
 | 
			
		||||
  dmg (4.0.0)
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										187
									
								
								cookbooks/composer/README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										187
									
								
								cookbooks/composer/README.md
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,187 @@
 | 
			
		||||
[](https://travis-ci.org/djoos-cookbooks/composer)
 | 
			
		||||
 | 
			
		||||
# composer cookbook
 | 
			
		||||
 | 
			
		||||
## Description
 | 
			
		||||
 | 
			
		||||
This cookbook provides an easy way to install Composer, a dependency manager for PHP.
 | 
			
		||||
 | 
			
		||||
More information?
 | 
			
		||||
http://getcomposer.org/
 | 
			
		||||
 | 
			
		||||
## Requirements
 | 
			
		||||
 | 
			
		||||
### Cookbooks:
 | 
			
		||||
 | 
			
		||||
* php
 | 
			
		||||
* windows
 | 
			
		||||
 | 
			
		||||
### Platforms:
 | 
			
		||||
 | 
			
		||||
* Ubuntu
 | 
			
		||||
* Debian
 | 
			
		||||
* RHEL
 | 
			
		||||
* CentOS
 | 
			
		||||
* Fedora
 | 
			
		||||
* Windows
 | 
			
		||||
 | 
			
		||||
## Attributes
 | 
			
		||||
 | 
			
		||||
* `node['composer']['url']` - Location of the source
 | 
			
		||||
* `node['composer']['install_dir']` - Installation target directory (absolute or relative path) if installing locally
 | 
			
		||||
* `node['composer']['bin']` - bin directory
 | 
			
		||||
* `node['composer']['install_globally']` - Installation method, ':source' or ':package' - default true
 | 
			
		||||
* `node['composer']['mask']` - Mask for composer.phar - 0755
 | 
			
		||||
* `node['composer']['link_type']` - link type for composer.phar link - default :symbolic
 | 
			
		||||
* `node['composer']['global_configs']` - Hash with global config options for users, eg. { "userX" => { "github-oauth" => { "github.com" => "userX_oauth_token" }, "vendor-dir" => "myvendordir" } } - default {}
 | 
			
		||||
* `node['composer']['home_dir']` - COMPOSER_HOME, defaults to nil (in which case install_dir will be used), please do read the [Composer documentation on COMPOSER_HOME](https://getcomposer.org/doc/03-cli.md#composer-home) when setting a custom home_dir
 | 
			
		||||
* `node['composer']['php_recipe']` - The php recipe to include, defaults to "php::default"
 | 
			
		||||
* `node['composer']['global_install']['install_dir']` - The default location to install the packages in for composer_install_global
 | 
			
		||||
* `node['composer']['global_install']['bin_dir']` - The default location to symlink the binaries when using composer_install_global
 | 
			
		||||
 | 
			
		||||
## Resources / Providers
 | 
			
		||||
This cookbook includes an LWRP for managing a Composer project and one for a global installation of composer packages
 | 
			
		||||
 | 
			
		||||
### `composer_project`
 | 
			
		||||
 | 
			
		||||
#### Actions
 | 
			
		||||
- :install: Reads the composer.json file from the current directory, resolves the dependencies, and installs them into project directory - this is the default action
 | 
			
		||||
- :require Create composer.json file using specified package and version and installs it with the dependencies.
 | 
			
		||||
- :update: Gets the latest versions of the dependencies and updates the composer.lock file
 | 
			
		||||
- :dump_autoload: Updates the autoloader without having to go through an install or update (eg. because of new classes in a classmap package)
 | 
			
		||||
- :remove Removes package from composer.json and uninstalls it
 | 
			
		||||
 | 
			
		||||
#### Attribute parameters
 | 
			
		||||
- project_dir: The directory where your project's composer.json can be found (name attribute)
 | 
			
		||||
- package: The package to require or remove when using those actions
 | 
			
		||||
- version: The version of the package to require or remove when using those actions, default *.*.* Be careful when uninstalling, the version has to match the installed package!
 | 
			
		||||
- vendor: Can be used to combine package and version, deprecated!
 | 
			
		||||
- dev: Install packages listed in require-dev, default false
 | 
			
		||||
- quiet: Do not output any message, default true
 | 
			
		||||
- optimize_autoloader: Optimize PSR0 packages to use classmaps, default false
 | 
			
		||||
- prefer_dist: use the dist installation method
 | 
			
		||||
- prefer_source: use the source installation method
 | 
			
		||||
- bin_dir, overwrites the composer bin dir
 | 
			
		||||
- user: the user to use when executing the composer commands
 | 
			
		||||
- group: the group to use when executing the composer commands
 | 
			
		||||
- umask: the umask to use when executing the composer commands
 | 
			
		||||
- environment: A hash of environment variables that will be available when running composer
 | 
			
		||||
 | 
			
		||||
#### Examples
 | 
			
		||||
```
 | 
			
		||||
# Install the project dependencies
 | 
			
		||||
composer_project "/path/to/project" do
 | 
			
		||||
    dev false
 | 
			
		||||
    quiet true
 | 
			
		||||
    prefer_dist false
 | 
			
		||||
    action :install
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# Require the package in the project dir
 | 
			
		||||
composer_project "/path/to/project" do
 | 
			
		||||
    package 'vendor/package'
 | 
			
		||||
    version '*.*.*'
 | 
			
		||||
    dev false
 | 
			
		||||
    quiet true
 | 
			
		||||
    prefer_dist false
 | 
			
		||||
    action :require
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# Update the project dependencies
 | 
			
		||||
composer_project "/path/to/project" do
 | 
			
		||||
    dev false
 | 
			
		||||
    quiet true
 | 
			
		||||
    action :update
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# Dump-autoload in the project dir
 | 
			
		||||
composer_project "/path/to/project" do
 | 
			
		||||
    dev false
 | 
			
		||||
    quiet true
 | 
			
		||||
    action :dump_autoload
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# Remove the package in the project dir
 | 
			
		||||
composer_project "/path/to/project" do
 | 
			
		||||
    package 'vendor/package'
 | 
			
		||||
    action :remove
 | 
			
		||||
end
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### `composer_install_global`
 | 
			
		||||
 | 
			
		||||
#### Actions
 | 
			
		||||
- :install: Installs the package in the preferred global composer directory, putting binary symlinks in the preferred global binary directory (see attributes)
 | 
			
		||||
- :update: Gets the latest versions of the dependencies and updates the composer.lock file for the globally installed composer packages
 | 
			
		||||
- :remove Removes package from the global composer.json and uninstalls it
 | 
			
		||||
 | 
			
		||||
#### Attribute parameters
 | 
			
		||||
- package: The package to install or remove, name_attribute
 | 
			
		||||
- version: The version of the package to install or remove when using those actions, default *.*.* Be careful when uninstalling, the version has to match the installed package!
 | 
			
		||||
- install_dir: the directory in which to make the global installation, default: see the attributes
 | 
			
		||||
- bin_dir: the directory in which to make the symlinks to the binaries, default: see the attributes
 | 
			
		||||
- dev: Install packages listed in require-dev, default false
 | 
			
		||||
- quiet: Do not output any message, default true
 | 
			
		||||
- optimize_autoloader: Optimize PSR0 packages to use classmaps, default false
 | 
			
		||||
- prefer_dist: use the dist installation method
 | 
			
		||||
- prefer_source: use the source installation method
 | 
			
		||||
 | 
			
		||||
#### Examples
 | 
			
		||||
```
 | 
			
		||||
# Install a package globally
 | 
			
		||||
composer_install_global "package" do
 | 
			
		||||
    version '~4.1'
 | 
			
		||||
    action :install
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# Update the package
 | 
			
		||||
composer_install_global "package" do
 | 
			
		||||
    action :update
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# Remove the package from the global installation
 | 
			
		||||
composer_install_global "package" do
 | 
			
		||||
    action :remove
 | 
			
		||||
end
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
## Usage
 | 
			
		||||
 | 
			
		||||
1. include `recipe[composer]` in a run list
 | 
			
		||||
2. tweak the attributes via attributes/default.rb
 | 
			
		||||
--- OR ---
 | 
			
		||||
[override the attribute on a higher level](http://wiki.opscode.com/display/chef/Attributes#Attributes-AttributesPrecedence)
 | 
			
		||||
 | 
			
		||||
## References
 | 
			
		||||
 | 
			
		||||
* [Composer home page] (http://getcomposer.org/)
 | 
			
		||||
 | 
			
		||||
## License and Authors
 | 
			
		||||
 | 
			
		||||
Author: David Joos <development@davidjoos.com>
 | 
			
		||||
Copyright: 2016, David Joos
 | 
			
		||||
 | 
			
		||||
Author: David Joos <david.joos@escapestudios.com>
 | 
			
		||||
Author: Escape Studios Development <dev@escapestudios.com>
 | 
			
		||||
Copyright: 2012-2015, Escape Studios
 | 
			
		||||
 | 
			
		||||
Unless otherwise noted, all files are released under the MIT license,
 | 
			
		||||
possible exceptions will contain licensing information in them.
 | 
			
		||||
 | 
			
		||||
Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
			
		||||
of this software and associated documentation files (the "Software"), to deal
 | 
			
		||||
in the Software without restriction, including without limitation the rights
 | 
			
		||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
			
		||||
copies of the Software, and to permit persons to whom the Software is
 | 
			
		||||
furnished to do so, subject to the following conditions:
 | 
			
		||||
 | 
			
		||||
The above copyright notice and this permission notice shall be included in
 | 
			
		||||
all copies or substantial portions of the Software.
 | 
			
		||||
 | 
			
		||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
			
		||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
			
		||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
			
		||||
THE SOFTWARE.
 | 
			
		||||
							
								
								
									
										29
									
								
								cookbooks/composer/attributes/default.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								cookbooks/composer/attributes/default.rb
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,29 @@
 | 
			
		||||
#
 | 
			
		||||
# Cookbook Name:: composer
 | 
			
		||||
# Attributes:: default
 | 
			
		||||
#
 | 
			
		||||
# Copyright (c) 2016, David Joos
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
include_attribute 'php'
 | 
			
		||||
 | 
			
		||||
if node['platform'] == 'windows'
 | 
			
		||||
  default['composer']['url'] = 'https://getcomposer.org/Composer-Setup.exe'
 | 
			
		||||
  default['composer']['install_dir'] = 'C:\\ProgramData\\ComposerSetup'
 | 
			
		||||
  default['composer']['bin'] = "#{node['composer']['install_dir']}\\composer.bat"
 | 
			
		||||
  default['composer']['global_install']['install_dir'] = 'C:\\Program\ Files\\Composer'
 | 
			
		||||
  default['composer']['global_install']['bin_dir'] = 'C:\\ProgramData\\Composer'
 | 
			
		||||
else
 | 
			
		||||
  default['composer']['url'] = 'http://getcomposer.org/composer.phar'
 | 
			
		||||
  default['composer']['install_dir'] = '/usr/local/bin'
 | 
			
		||||
  default['composer']['bin'] = "#{node['composer']['install_dir']}/composer"
 | 
			
		||||
  default['composer']['install_globally'] = true
 | 
			
		||||
  default['composer']['mask'] = '0755'
 | 
			
		||||
  default['composer']['link_type'] = :symbolic
 | 
			
		||||
  default['composer']['global_install']['install_dir'] = '/usr/local/composer'
 | 
			
		||||
  default['composer']['global_install']['bin_dir'] = '/usr/local/bin'
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
default['composer']['global_configs'] = {}
 | 
			
		||||
default['composer']['home_dir'] = nil
 | 
			
		||||
default['composer']['php_recipe'] = 'php::default'
 | 
			
		||||
							
								
								
									
										10
									
								
								cookbooks/composer/libraries/composer.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								cookbooks/composer/libraries/composer.rb
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,10 @@
 | 
			
		||||
# Composer module
 | 
			
		||||
module Composer
 | 
			
		||||
  def self.install_dir(node)
 | 
			
		||||
    node['composer']['install_dir']
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def self.home_dir(node)
 | 
			
		||||
    node['composer']['home_dir'] || install_dir(node)
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										63
									
								
								cookbooks/composer/metadata.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								cookbooks/composer/metadata.json
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										78
									
								
								cookbooks/composer/providers/install_global.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										78
									
								
								cookbooks/composer/providers/install_global.rb
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,78 @@
 | 
			
		||||
#
 | 
			
		||||
# Cookbook Name:: composer
 | 
			
		||||
# Resource:: install_global
 | 
			
		||||
#
 | 
			
		||||
# Copyright 2012-2014, Escape Studios
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
use_inline_resources if defined?(use_inline_resources)
 | 
			
		||||
 | 
			
		||||
def whyrun_supported?
 | 
			
		||||
  true
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
action :install do
 | 
			
		||||
  install_global_install
 | 
			
		||||
  new_resource.updated_by_last_action(true)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
action :remove do
 | 
			
		||||
  install_global_remove
 | 
			
		||||
  new_resource.updated_by_last_action(true)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
action :update do
 | 
			
		||||
  install_global_update
 | 
			
		||||
  new_resource.updated_by_last_action(true)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
def install_global_install
 | 
			
		||||
  install_dir = new_resource.install_dir ? new_resource.install_dir : node['composer']['global_install']['install_dir']
 | 
			
		||||
  bin_dir = new_resource.bin_dir ? new_resource.bin_dir : node['composer']['global_install']['bin_dir']
 | 
			
		||||
  directory install_dir
 | 
			
		||||
 | 
			
		||||
  composer_project install_dir do
 | 
			
		||||
    package new_resource.package
 | 
			
		||||
    version new_resource.version
 | 
			
		||||
    bin_dir bin_dir
 | 
			
		||||
    dev new_resource.dev
 | 
			
		||||
    quiet new_resource.quiet
 | 
			
		||||
    optimize_autoloader new_resource.optimize_autoloader
 | 
			
		||||
    prefer_dist new_resource.prefer_dist
 | 
			
		||||
    prefer_source new_resource.prefer_source
 | 
			
		||||
    action :require
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
def install_global_remove
 | 
			
		||||
  install_dir = new_resource.install_dir ? new_resource.install_dir : node['composer']['global_install']['install_dir']
 | 
			
		||||
 | 
			
		||||
  composer_project install_dir do
 | 
			
		||||
    package new_resource.package
 | 
			
		||||
    version new_resource.version
 | 
			
		||||
    bin_dir bin_dir
 | 
			
		||||
    dev new_resource.dev
 | 
			
		||||
    quiet new_resource.quiet
 | 
			
		||||
    optimize_autoloader new_resource.optimize_autoloader
 | 
			
		||||
    prefer_dist new_resource.prefer_dist
 | 
			
		||||
    prefer_source new_resource.prefer_source
 | 
			
		||||
    action :remove
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
def install_global_update
 | 
			
		||||
  install_dir = new_resource.install_dir ? new_resource.install_dir : node['composer']['global_install']['install_dir']
 | 
			
		||||
  bin_dir = new_resource.bin_dir ? new_resource.bin_dir : node['composer']['global_install']['bin_dir']
 | 
			
		||||
 | 
			
		||||
  composer_project install_dir do
 | 
			
		||||
    package new_resource.package
 | 
			
		||||
    version new_resource.version
 | 
			
		||||
    bin_dir bin_dir
 | 
			
		||||
    dev new_resource.dev
 | 
			
		||||
    quiet new_resource.quiet
 | 
			
		||||
    optimize_autoloader new_resource.optimize_autoloader
 | 
			
		||||
    prefer_dist new_resource.prefer_dist
 | 
			
		||||
    prefer_source new_resource.prefer_source
 | 
			
		||||
    action :update
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										125
									
								
								cookbooks/composer/providers/project.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										125
									
								
								cookbooks/composer/providers/project.rb
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,125 @@
 | 
			
		||||
#
 | 
			
		||||
# Cookbook Name:: composer
 | 
			
		||||
# Resource:: project
 | 
			
		||||
#
 | 
			
		||||
# Copyright (c) 2016, David Joos
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
use_inline_resources if defined?(use_inline_resources)
 | 
			
		||||
 | 
			
		||||
def whyrun_supported?
 | 
			
		||||
  true
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
action :install do
 | 
			
		||||
  make_execute 'install'
 | 
			
		||||
  new_resource.updated_by_last_action(true)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
action :require do
 | 
			
		||||
  make_require
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
action :update do
 | 
			
		||||
  make_execute 'update'
 | 
			
		||||
  new_resource.updated_by_last_action(true)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
action :dump_autoload do
 | 
			
		||||
  make_execute 'dump-autoload'
 | 
			
		||||
  new_resource.updated_by_last_action(true)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
action :remove do
 | 
			
		||||
  remove_package 'remove'
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
def make_execute(cmd)
 | 
			
		||||
  dev = new_resource.dev ? '--dev' : '--no-dev'
 | 
			
		||||
  quiet = new_resource.quiet ? '--quiet' : ''
 | 
			
		||||
  optimize = new_resource.optimize_autoloader ? optimize_flag(cmd) : ''
 | 
			
		||||
  prefer_dist = new_resource.prefer_dist ? '--prefer-dist' : ''
 | 
			
		||||
  prefer_source = new_resource.prefer_source ? '--prefer-source' : ''
 | 
			
		||||
  environment = {
 | 
			
		||||
    :COMPOSER_HOME => Composer.home_dir(node),
 | 
			
		||||
    :COMPOSER_BIN_DIR => new_resource.bin_dir
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  execute "#{cmd}-composer-for-project" do
 | 
			
		||||
    cwd new_resource.project_dir
 | 
			
		||||
    command "#{node['composer']['bin']} #{cmd} --no-interaction --no-ansi #{quiet} #{dev} #{optimize} #{prefer_dist} #{prefer_source}"
 | 
			
		||||
    environment(environment.merge(new_resource.environment))
 | 
			
		||||
    action :run
 | 
			
		||||
    user new_resource.user
 | 
			
		||||
    group new_resource.group
 | 
			
		||||
    umask new_resource.umask
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
def make_require
 | 
			
		||||
  dev = new_resource.dev ? '--dev' : '--update-no-dev'
 | 
			
		||||
  package = new_resource.package
 | 
			
		||||
  version = new_resource.version ? new_resource.version : '*.*.*'
 | 
			
		||||
  package, version = vendor_package_identity(new_resource.vendor, package, version)
 | 
			
		||||
  raise 'package is needed for composer_project with action require' if package.nil?
 | 
			
		||||
  prefer_dist = new_resource.prefer_dist ? '--prefer-dist' : ''
 | 
			
		||||
  environment = {
 | 
			
		||||
    :COMPOSER_HOME => Composer.home_dir(node),
 | 
			
		||||
    :COMPOSER_BIN_DIR => new_resource.bin_dir
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  execute 'Install-composer-for-single-project' do
 | 
			
		||||
    cwd new_resource.project_dir
 | 
			
		||||
    command "#{node['composer']['bin']} require #{package}:#{version} #{dev} #{prefer_dist}"
 | 
			
		||||
    environment(environment.merge(new_resource.environment))
 | 
			
		||||
    action :run
 | 
			
		||||
    not_if do
 | 
			
		||||
      !version.include?('*') &&
 | 
			
		||||
        shell_out("cd #{new_resource.project_dir} && #{node['composer']['bin']} show #{package} #{version}").exitstatus.zero?
 | 
			
		||||
    end
 | 
			
		||||
    user new_resource.user
 | 
			
		||||
    group new_resource.group
 | 
			
		||||
    umask new_resource.umask
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
def remove_package(cmd)
 | 
			
		||||
  package = new_resource.package
 | 
			
		||||
  version = new_resource.version ? new_resource.version : '*.*.*'
 | 
			
		||||
  package, version = vendor_package_identity(new_resource.vendor, package, version)
 | 
			
		||||
  raise 'package is needed for composer_project with action require' if package.nil?
 | 
			
		||||
  environment = {
 | 
			
		||||
    :COMPOSER_HOME => Composer.home_dir(node),
 | 
			
		||||
    :COMPOSER_BIN_DIR => new_resource.bin_dir
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  execute "#{cmd}-composer-for-project" do
 | 
			
		||||
    cwd new_resource.project_dir
 | 
			
		||||
    command "#{node['composer']['bin']} remove #{package}"
 | 
			
		||||
    environment(environment.merge(new_resource.environment))
 | 
			
		||||
    action :run
 | 
			
		||||
    only_if "#{node['composer']['bin']} show #{package} #{version}"
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
def optimize_flag(cmd)
 | 
			
		||||
  %(install update).include?(cmd) ? '--optimize-autoloader' : '--optimize'
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
def vendor_package_identity(vendor, package, version)
 | 
			
		||||
  unless vendor.nil?
 | 
			
		||||
    # @todo take out deprecated vendor logic
 | 
			
		||||
    Chef::Log.warn('The vendor attribute is deprecated, please use package and version instead.')
 | 
			
		||||
 | 
			
		||||
    vendor_split = vendor.split(':')
 | 
			
		||||
    package = vendor_split[0]
 | 
			
		||||
 | 
			
		||||
    version = if vendor_split[1].nil?
 | 
			
		||||
                version
 | 
			
		||||
              else
 | 
			
		||||
                vendor_split[1]
 | 
			
		||||
              end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  [package, version]
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										12
									
								
								cookbooks/composer/recipes/default.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								cookbooks/composer/recipes/default.rb
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,12 @@
 | 
			
		||||
#
 | 
			
		||||
# Cookbook Name:: composer
 | 
			
		||||
# Recipe:: default
 | 
			
		||||
#
 | 
			
		||||
# Copyright (c) 2016, David Joos
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
include_recipe 'composer::install'
 | 
			
		||||
 | 
			
		||||
if node['composer']['install_globally']
 | 
			
		||||
  include_recipe 'composer::global_configs'
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										45
									
								
								cookbooks/composer/recipes/global_configs.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								cookbooks/composer/recipes/global_configs.rb
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,45 @@
 | 
			
		||||
#
 | 
			
		||||
# Cookbook Name:: composer
 | 
			
		||||
# Recipe:: global_configs
 | 
			
		||||
#
 | 
			
		||||
# Copyright (c) 2016, David Joos
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
configs = node['composer']['global_configs']
 | 
			
		||||
 | 
			
		||||
unless configs.nil?
 | 
			
		||||
  configs.each_pair do |user, user_configs|
 | 
			
		||||
    user_composer_dir = "#{Dir.home(user)}/.composer"
 | 
			
		||||
 | 
			
		||||
    directory user_composer_dir do
 | 
			
		||||
      owner user
 | 
			
		||||
      group user
 | 
			
		||||
      mode '0755'
 | 
			
		||||
      action :create
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    user_configs.nil? && next
 | 
			
		||||
 | 
			
		||||
    user_configs.each_pair do |option, value|
 | 
			
		||||
      if value.respond_to?(:each_pair)
 | 
			
		||||
        value.each_pair do |value_k, value_v|
 | 
			
		||||
          execute "composer-config-for-#{user}" do
 | 
			
		||||
            command "composer config --global #{option}.#{value_k} #{value_v}"
 | 
			
		||||
            environment 'COMPOSER_HOME' => user_composer_dir
 | 
			
		||||
            user user
 | 
			
		||||
            group user
 | 
			
		||||
            action :run
 | 
			
		||||
          end
 | 
			
		||||
        end
 | 
			
		||||
      else
 | 
			
		||||
        execute "composer-config-for-#{user}" do
 | 
			
		||||
          command "composer config --global #{option} #{value}"
 | 
			
		||||
          environment 'COMPOSER_HOME' => user_composer_dir
 | 
			
		||||
          user user
 | 
			
		||||
          group user
 | 
			
		||||
          action :run
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										36
									
								
								cookbooks/composer/recipes/install.rb
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										36
									
								
								cookbooks/composer/recipes/install.rb
									
									
									
									
									
										Executable file
									
								
							@ -0,0 +1,36 @@
 | 
			
		||||
#
 | 
			
		||||
# Cookbook Name:: composer
 | 
			
		||||
# Recipe:: install
 | 
			
		||||
#
 | 
			
		||||
# Copyright (c) 2016, David Joos
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
include_recipe node['composer']['php_recipe']
 | 
			
		||||
 | 
			
		||||
if node['platform'] == 'windows'
 | 
			
		||||
  windows_package 'Composer - PHP Dependency Manager' do
 | 
			
		||||
    source node['composer']['url']
 | 
			
		||||
    options %w(
 | 
			
		||||
      /VERYSILENT
 | 
			
		||||
    ).join(' ')
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  install_dir = "#{node['composer']['install_dir'].tr('/', '\\')}\\bin"
 | 
			
		||||
 | 
			
		||||
  ENV['PATH'] += ";#{install_dir}"
 | 
			
		||||
  windows_path install_dir
 | 
			
		||||
else
 | 
			
		||||
  log '[composer] phar (PHP archive) not supported' do
 | 
			
		||||
    level :warn
 | 
			
		||||
    not_if "php -m | grep 'Phar'"
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  file = node['composer']['install_globally'] ? "#{node['composer']['install_dir']}/composer" : "#{node['composer']['install_dir']}/composer.phar"
 | 
			
		||||
 | 
			
		||||
  remote_file file do
 | 
			
		||||
    source node['composer']['url']
 | 
			
		||||
    mode node['composer']['mask']
 | 
			
		||||
    action :create
 | 
			
		||||
    not_if { ::File.exist?(file) }
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										16
									
								
								cookbooks/composer/recipes/self_update.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								cookbooks/composer/recipes/self_update.rb
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,16 @@
 | 
			
		||||
#
 | 
			
		||||
# Cookbook Name:: composer
 | 
			
		||||
# Recipe:: self_update
 | 
			
		||||
#
 | 
			
		||||
# Copyright (c) 2016, David Joos
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
include_recipe 'composer::install'
 | 
			
		||||
 | 
			
		||||
execute 'composer-self_update' do
 | 
			
		||||
  cwd node['composer']['install_dir']
 | 
			
		||||
  command 'composer self-update'
 | 
			
		||||
  environment 'COMPOSER_HOME' => Composer.home_dir(node)
 | 
			
		||||
  action :run
 | 
			
		||||
  ignore_failure true
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										24
									
								
								cookbooks/composer/resources/install_global.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								cookbooks/composer/resources/install_global.rb
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,24 @@
 | 
			
		||||
#
 | 
			
		||||
# Cookbook Name:: composer
 | 
			
		||||
# Resource:: install_global
 | 
			
		||||
#
 | 
			
		||||
# Copyright 2012-2014, Escape Studios
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
actions :install, :update, :remove
 | 
			
		||||
default_action :install
 | 
			
		||||
 | 
			
		||||
attribute :package, :kind_of => String, :name_attribute => true, :required => true
 | 
			
		||||
attribute :version, :kind_of => String, :default => '*.*.*'
 | 
			
		||||
attribute :install_dir, :kind_of => String, :default => nil
 | 
			
		||||
attribute :bin_dir, :kind_of => String, :default => nil
 | 
			
		||||
attribute :dev, :kind_of => [TrueClass, FalseClass], :default => false
 | 
			
		||||
attribute :quiet, :kind_of => [TrueClass, FalseClass], :default => true
 | 
			
		||||
attribute :optimize_autoloader, :kind_of => [TrueClass, FalseClass], :default => false
 | 
			
		||||
attribute :prefer_dist, :kind_of => [TrueClass, FalseClass], :default => false
 | 
			
		||||
attribute :prefer_source, :kind_of => [TrueClass, FalseClass], :default => false
 | 
			
		||||
 | 
			
		||||
def initialize(*args)
 | 
			
		||||
  super
 | 
			
		||||
  @action = :install
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										29
									
								
								cookbooks/composer/resources/project.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								cookbooks/composer/resources/project.rb
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,29 @@
 | 
			
		||||
#
 | 
			
		||||
# Cookbook Name:: composer
 | 
			
		||||
# Resource:: project
 | 
			
		||||
#
 | 
			
		||||
# Copyright (c) 2016, David Joos
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
actions :install, :single, :require, :update, :dump_autoload, :remove
 | 
			
		||||
default_action :install
 | 
			
		||||
 | 
			
		||||
attribute :project_dir, :kind_of => String, :name_attribute => true
 | 
			
		||||
attribute :vendor, :kind_of => String, :default => nil
 | 
			
		||||
attribute :package, :kind_of => String, :default => nil
 | 
			
		||||
attribute :version, :kind_of => String, :default => nil
 | 
			
		||||
attribute :dev, :kind_of => [TrueClass, FalseClass], :default => false
 | 
			
		||||
attribute :quiet, :kind_of => [TrueClass, FalseClass], :default => true
 | 
			
		||||
attribute :optimize_autoloader, :kind_of => [TrueClass, FalseClass], :default => false
 | 
			
		||||
attribute :prefer_dist, :kind_of => [TrueClass, FalseClass], :default => false
 | 
			
		||||
attribute :prefer_source, :kind_of => [TrueClass, FalseClass], :default => false
 | 
			
		||||
attribute :bin_dir, :kind_of => String, :default => 'vendor/bin'
 | 
			
		||||
attribute :user, :kind_of => String, :default => 'root'
 | 
			
		||||
attribute :group, :kind_of => String, :default => 'root'
 | 
			
		||||
attribute :umask, :kind_of => [String, Integer], :default => '0002'
 | 
			
		||||
attribute :environment, :kind_of => Hash, :default => {}
 | 
			
		||||
 | 
			
		||||
def initialize(*args)
 | 
			
		||||
  super
 | 
			
		||||
  @action = :install
 | 
			
		||||
end
 | 
			
		||||
@ -9,5 +9,6 @@ version          '0.1.0'
 | 
			
		||||
depends "mediawiki"
 | 
			
		||||
depends "ark"
 | 
			
		||||
depends "backup"
 | 
			
		||||
depends "composer"
 | 
			
		||||
depends "kosmos-nginx"
 | 
			
		||||
depends "kosmos-base"
 | 
			
		||||
 | 
			
		||||
@ -9,6 +9,7 @@
 | 
			
		||||
 | 
			
		||||
include_recipe 'apt'
 | 
			
		||||
include_recipe 'ark'
 | 
			
		||||
include_recipe 'composer'
 | 
			
		||||
 | 
			
		||||
# FIXME: For now run the update script manually after updating:
 | 
			
		||||
#
 | 
			
		||||
@ -93,10 +94,16 @@ nginx_site 'mediawiki' do
 | 
			
		||||
  enable true
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Extensions
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
mediawiki_credentials = Chef::EncryptedDataBagItem.load('credentials', 'mediawiki')
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Cleantalk Antispam
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
ark "antispam" do
 | 
			
		||||
  url "https://github.com/CleanTalk/mediawiki-antispam/archive/1.8.zip"
 | 
			
		||||
  path "#{node['mediawiki']['webdir']}/extensions/Antispam"
 | 
			
		||||
@ -106,7 +113,10 @@ ark "antispam" do
 | 
			
		||||
  action :dump
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# MediawikiHubot extension
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
# requires curl extension
 | 
			
		||||
if platform?('ubuntu') && node[:platform_version].to_f < 16.04
 | 
			
		||||
  package "php5-curl"
 | 
			
		||||
@ -174,10 +184,40 @@ $wgArticlePath = "/$1";
 | 
			
		||||
                                 "$wgCTAccessKey = \"#{mediawiki_credentials['antispam_key']}\";")
 | 
			
		||||
    file.insert_line_if_no_match(/MediawikiHubot\.php/,
 | 
			
		||||
                                 "require_once \"$IP/extensions/MediawikiHubot/MediawikiHubot.php\";")
 | 
			
		||||
 | 
			
		||||
    file.insert_line_if_no_match(/Mermaid/,
 | 
			
		||||
                                 "wfLoadExtension( 'Mermaid' );")
 | 
			
		||||
 | 
			
		||||
    file.write_file
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Composer dependencies
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
file "#{node['mediawiki']['webdir']}/composer.local.json" do
 | 
			
		||||
  requires = { "require": {
 | 
			
		||||
    "mediawiki/mermaid": "~1.0"
 | 
			
		||||
  }}.to_json
 | 
			
		||||
  content requires
 | 
			
		||||
  owner node['nginx']['user']
 | 
			
		||||
  group node['nginx']['group']
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
composer_project node['mediawiki']['webdir'] do
 | 
			
		||||
  dev false
 | 
			
		||||
  quiet true
 | 
			
		||||
  prefer_dist false
 | 
			
		||||
  user node['nginx']['user']
 | 
			
		||||
  group node['nginx']['group']
 | 
			
		||||
  action :install
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Backup
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
unless node.chef_environment == "development"
 | 
			
		||||
  node.override["backup"]["mysql"]["host"] = "localhost"
 | 
			
		||||
  node.override["backup"]["mysql"]["username"] = "root"
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user