Automate the deploy process with Phing
What is Phing?
Phing is a project build system based on Apache Ant. You can do anything with it that you could do with a traditional build system like GNU make. Phing uses easy to understand and simple XML build files, to configure your tasks. It's easy to extend Phing with your own filters and tasks.How it works?
Phing helps you to automate nearly all steps before you deploy a new project, or update a existing project. Phing isn't limited to do jobs with PHP files, PHP is only needed to run Phing.The build file is a simple to understand XML file, where you can add tasks to execute.
I'm using Phing to optimize my static files:
- optmize images with smush.it
- integrate layout images which are only used once in the CSS, directly into the CSS (data URI's and for IE < 8 a MHTML document)
- merge CSS and Javascript files, to make fewer HTTP requests
- compress merged CSS and Jacascript with the YUICompressor
Following an example build file
<project name="betalon" default="static" basedir="/home/betalon">
<!-- prepare build directory for static files -->
<target name="static">
<property name="static.sourceDir" value="${project.basedir}/static/source" override="true" />
<property name="static.releaseDir" value="${project.basedir}/static/release" override="true" />
<echo msg="Empty the release directory" />
<delete dir="${static.releaseDir}" includeemptydirs="true" verbose="false" failonerror="true" />
<echo msg="Create the release directory" />
<mkdir dir="${static.releaseDir}" />
<!-- image files -->
<property name="static.img.releaseDir" value="${static.releaseDir}/img" override="true" />
<mkdir dir="${static.img.releaseDir}" />
<copy todir="${static.img.releaseDir}" >
<fileset dir="${static.sourceDir}/img" />
</copy>
<!-- css files -->
<property name="static.css.releaseDir" value="${static.releaseDir}/css" override="true" />
<mkdir dir="${static.css.releaseDir}" />
<!-- create screen.css -->
<property name="static.css.file.screen" value="${static.css.releaseDir}/screen.css" override="true" />
<append destFile="${static.css.file.screen}">
<filelist dir="${static.sourceDir}/css" files="screen.css,syntaxhighlighter/shCore.css,syntaxhighlighter/shThemeDefault.css"/>
</append>
<copy file="${static.sourceDir}/css/iepngfix.htc" tofile="${static.css.releaseDir}/iepngfix.htc" overwrite="true"/>
<!-- rewrite pathes and compress merged files -->
<reflexive>
<fileset dir="${static.css.releaseDir}">
<include name="*.css" />
</fileset>
<filterchain>
<replaceregexp>
<regexp pattern="\/static\/source\/" replace="/static/release/" ignoreCase="true"/>
</replaceregexp>
</filterchain>
<filterchain>
<filterreader classname="phing.filters.CssEmbedBase64Image">
<param name="documentRoot" value="${project.basedir}" />
<param name="hostname" value="www.betalon.com" />
<param name="basePath" value="${project.basedir}" />
<!-- exclude because of the IEPNG Hack for IE6 witch doesn't work with inline images -->
<param name="exclude" value="/logo.png/" />
</filterreader>
</filterchain>
</reflexive>
<!-- javascript files -->
<property name="static.js.releaseDir" value="${static.releaseDir}/js" override="true" />
<mkdir dir="${static.js.releaseDir}" />
<!-- create main.js // is loaded on every page -->
<property name="static.js.file.syntaxhighlighter" value="${static.js.releaseDir}/main.js" override="true" />
<append destFile="${static.js.file.syntaxhighlighter}">
<filterchain>
<replaceregexp>
<regexp pattern="\/static\/source\/" replace="/static/release/" ignoreCase="true"/>
</replaceregexp>
</filterchain>
<filelist dir="${static.sourceDir}/js" files="init.js,swfobject.js,imagereplace.js" />
<filelist dir="${static.sourceDir}/js/syntaxhighlighter" files="shCore.js,shBrushJScript.js,shBrushXml.js,shBrushPhp.js,shBrushCss.js,shBrushSql.js"/>
</append>
<!-- rewrite pathes and compress merged files -->
<reflexive>
<fileset dir="${static.js.releaseDir}" />
<filterchain>
<replaceregexp>
<regexp pattern="\/static\/source\/" replace="/static/release/" ignoreCase="true"/>
</replaceregexp>
</filterchain>
</reflexive>
<!-- SWF files -->
<property name="static.swf.releaseDir" value="${static.releaseDir}/swf" override="true" />
<mkdir dir="${static.swf.releaseDir}" />
<copy todir="${static.swf.releaseDir}" >
<fileset dir="${static.sourceDir}/swf" />
</copy>
</target>
</project>
Conclusion
Phing is great, it helps me to save much of time, and helps to improve the performance of my website with less work.Try it: www.phing.info
headline1
Jan 23, 2010 10:14:08 PM
ciprofloxacin dot not take :-PPP omeprazole corn starch utaa dangers of ativan >:-]] celebrex and hypertension 2766 razobazam anxiety :PP
Leave a comment