Automation with phing

45
Presented by Joey Rivera

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 of Automation with phing

Page 1: Automation with phing

Presented by Joey Rivera

Page 2: Automation with phing

Introduction

• Joey Rivera• Manger of Technology Development

at Cengage Learning• http://www.joeyrivera.com• @joeyrivera

Page 3: Automation with phing

Summary

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

Page 4: Automation with phing

Problem

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

Page 5: Automation with phing

Problem Cont.

• We make mistakes• Manual process can be time

consuming• Busy work is no fun

Page 6: Automation with phing

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

Our Before

Page 8: Automation with phing

Our After

Page 9: Automation with phing

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

Why Phing

• Automation• Save time• Less errors• Tons of built-in

tasks and features

Page 11: Automation with phing

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

Dependencies

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

Page 13: Automation with phing

Using Phing

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

Page 14: Automation with phing

Build File

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

Page 15: Automation with phing

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

Example Build File

Page 16: Automation with phing

Project Node

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

Page 17: Automation with phing

Targets

• Grouping of tasks• Can depend on other tasks

Page 18: Automation with phing

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

Properties

• Variables• global vs. target specific• Declaration

– inline– external file– input

Page 20: Automation with phing

Built-in Properties

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

Page 21: Automation with phing

Property File

• Text file• Good way to

organize variables into one location

• Useful for environment specific files

Example:

Page 22: Automation with phing

Types

• Used within a task• More complex

data variables– FileSet• PatternSet• * vs. **

– Excludes

Example:

Page 23: Automation with phing

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

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

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

Custom Task

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

Page 27: Automation with phing

Examples

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

Page 28: Automation with phing

Version Control

• SVN• Git

Page 29: Automation with phing

Packaging

• Tar• Zip• PharPackage

Page 30: Automation with phing

Unit Testing

• PhpUnit• PhpUnitReport

Page 31: Automation with phing

Documentation

• PhpDocumentor2– http://www.phpdoc.org/

Page 32: Automation with phing

Documentation Cont.

Page 33: Automation with phing

Deploying

• Copy• Scp• FtpDeploy

Page 34: Automation with phing

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

DbDeploy cont.

• Create changelog table

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

Page 36: Automation with phing

DbDeploy Example

Deltas – each representing a version

Deploy file after running DbDeploy

Page 37: Automation with phing

DbDeploy Delta Example

Page 38: Automation with phing

Other

• Exec– Can run any system command– OS specific

Page 39: Automation with phing

Our Implementation

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

Page 40: Automation with phing

Restoring DB’s

• Dev, Test, Staging, QA, Prod• Environment specific data

Page 41: Automation with phing

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

Tagging

• From branch to Tag– Diff between rev of

last release and last tag of the same iteration

Page 43: Automation with phing

Before < After

Page 44: Automation with phing

Resources

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

• http://dbdeploy.com/• http://www.phpdoc.org/

Page 45: Automation with phing

Thanks!

• http://www.joeyrivera.com• @joeyrivera• Special thanks to my wife Ashley

Rivera (http://cargocollective.com/ashleyrivera ) for the graphics and template.