Presented by Joey Rivera
Introduction

• Joey Rivera
• Manger of Technology Development at
  Cengage Learning
• http://www.joeyrivera.com
• @joeyrivera
Summary

•   Why we need Phing
•   Installing and Usage
•   Extending
•   Examples
•   Our implementations
Problem




  http://www.seniorark.com/Humor/Double%20Takes/crooked%20line.gif
Problem Cont.

• We make mistakes
• Manual process can be time consuming
• Busy work is no fun
Our Goals

• Identify manual process at work
  – daily, weekly, monthly processes
• Analyze amount of time spent on those
• Automate them
Our Before
Our After
Phing is

•   PHing Is Not GNU make
•   Build tool based on Ant
•   XML based build files
•   Written in PHP5
•   Flexible and extendable
•   Platform independent
Why Phing

•   Automation
•   Save time
•   Less errors
•   Tons of built-in
    tasks and features
Install

• http://www.phing.info
• PEAR install
  – pear channel-discover pear.phing.info
  – pear install phing/phing
  – Get necessary dependencies
• Non-PEAR Install
  – Download
  – Configure multiple env variables
Dependencies




     http://www.phing.info/docs/guide/stable/
Using Phing

• Command line
  – phing -v
  – phing -f buildfile
  – phing -f buildfile targetname
  – phing
  – phing -l
  – phing -debug
Build File

• XML file
  – Project
  – Targets
  – Tasks
  – Types and properties
  – Filters
  – Mappers
  – Conditions
Example Build File




        http://www.phing.info/docs/guide/stable/
Project Node

• Requires one per build.xml
• Requires a default target declaration
• Optional attributes:
  – name
  – basedir
  – description
Targets

• Grouping of tasks
• Can depend on other tasks
Tasks

• Single piece of executable
  code
• Core:
  – Copy, Delete, Echo, Exec, Mo
    ve, Foreach, and more
• Optional:
  – FtpDeploy, GitPush, PDOSQL
    Exec, Scp, Zip, and more
Properties

• Variables
• global vs. target specific
• Declaration
  – inline
  – external file
  – input
Built-in Properties




       http://www.phing.info/docs/guide/stable/
Property File

• Text file              Example:
• Good way to
  organize variables
  into one location
• Useful for
  environment specific
  files
Types

• Used within a task   Example:
• More complex data
  variables
  – FileSet
    • PatternSet
    • * vs. **
  – Excludes
Filters and Mappers
• Filters Transform data/file contents within a task
   – Tidy
   – ExpandProperty
   – StripPhpComments
• Mappers are like filters for files and directories
   – Flatten
   – Glob
   – RegExp
Conditions
• Used through the following
  two tasks:                   Example:
   – condition
   – if
• Compare using
   –   equals
   –   isset
   –   contrains
   –   istrue
   –   available
• Can nest
   – or
   – and
   – not
Extending      $PHING_HOME
                |-- bin
                |-- classes

• Can extend    | `-- phing
                |       |-- filters
                |       | `-- util
  – Tasks       |       |-- mappers
  – Types       |
                |
                        |-- parser
                        |-- tasks
  – Mappers     |       | |-- ext
                |       | |-- system
  – Ad hoc      |       | | `-- condition
                |       | `-- user
                |       `-- types
                |-- docs
                | `-- phing_guide
                `-- test
                    |-- classes
                             `-- etc
Custom Task




       http://www.phing.info/docs/guide/stable/
Examples

•   Version Control
•   Packaging
•   Unit Testing
•   Documentation
•   Deployment
•   DbDeploy
•   Exec
Version Control

• SVN
• Git
Packaging

• Tar
• Zip
• PharPackage
Unit Testing

• PhpUnit
• PhpUnitReport
Documentation

• PhpDocumentor2
  – http://www.phpdoc.org/
Documentation Cont.
Deploying

• Copy
• Scp
• FtpDeploy
Database Deployment

• DbDeploy
  – Database change management tool
  – Creates script file based on deltas
  – Tracks db version
  – Easy to move version forward or backwards
  – http://dbdeploy.com/
DbDeploy cont.

• Create changelog table




              http://www.phing.info/docs/guide/stable/
DbDeploy Example




Deltas – each representing   Deploy file after running DbDeploy
         a version
DbDeploy Delta Example
Other

• Exec
  – Can run any system command
  – OS specific
Our Implementation

• Restoring our DB’s
• Automate SVN Exports
• Automate Tagging
Restoring DB’s

• Dev, Test, Staging, QA, Prod
• Environment specific data
Automate SVN Exports

• Trunk to Dev
   – Export diff between last
     rev and newest rev
• ‘Release’ Branch to
  Testing
   – Export diff between last
     rev and newest rev
• Tag to
  Staging, QA, Prod
   – Export diff between last
     tag and newest tag
Tagging

• From branch to Tag
  – Diff between rev of last
    release and last tag of
    the same iteration
Before < After
Resources

• http://www.phing.info/docs/guide/stable/
• http://dbdeploy.com/
• http://www.phpdoc.org/
Thanks!

• http://www.joeyrivera.com
• @joeyrivera
• Special thanks to my wife Ashley Rivera
  (http://cargocollective.com/ashleyrivera )
  for the graphics and template.

Automation with phing

Editor's Notes

  • #5 Symbolizes we are not perfect.
  • #6 No challenge in manual busy work. Less attention given.
  • #7 At the end you get faster, more efficient processes, with less errors.&lt;mention ct deployer?&gt;
  • #9 Branching, Tagging, and several standalone servers for their own purpose.
  • #11 Saves you time, don’t need to reinvent the wheel
  • #14 not build file passed defaults to build.xml in current dirno target name passed defaults to project default target in build file
  • #18 logical grouping of tasks to achieve a goalmultiple depends with comma delimited
  • #19 Where the real work happens.Optional are installed through dependencies.You can create your own which will be covered later.
  • #20 Mention override=“true” to override property values.
  • #23 Excludes allows excluding files, class, and methods.
  • #24 ExpandProperty great to replace environment specific variablesFlatten remove directory from filename.Glob is copy/rename.RegExp replaces filename using expression.
  • #25 Can also have elseif and else.
  • #34 Talk about ssh keys for scp/ssh
  • #39 Good when there isn’t a task you need - and rather not create your own.
  • #41 Obfuscation.
  • #42 All cron’d but Prod
  • #44 Lean mean fighting machine.