Permalink
Browse files

Merge branch 'php_extensions'

  • Loading branch information...
2 parents 25a6116 + dd43bd0 commit 1e2876374a7344758db639e816f42e7fb82ce96e @loicfrering loicfrering committed Mar 5, 2013
@@ -1,2 +1,39 @@
default[:php][:multi][:versions] = ["5.2.17", "5.3.3", "5.3.22", "5.4.12", "5.5.0alpha4"]
default[:php][:multi][:aliases] = {"5.2" => "5.2.17", "5.3" => "5.3.22", "5.4" => "5.4.12", "5.5" => "5.5.0alpha4"}
+
+default[:php][:multi][:extensions] = {
+ 'apc' => {
+ 'versions' => default[:php][:multi][:versions].reject { |version| version.start_with?("5.5") }
+ },
+ 'memcache' => {
+ 'versions' => default[:php][:multi][:versions].reject { |version| version.start_with?("5.5") }
+ },
+ 'memcached' => {
+ 'versions' => default[:php][:multi][:versions].reject { |version| version.start_with?("5.5") },
+ 'before_packages' => %w(libevent-dev libcloog-ppl0),
+ 'before_script' => <<-EOF
+ wget https://launchpad.net/libmemcached/1.0/1.0.16/+download/libmemcached-1.0.16.tar.gz
+ tar xzf libmemcached-1.0.16.tar.gz
+ cd libmemcached-1.0.16
+ ./configure && make && make install
+ EOF
+ },
+ 'mongo' => {
+ 'versions' => default[:php][:multi][:versions].reject { |version| version.start_with?("5.5") }
+ },
+ 'amqp' => {
+ 'versions' => default[:php][:multi][:versions].reject { |version| version.start_with?("5.5") },
+ 'before_script' => <<-EOF
+ git clone git://github.com/alanxz/rabbitmq-c.git
+ cd rabbitmq-c
+ git submodule init
+ git submodule update
+ autoreconf -i && ./configure && make && make install
+ EOF
+ },
+ 'pear.zero.mq/zmq-beta' => {
+ 'versions' => default[:php][:multi][:versions].reject { |version| version.start_with?("5.5") },
+ 'channel' => 'pear.zero.mq',
+ 'before_packages' => %w(libzmq-dev)
+ }
+}
@@ -0,0 +1,69 @@
+action :install do
+ new_resource = @new_resource
+ extension = new_resource.extension
+ versions = new_resource.versions
+
+ new_resource.before_packages.each do |pkg|
+ package pkg do
+ action :install
+ end
+ end
+
+ bash "before installing PECL extension #{extension} script" do
+ user "root"
+ cwd "/tmp"
+ code new_resource.before_script
+ only_if do
+ new_resource.before_script && !new_resource.before_script.empty?
+ end
+ end
+
+ versions.each do |php_version|
+ bash "install PECL extension #{extension} for PHP #{php_version}" do
+ user new_resource.owner
+ group new_resource.group
+ environment Hash["HOME" => node.travis_build_environment.home]
+ code <<-EOF
+ source /etc/profile.d/phpenv.sh
+ phpenv global #{php_version}
+
+ if [ ! -z "#{new_resource.channel}" ]; then
+ pear channel-discover #{new_resource.channel}
+ fi
+
+ pecl info #{extension}
+ return=$?
+ if [ $return = 0 ]; then
+ echo "Extension #{extension} was already installed for PHP #{php_version}."
+ elif [ $return = 1 ]; then
+ result=$(pecl install #{extension} | tail -1)
+ if [[ "$result" =~ ^ERROR: ]]; then
+ echo "There was an error installing extension #{extension} for PHP #{php_version}:"
+ echo "$result"
+ exit 1
+ fi
+ echo "Extension #{extension} successfully installed for PHP #{php_version}."
+ else
+ echo "There was an error installing extension #{extension} for PHP #{php_version}."
+ exit 1
+ fi
+ EOF
+ end
+ end
+end
+
+action :uninstall do
+ new_resource = @new_resource
+ extension = new_resource.extension
+ versions = new_resource.versions
+
+ versions.each do |php_version|
+ bash "uninstall PECL extension #{extension} for PHP #{php_version}" do
+ user new_resource.owner
+ group new_resource.group
+ code <<-EOF
+ pecl uninstall #{extension}
+ EOF
+ end
+ end
+end
@@ -0,0 +1,24 @@
+include_recipe "phpenv"
+include_recipe "phpbuild"
+
+node.php.multi.extensions.each do |php_extension, options|
+ php_pecl php_extension do
+ channel options['channel']
+ versions options['versions'] || node.php.multi.versions
+ before_packages options['before_packages']
+ before_script options['before_script']
+ owner node.travis_build_environment.user
+ group node.travis_build_environment.group
+
+ action :install
+ end
+end
+
+node.php.multi.versions.each do |php_version|
+ bash "disable preinstalled PECL extensions for PHP #{php_version}" do
+ user node.travis_build_environment.user
+ group node.travis_build_environment.group
+ environment Hash["HOME" => node.travis_build_environment.home]
+ code "sed -i '/^extension=/d' $HOME/.phpenv/versions/#{php_version}/etc/php.ini"
+ end
+end
@@ -22,4 +22,5 @@
end
end
+include_recipe "php::extensions"
include_recipe "composer"
@@ -0,0 +1,9 @@
+actions :install, :uninstall
+
+attribute :extension, :kind_of => String, :name_attribute => true
+attribute :channel, :kind_of => String
+attribute :versions, :kind_of => Array
+attribute :before_packages, :kind_of => Array, :default => []
+attribute :before_script, :kind_of => String
+attribute :owner, :regex => Chef::Config[:user_valid_regex]
+attribute :group, :regex => Chef::Config[:group_valid_regex]
@@ -0,0 +1,6 @@
+default[:phpenv] = {
+ :git => {
+ :repository => "git://github.com/CHH/phpenv.git",
+ :revision => "a3091e84de6dd2c61ea1bdb96cf3053c62740a3f"
+ }
+}
@@ -1,21 +1,25 @@
include_recipe "git"
+phpenv_path = "#{node.travis_build_environment.home}/.phpenv"
-remote_file "/tmp/phpenv-install.sh" do
- source "https://raw.github.com/CHH/phpenv/master/bin/phpenv-install.sh"
- mode "0755"
+git "/tmp/phpenv" do
+ user node.travis_build_environment.user
+ group node.travis_build_environment.group
+ repository node[:phpenv][:git][:repository]
+ revision node[:phpenv][:git][:revision]
+ action :checkout
end
bash "install phpenv" do
user node.travis_build_environment.user
group node.travis_build_environment.group
- environment Hash["HOME" => node.travis_build_environment.home]
code <<-EOF
- . /tmp/phpenv-install.sh
+ PHPENV_ROOT="#{phpenv_path}" . /tmp/phpenv/bin/phpenv-install.sh
+ cp /tmp/phpenv/extensions/rbenv-config-add /tmp/phpenv/extensions/rbenv-config-rm "#{phpenv_path}/libexec"
EOF
- not_if "test -f #{node.travis_build_environment.home}/.phpenv/bin/phpenv"
+ not_if "test -f #{phpenv_path}/bin/phpenv"
end
-directory "#{node.travis_build_environment.home}/.phpenv/versions" do
+directory "#{phpenv_path}/versions" do
owner node.travis_build_environment.user
group node.travis_build_environment.group
mode "0755"

0 comments on commit 1e28763

Please sign in to comment.