From af6fe37e0b55de177acd486981fcaeb3ff81ce4b Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Fri, 1 Jun 2018 17:04:15 +0200 Subject: [PATCH] Add Composer, Mermaid extension --- Berksfile | 1 + Berksfile.lock | 5 + cookbooks/composer/README.md | 187 ++++++++++++++++++ cookbooks/composer/attributes/default.rb | 29 +++ cookbooks/composer/libraries/composer.rb | 10 + cookbooks/composer/metadata.json | 63 ++++++ .../composer/providers/install_global.rb | 78 ++++++++ cookbooks/composer/providers/project.rb | 125 ++++++++++++ cookbooks/composer/recipes/default.rb | 12 ++ cookbooks/composer/recipes/global_configs.rb | 45 +++++ cookbooks/composer/recipes/install.rb | 36 ++++ cookbooks/composer/recipes/self_update.rb | 16 ++ .../composer/resources/install_global.rb | 24 +++ cookbooks/composer/resources/project.rb | 29 +++ site-cookbooks/kosmos-mediawiki/metadata.rb | 1 + .../kosmos-mediawiki/recipes/default.rb | 40 ++++ 16 files changed, 701 insertions(+) create mode 100644 cookbooks/composer/README.md create mode 100644 cookbooks/composer/attributes/default.rb create mode 100644 cookbooks/composer/libraries/composer.rb create mode 100644 cookbooks/composer/metadata.json create mode 100644 cookbooks/composer/providers/install_global.rb create mode 100644 cookbooks/composer/providers/project.rb create mode 100644 cookbooks/composer/recipes/default.rb create mode 100644 cookbooks/composer/recipes/global_configs.rb create mode 100755 cookbooks/composer/recipes/install.rb create mode 100644 cookbooks/composer/recipes/self_update.rb create mode 100644 cookbooks/composer/resources/install_global.rb create mode 100644 cookbooks/composer/resources/project.rb diff --git a/Berksfile b/Berksfile index 86e0bb0..88871ab 100644 --- a/Berksfile +++ b/Berksfile @@ -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' diff --git a/Berksfile.lock b/Berksfile.lock index a5194c6..26823ae 100644 --- a/Berksfile.lock +++ b/Berksfile.lock @@ -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) diff --git a/cookbooks/composer/README.md b/cookbooks/composer/README.md new file mode 100644 index 0000000..d41686e --- /dev/null +++ b/cookbooks/composer/README.md @@ -0,0 +1,187 @@ +[![Build Status](https://travis-ci.org/djoos-cookbooks/composer.png)](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 +Copyright: 2016, David Joos + +Author: David Joos +Author: Escape Studios Development +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. diff --git a/cookbooks/composer/attributes/default.rb b/cookbooks/composer/attributes/default.rb new file mode 100644 index 0000000..bb99dca --- /dev/null +++ b/cookbooks/composer/attributes/default.rb @@ -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' diff --git a/cookbooks/composer/libraries/composer.rb b/cookbooks/composer/libraries/composer.rb new file mode 100644 index 0000000..f9e3abc --- /dev/null +++ b/cookbooks/composer/libraries/composer.rb @@ -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 diff --git a/cookbooks/composer/metadata.json b/cookbooks/composer/metadata.json new file mode 100644 index 0000000..d86a891 --- /dev/null +++ b/cookbooks/composer/metadata.json @@ -0,0 +1,63 @@ +{ + "name": "composer", + "description": "Installs/Configures Composer", + "long_description": "[![Build Status](https://travis-ci.org/djoos-cookbooks/composer.png)](https://travis-ci.org/djoos-cookbooks/composer)\n\n# composer cookbook\n\n## Description\n\nThis cookbook provides an easy way to install Composer, a dependency manager for PHP.\n\nMore information?\nhttp://getcomposer.org/\n\n## Requirements\n\n### Cookbooks:\n\n* php\n* windows\n\n### Platforms:\n\n* Ubuntu\n* Debian\n* RHEL\n* CentOS\n* Fedora\n* Windows\n\n## Attributes\n\n* `node['composer']['url']` - Location of the source\n* `node['composer']['install_dir']` - Installation target directory (absolute or relative path) if installing locally\n* `node['composer']['bin']` - bin directory\n* `node['composer']['install_globally']` - Installation method, ':source' or ':package' - default true\n* `node['composer']['mask']` - Mask for composer.phar - 0755\n* `node['composer']['link_type']` - link type for composer.phar link - default :symbolic\n* `node['composer']['global_configs']` - Hash with global config options for users, eg. { \"userX\" => { \"github-oauth\" => { \"github.com\" => \"userX_oauth_token\" }, \"vendor-dir\" => \"myvendordir\" } } - default {}\n* `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\n* `node['composer']['php_recipe']` - The php recipe to include, defaults to \"php::default\"\n* `node['composer']['global_install']['install_dir']` - The default location to install the packages in for composer_install_global\n* `node['composer']['global_install']['bin_dir']` - The default location to symlink the binaries when using composer_install_global\n\n## Resources / Providers\nThis cookbook includes an LWRP for managing a Composer project and one for a global installation of composer packages\n\n### `composer_project`\n\n#### Actions\n- :install: Reads the composer.json file from the current directory, resolves the dependencies, and installs them into project directory - this is the default action\n- :require Create composer.json file using specified package and version and installs it with the dependencies.\n- :update: Gets the latest versions of the dependencies and updates the composer.lock file\n- :dump_autoload: Updates the autoloader without having to go through an install or update (eg. because of new classes in a classmap package)\n- :remove Removes package from composer.json and uninstalls it\n\n#### Attribute parameters\n- project_dir: The directory where your project's composer.json can be found (name attribute)\n- package: The package to require or remove when using those actions\n- 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!\n- vendor: Can be used to combine package and version, deprecated!\n- dev: Install packages listed in require-dev, default false\n- quiet: Do not output any message, default true\n- optimize_autoloader: Optimize PSR0 packages to use classmaps, default false\n- prefer_dist: use the dist installation method\n- prefer_source: use the source installation method\n- bin_dir, overwrites the composer bin dir\n- user: the user to use when executing the composer commands\n- group: the group to use when executing the composer commands\n- umask: the umask to use when executing the composer commands\n- environment: A hash of environment variables that will be available when running composer\n\n#### Examples\n```\n# Install the project dependencies\ncomposer_project \"/path/to/project\" do\n dev false\n quiet true\n prefer_dist false\n action :install\nend\n\n# Require the package in the project dir\ncomposer_project \"/path/to/project\" do\n package 'vendor/package'\n version '*.*.*'\n dev false\n quiet true\n prefer_dist false\n action :require\nend\n\n# Update the project dependencies\ncomposer_project \"/path/to/project\" do\n dev false\n quiet true\n action :update\nend\n\n# Dump-autoload in the project dir\ncomposer_project \"/path/to/project\" do\n dev false\n quiet true\n action :dump_autoload\nend\n\n# Remove the package in the project dir\ncomposer_project \"/path/to/project\" do\n package 'vendor/package'\n action :remove\nend\n```\n\n### `composer_install_global`\n\n#### Actions\n- :install: Installs the package in the preferred global composer directory, putting binary symlinks in the preferred global binary directory (see attributes)\n- :update: Gets the latest versions of the dependencies and updates the composer.lock file for the globally installed composer packages\n- :remove Removes package from the global composer.json and uninstalls it\n\n#### Attribute parameters\n- package: The package to install or remove, name_attribute\n- 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!\n- install_dir: the directory in which to make the global installation, default: see the attributes\n- bin_dir: the directory in which to make the symlinks to the binaries, default: see the attributes\n- dev: Install packages listed in require-dev, default false\n- quiet: Do not output any message, default true\n- optimize_autoloader: Optimize PSR0 packages to use classmaps, default false\n- prefer_dist: use the dist installation method\n- prefer_source: use the source installation method\n\n#### Examples\n```\n# Install a package globally\ncomposer_install_global \"package\" do\n version '~4.1'\n action :install\nend\n\n# Update the package\ncomposer_install_global \"package\" do\n action :update\nend\n\n# Remove the package from the global installation\ncomposer_install_global \"package\" do\n action :remove\nend\n```\n\n## Usage\n\n1. include `recipe[composer]` in a run list\n2. tweak the attributes via attributes/default.rb\n--- OR ---\n[override the attribute on a higher level](http://wiki.opscode.com/display/chef/Attributes#Attributes-AttributesPrecedence)\n\n## References\n\n* [Composer home page] (http://getcomposer.org/)\n\n## License and Authors\n\nAuthor: David Joos \nCopyright: 2016, David Joos\n\nAuthor: David Joos \nAuthor: Escape Studios Development \nCopyright: 2012-2015, Escape Studios\n\nUnless otherwise noted, all files are released under the MIT license,\npossible exceptions will contain licensing information in them.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n", + "maintainer": "David Joos", + "maintainer_email": "development@davidjoos.com", + "license": "MIT", + "platforms": { + "debian": ">= 0.0.0", + "ubuntu": ">= 0.0.0", + "redhat": ">= 0.0.0", + "centos": ">= 0.0.0", + "fedora": ">= 0.0.0", + "scientific": ">= 0.0.0", + "amazon": ">= 0.0.0", + "windows": ">= 0.0.0" + }, + "dependencies": { + "apt": ">= 0.0.0", + "php": ">= 0.0.0", + "windows": ">= 0.0.0" + }, + "recommendations": { + + }, + "suggestions": { + + }, + "conflicting": { + + }, + "providing": { + + }, + "replacing": { + + }, + "attributes": { + + }, + "groupings": { + + }, + "recipes": { + "composer": "Installs (if applicable) and self-updates composer.", + "composer::install": "Installs composer.", + "composer::self_update": "Installs (if applicable) and self-updates composer.", + "composer::global_configs": "Sets up global config options via `composer config --global`" + }, + "version": "2.6.1", + "source_url": "https://github.com/djoos-cookbooks/composer", + "issues_url": "https://github.com/djoos-cookbooks/composer/issues", + "privacy": false, + "chef_versions": [ + + ], + "ohai_versions": [ + + ], + "gems": [ + + ] +} diff --git a/cookbooks/composer/providers/install_global.rb b/cookbooks/composer/providers/install_global.rb new file mode 100644 index 0000000..8022a64 --- /dev/null +++ b/cookbooks/composer/providers/install_global.rb @@ -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 diff --git a/cookbooks/composer/providers/project.rb b/cookbooks/composer/providers/project.rb new file mode 100644 index 0000000..11064ad --- /dev/null +++ b/cookbooks/composer/providers/project.rb @@ -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 diff --git a/cookbooks/composer/recipes/default.rb b/cookbooks/composer/recipes/default.rb new file mode 100644 index 0000000..d2981ca --- /dev/null +++ b/cookbooks/composer/recipes/default.rb @@ -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 diff --git a/cookbooks/composer/recipes/global_configs.rb b/cookbooks/composer/recipes/global_configs.rb new file mode 100644 index 0000000..6a92623 --- /dev/null +++ b/cookbooks/composer/recipes/global_configs.rb @@ -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 diff --git a/cookbooks/composer/recipes/install.rb b/cookbooks/composer/recipes/install.rb new file mode 100755 index 0000000..477b418 --- /dev/null +++ b/cookbooks/composer/recipes/install.rb @@ -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 diff --git a/cookbooks/composer/recipes/self_update.rb b/cookbooks/composer/recipes/self_update.rb new file mode 100644 index 0000000..25d1bc1 --- /dev/null +++ b/cookbooks/composer/recipes/self_update.rb @@ -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 diff --git a/cookbooks/composer/resources/install_global.rb b/cookbooks/composer/resources/install_global.rb new file mode 100644 index 0000000..93f259d --- /dev/null +++ b/cookbooks/composer/resources/install_global.rb @@ -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 diff --git a/cookbooks/composer/resources/project.rb b/cookbooks/composer/resources/project.rb new file mode 100644 index 0000000..1780ef2 --- /dev/null +++ b/cookbooks/composer/resources/project.rb @@ -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 diff --git a/site-cookbooks/kosmos-mediawiki/metadata.rb b/site-cookbooks/kosmos-mediawiki/metadata.rb index 5b654b0..e97b9d2 100644 --- a/site-cookbooks/kosmos-mediawiki/metadata.rb +++ b/site-cookbooks/kosmos-mediawiki/metadata.rb @@ -9,5 +9,6 @@ version '0.1.0' depends "mediawiki" depends "ark" depends "backup" +depends "composer" depends "kosmos-nginx" depends "kosmos-base" diff --git a/site-cookbooks/kosmos-mediawiki/recipes/default.rb b/site-cookbooks/kosmos-mediawiki/recipes/default.rb index 3ff20e7..cf37b16 100644 --- a/site-cookbooks/kosmos-mediawiki/recipes/default.rb +++ b/site-cookbooks/kosmos-mediawiki/recipes/default.rb @@ -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"