automation with phing
DESCRIPTION
Presentation for Codeworks 2012 Atlanta. This presentation went through what Phing is, how to set it up, example, and how we implemented it with our applications.TRANSCRIPT
![Page 1: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/1.jpg)
Presented by Joey Rivera
![Page 2: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/2.jpg)
Introduction
• Joey Rivera• Manger of Technology Development
at Cengage Learning• http://www.joeyrivera.com• @joeyrivera
![Page 3: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/3.jpg)
Summary
• Why we need Phing• Installing and Usage• Extending• Examples• Our implementations
![Page 4: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/4.jpg)
Problem
http://www.seniorark.com/Humor/Double%20Takes/crooked%20line.gif
![Page 5: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/5.jpg)
Problem Cont.
• We make mistakes• Manual process can be time
consuming• Busy work is no fun
![Page 6: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/6.jpg)
Our Goals
• Identify manual process at work– daily, weekly, monthly processes
• Analyze amount of time spent on those
• Automate them
![Page 7: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/7.jpg)
Our Before
![Page 8: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/8.jpg)
Our After
![Page 9: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/9.jpg)
Phing is
• PHing Is Not GNU make• Build tool based on Ant• XML based build files• Written in PHP5• Flexible and extendable• Platform independent
![Page 10: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/10.jpg)
Why Phing
• Automation• Save time• Less errors• Tons of built-in
tasks and features
![Page 11: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/11.jpg)
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
![Page 12: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/12.jpg)
Dependencies
http://www.phing.info/docs/guide/stable/
![Page 13: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/13.jpg)
Using Phing
• Command line– phing -v – phing -f buildfile– phing -f buildfile targetname– phing– phing -l– phing -debug
![Page 14: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/14.jpg)
Build File
• XML file– Project – Targets– Tasks– Types and properties– Filters–Mappers– Conditions
![Page 15: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/15.jpg)
http://www.phing.info/docs/guide/stable/
Example Build File
![Page 16: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/16.jpg)
Project Node
• Requires one per build.xml• Requires a default target declaration• Optional attributes:– name– basedir– description
![Page 17: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/17.jpg)
Targets
• Grouping of tasks• Can depend on other tasks
![Page 18: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/18.jpg)
Tasks
• Single piece of executable code• Core:
– Copy, Delete, Echo, Exec, Move, Foreach, and more
• Optional:– FtpDeploy, GitPush, PDOSQLExec,
Scp, Zip, and more
![Page 19: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/19.jpg)
Properties
• Variables• global vs. target specific• Declaration
– inline– external file– input
![Page 20: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/20.jpg)
Built-in Properties
http://www.phing.info/docs/guide/stable/
![Page 21: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/21.jpg)
Property File
• Text file• Good way to
organize variables into one location
• Useful for environment specific files
Example:
![Page 22: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/22.jpg)
Types
• Used within a task• More complex
data variables– FileSet• PatternSet• * vs. **
– Excludes
Example:
![Page 23: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/23.jpg)
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
![Page 24: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/24.jpg)
Conditions
• Used through the following two tasks:– condition– if
• Compare using– equals– isset– contrains– istrue– available
• Can nest– or– and– not
Example:
![Page 25: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/25.jpg)
Extending
• Can extend– Tasks– Types–Mappers– Ad hoc
$PHING_HOME |-- bin |-- classes | `-- phing | |-- filters | | `-- util | |-- mappers | |-- parser | |-- tasks | | |-- ext | | |-- system | | | `-- condition | | `-- user | `-- types |-- docs | `-- phing_guide `-- test |-- classes
`-- etc
![Page 26: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/26.jpg)
Custom Task
http://www.phing.info/docs/guide/stable/
![Page 27: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/27.jpg)
Examples
• Version Control• Packaging• Unit Testing• Documentation• Deployment• DbDeploy• Exec
![Page 28: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/28.jpg)
Version Control
• SVN• Git
![Page 29: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/29.jpg)
Packaging
• Tar• Zip• PharPackage
![Page 30: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/30.jpg)
Unit Testing
• PhpUnit• PhpUnitReport
![Page 32: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/32.jpg)
Documentation Cont.
![Page 33: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/33.jpg)
Deploying
• Copy• Scp• FtpDeploy
![Page 34: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/34.jpg)
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/
![Page 35: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/35.jpg)
DbDeploy cont.
• Create changelog table
http://www.phing.info/docs/guide/stable/
![Page 36: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/36.jpg)
DbDeploy Example
Deltas – each representing a version
Deploy file after running DbDeploy
![Page 37: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/37.jpg)
DbDeploy Delta Example
![Page 38: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/38.jpg)
Other
• Exec– Can run any system command– OS specific
![Page 39: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/39.jpg)
Our Implementation
• Restoring our DB’s• Automate SVN Exports• Automate Tagging
![Page 40: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/40.jpg)
Restoring DB’s
• Dev, Test, Staging, QA, Prod• Environment specific data
![Page 41: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/41.jpg)
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
![Page 42: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/42.jpg)
Tagging
• From branch to Tag– Diff between rev of
last release and last tag of the same iteration
![Page 43: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/43.jpg)
Before < After
![Page 44: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/44.jpg)
Resources
• http://www.phing.info/docs/guide/stable/
• http://dbdeploy.com/• http://www.phpdoc.org/
![Page 45: Automation with phing](https://reader036.vdocuments.site/reader036/viewer/2022081512/554de062b4c905d10e8b55b4/html5/thumbnails/45.jpg)
Thanks!
• http://www.joeyrivera.com• @joeyrivera• Special thanks to my wife Ashley
Rivera (http://cargocollective.com/ashleyrivera ) for the graphics and template.