Automation with phing

Post on 09-May-2015

2.071 views 0 download

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

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

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

Example Build File

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, Move, Foreach, and more

• Optional:– FtpDeploy, GitPush, PDOSQLExec,

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• Good way to

organize variables into one location

• Useful for environment specific files

Example:

Types

• Used within a task• More complex

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

– Excludes

Example:

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:– condition– if

• Compare using– equals– isset– contrains– istrue– available

• Can nest– or– and– not

Example:

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

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 a version

Deploy file after running DbDeploy

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.