ソースを参照

Vagrant support for simplifying testing

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24746 44c647ce-9c0f-0410-b52a-842ac1e357ba
rob 13 年 前
コミット
c19a6ba38e
5 ファイル変更337 行追加0 行削除
  1. 55 0
      DEVELOPMENT_README.txt
  2. 88 0
      Vagrantfile
  3. 90 0
      puppet/manifests/default.pp
  4. 14 0
      puppet/scripts/pe.sh
  5. 90 0
      puppet/scripts/php-build.sh

+ 55 - 0
DEVELOPMENT_README.txt

@@ -0,0 +1,55 @@
+Development using a virtual machine
+###################################
+
+You can set up a development virtual machine for ZF1 unit testing and library 
+development following these simple instructions.
+
+1. Install requirements for VM. (Note: these are not required by ZF1 itself)
+   - VirtualBox (https://www.virtualbox.org/)
+   - Ruby (http://www.ruby-lang.org/)
+   - Vagrant (http://vagrantup.com/)
+
+2. Checkout repository to any location
+   > svn checkout http://framework.zend.com/svn/framework/standard/trunk zf1-dev
+   > cd zf1-dev
+   
+3. Start the process by running Vagrant.
+   > vagrant up
+
+   This will take a long while as it has to download a VM image and then 
+   provision it. Once it has finished, it will exit and leave you back at the
+   command prompt.
+
+4. SSH into the VM
+   > vagrant ssh
+
+5. Build a version of PHP.
+   > php-build.sh 5.3.11
+
+   This also takes a while as it compiles PHP for you!
+   
+6. Select PHP to use:
+   > pe 5.3.11
+
+7. Run tests
+   > cd /vagrant/tests
+   > phpunit --stderr -d memory_limit=-1 Zend/Acl/AclTest.php
+   > phpunit --stderr -d memory_limit=-1 Zend/Amf/AllTests.php
+   (etc...)
+
+Note that you can repeat items 5 and 6 to create any version if PHP.
+
+   
+Notes:
+- The VM will be running in the background as VBoxHeadless
+- HTTP and SSH ports on the VM are forwarded to localhost (22 -> 2222, 80 -> 8081)
+- The zf1-dev directory you checked out will be mounted inside the VM at /vagrant
+- You can develop by editing the files you cloned in the IDE of you choice.
+- To stop the VM do one of the following:
+  > vagrant suspend   # if you plan on running it later
+  > vagrant halt      # if you wish to turn off the VM, but keep it around
+  > vagrant destroy   # if you wish to delete the VM completely
+- Also, when any of of the Puppet manifests change (.pp files), it is a good idea to rerun them:
+  > vagrant provision
+
+

+ 88 - 0
Vagrantfile

@@ -0,0 +1,88 @@
+# -*- mode: ruby -*-
+# vi: set ft=ruby :
+
+Vagrant::Config.run do |config|
+  # All Vagrant configuration is done here. The most common configuration
+  # options are documented and commented below. For a complete reference,
+  # please see the online documentation at vagrantup.com.
+
+  # Every Vagrant virtual environment requires a box to build off of.
+  config.vm.box = "lucid32"
+
+  # The url from where the 'config.vm.box' box will be fetched if it
+  # doesn't already exist on the user's system.
+  config.vm.box_url = "http://files.vagrantup.com/lucid32.box"
+
+  # Boot with a GUI so you can see the screen. (Default is headless)
+  #config.vm.boot_mode = :gui
+
+  # Assign this VM to a host-only network IP, allowing you to access it
+  # via the IP. Host-only networks can talk to the host machine as well as
+  # any other machines on the same network, but cannot be accessed (through this
+  # network interface) by any external networks.
+  # config.vm.network :hostonly, "192.168.33.10"
+
+  # Assign this VM to a bridged network, allowing you to connect directly to a
+  # network using the host's network device. This makes the VM appear as another
+  # physical device on your network.
+  # config.vm.network :bridged
+
+  # Forward a port from the guest to the host, which allows for outside
+  # computers to access the VM, whereas host only networking does not.
+  config.vm.forward_port 80, 8081
+
+
+  # Pass custom arguments to VBoxManage before booting VM
+  config.vm.customize [
+    # 'modifyvm', :id, '--chipset', 'ich9', # solves kernel panic issue on some host machines
+    # '--uartmode1', 'file', 'C:\\base6-console.log' # uncomment to change log location on Windows
+    "setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"
+  ]
+
+  # Share an additional folder to the guest VM. The first argument is
+  # an identifier, the second is the path on the guest to mount the
+  # folder, and the third is the path on the host to the actual folder.
+  # config.vm.share_folder "v-data", "/vagrant_data", "../data"
+
+  # Enable provisioning with Puppet stand alone.  Puppet manifests
+  # are contained in a directory path relative to this Vagrantfile.
+  # You will need to create the manifests directory and a manifest in
+  # the file lucid32.pp in the manifests_path directory.
+  #
+  # An example Puppet manifest to provision the message of the day:
+  #
+  # # group { "puppet":
+  # #   ensure => "present",
+  # # }
+  # #
+  # # File { owner => 0, group => 0, mode => 0644 }
+  # #
+  # # file { '/etc/motd':
+  # #   content => "Welcome to your Vagrant-built virtual machine!
+  # #               Managed by Puppet.\n"
+  # # }
+  #
+  # config.vm.provision :puppet do |puppet|
+  #   puppet.manifests_path = "manifests"
+  #   puppet.manifest_file  = "lucid32.pp"
+  # end
+
+
+  config.vm.provision :puppet do |puppet|
+    puppet.manifests_path = "puppet/manifests"
+    puppet.manifest_file  = "default.pp"
+  end
+
+#  config.vm.provision :puppet do |puppet|
+#    puppet.manifests_path = "puppet/manifests"
+#    puppet.module_path = "puppet/modules"
+#    puppet.manifest_file = "zf1.pp"
+#    puppet.options = [
+#      '--verbose',
+#      #'--debug',
+#      # '--graph',
+#      # '--graphdir=/vagrant/puppet/graphs'
+#    ]
+#  end  
+
+end

+ 90 - 0
puppet/manifests/default.pp

@@ -0,0 +1,90 @@
+group { "puppet":
+    ensure => "present",
+}
+
+File { owner => 0, group => 0, mode => 0644 }
+
+exec { 'update-apt':
+    command => "/usr/bin/apt-get update",
+}
+
+Exec["update-apt"] -> Package <| |>
+
+package { 'vim':
+    ensure => latest,
+    require => Exec["update-apt"],
+}
+
+package { 'curl':
+    ensure => latest,
+    require => Exec["update-apt"],
+}
+
+package { 'libxpm-dev':
+    ensure => latest,
+    require => Exec["update-apt"],
+}
+
+package { 'libmcrypt-dev':
+    ensure => latest,
+    require => Exec["update-apt"],
+}
+
+package { 'libbz2-dev':
+    ensure => latest,
+    require => Exec["update-apt"],
+}
+
+package { 'libcurl4-gnutls-dev':
+    ensure => latest,
+    require => Exec["update-apt"],
+}
+
+package { 'libjpeg62-dev':
+    ensure => latest,
+    require => Exec["update-apt"],
+}
+
+package { 'libpng12-dev':
+    ensure => latest,
+    require => Exec["update-apt"],
+}
+
+package { 'libfreetype6-dev':
+    ensure => latest,
+    require => Exec["update-apt"],
+}
+
+package { 'libt1-dev':
+    ensure => latest,
+    require => Exec["update-apt"],
+}
+
+package { 'libgmp3-dev':
+    ensure => latest,
+    require => Exec["update-apt"],
+}
+
+package { 'libmysqlclient-dev':
+    ensure => latest,
+    require => Exec["update-apt"],
+}
+
+package { 'libpq-dev':
+    ensure => latest,
+    require => Exec["update-apt"],
+}
+
+package { 'libpcre3-dev':
+    ensure => latest,
+    require => Exec["update-apt"],
+}
+
+$serial = "2012043001"
+$serialfile = "/var/log/pe-bashrc-update.serial"
+exec { "install-bashrc-update":
+    command => "/bin/cat /vagrant/puppet/scripts/pe.sh >> /home/vagrant/.bashrc \
+                && /bin/echo \"$serial\" > \"$serialfile\"",
+    unless  => "/usr/bin/test \"`/bin/cat $serialfile 2> /dev/null`\" = \"$serial\"",
+}
+

+ 14 - 0
puppet/scripts/pe.sh

@@ -0,0 +1,14 @@
+
+function pe () {
+        version=$1
+        shift
+
+        if [ "$#" == "0" ]; then
+                export PATH=/usr/local/php/${version}/bin:/usr/local/bin:/usr/bin:/bin:/vagrant/puppet/scripts
+        else
+                PATH=/usr/local/php/${version}/bin:$PATH $@
+        fi
+}
+
+export PATH=/vagrant/puppet/scripts/:$PATH
+

+ 90 - 0
puppet/scripts/php-build.sh

@@ -0,0 +1,90 @@
+#!/bin/bash
+
+VERSION=$1
+
+RESET=$2
+POSTFIX=
+EXTRA_FLAGS=
+
+if [ -z "$VERSION" ]; then
+    echo "Usage: php-build.sh {VERSION}"
+    echo ""
+    echo "e.g. php-build.sh 5.2.4"
+    exit;
+fi
+
+if [ -z "$RESET" ]; then
+    RESET=0
+fi
+
+
+SRC_DIR=/home/vagrant/src
+PHP_DIR=${SRC_DIR}/php-${VERSION}
+
+if [ ! -d "$SRC_DIR" ]; then 
+    mkdir ${SRC_DIR}
+fi
+cd $SRC_DIR
+
+# If we don't have the src file downloaded, then we're going to need it.
+if [ ! -f "php-${VERSION}.tar.gz" ]; then
+    RESET=1
+fi;
+
+# Retrieve source code 
+if [ $RESET -eq 1 ] ; then
+    echo "Downloading php-${VERSION}.tar.gz"
+    RESPONSE=$(curl --write-out %{http_code} --silent  --head --output /dev/null http://museum.php.net/php5/php-${VERSION}.tar.gz)
+    echo $RESPONSE
+    if [ $RESPONSE -eq 404 ]; then
+        wget -O php-${VERSION}.tar.gz http://uk3.php.net/get/php-${VERSION}.tar.gz/from/this/mirror
+    else
+        wget http://museum.php.net/php5/php-${VERSION}.tar.gz
+    fi
+
+    if [ ! -f php-${VERSION}.tar.gz ];
+    then
+        echo "Could not find php-${VERSION}.tar.gz"
+        exit;
+    fi
+    
+    rm -rf ${PHP_DIR}
+    tar -zxf php-${VERSION}.tar.gz
+fi
+
+cd $PHP_DIR
+echo "Configuring ${VERSION}${POSTFIX} in $PHP_DIR"
+
+# Configure 
+OPTIONS="--with-gd --with-jpeg-dir=/usr --with-xpm-dir=/usr --with-freetype-dir=/usr \
+    --with-mysql=/usr --enable-bcmath --with-gmp --with-readline \
+    --with-openssl --with-curl --without-esmtp \
+    --with-mysqli --enable-pcntl \
+    --enable-memory-limit --with-mcrypt --with-t1lib \
+    --enable-debug --with-iconv --enable-wddx --with-pdo-pgsql \
+    --enable-spl --enable-pdo --with-pdo-mysql --with-pdo-sqlite \
+    --with-ctype --with-bz2 --enable-mbstring --with-mime-magic \
+    --with-xmlrpc --with-zlib --disable-zend-memory-manager --with-esmtp \
+    --with-xsl --enable-exif --enable-soap --enable-ftp"
+
+./configure --prefix=/usr/local/php/${VERSION}${POSTFIX} ${EXTRA_FLAGS} ${OPTIONS}
+
+# Build and install
+echo "Building ${VERSION}${POSTFIX} in $PHP_DIR"
+make -j 5
+
+echo "Installing ${VERSION}${POSTFIX} in $PHP_DIR"
+sudo make install
+
+echo "Installing PHPUnit"
+export PATH=/usr/local/php/${VERSION}/bin:/usr/local/bin:/usr/bin:/bin:/vagrant/puppet/scripts
+sudo pear update-channels
+sudo pear upgrade-all
+sudo pear config-set auto_discover 1
+sudo pear install pear.phpunit.de/PHPUnit-3.4.15
+
+
+echo ""
+echo "PHP version ${VERSION} is now installed. Type: pe ${VERSION}"
+echo ""
+