SlideShare une entreprise Scribd logo
1  sur  28
Phing
           Automating PHP build deployment




09/07/12             http://coderinsights.blogspot.in   1
Old Way




09/07/12   http://coderinsights.blogspot.in   2
Why use Build Automation?
“We are human, We get bored,
We forget things, We make mistakes”

•   Improve product quality
•   Consolidate scripts
•   Eliminate repetitive tasks
•   Minimize error (bad builds)
•   Eliminate dependencies (Easier handover)
•   Highly extendible
•   Saves time

09/07/12                http://coderinsights.blogspot.in   3
What is [PHing Is Not Gnumake]
•   It's a PHP project build tool based on Apache Ant
•   Opensource
•   Mostly Cross platform
•   Uses XML build files
•   No required external dependencies
•   Built & optimised for PHP5




09/07/12              http://coderinsights.blogspot.in   4
What can you do?
•   Lots –Not just for deployment
•   SVN tasks
•   PHPUnit/SimpleTest
•   Code analysis tasks
•   PhpDocumentor
•   Zip/Unzip
•   File manipulation
•   Various OS tasks

09/07/12           http://coderinsights.blogspot.in   5
Features




09/07/12   http://coderinsights.blogspot.in   6
Phing Philosophy
• Build scripts contains "Targets"
      – Targets should be small and specialized.
      – Example Targets:
           • clean
              – Clear temporary and cached files
           • copy
              – Copy files to their intended destination
           • migrate
              – Upgrade the database schema



09/07/12                      http://coderinsights.blogspot.in   7
Phing Philosophy
• Targets can have dependencies
      – Target "live" can depend on clean, copy, and
        migrate
      – Meaning, when we run the "live" target, it first
        runs clean, copy, then migrate
           • And any tasks they depend on




09/07/12                   http://coderinsights.blogspot.in   8
Installing Phing
• pear channel-discover pear.phing.info
• pear install phing/Phing
• Want all the dependencies?
      –    pear   config-set preferred_state alpha
      –    pear   install –alldeps phing/Phing
      –    pear   config-set preferred_state stable
      –    pear   install phing/phingdocs
• Also available from:
      – SVN
      – Zip Download

09/07/12                 http://coderinsights.blogspot.in   9
Running Phing
• $> phing –v
      – Lists Phing version
• Phing expects to find a file "build.xml" in the
  current directory
      – build.xml defines the targets
      – You can use the "-f <filename>" flag to
        specify an alternate build file like
           • $> phing -f build-live.xml


09/07/12                http://coderinsights.blogspot.in   10
Syntax
• Build File uses XML
• Standard Elements
      – Task: code that performs a specific function
      – Target: groups of tasks
      – Project: root node
• Variables
      – ${variablename}
      – Conventions
           • Psuedo-Namespaces using periods
           • ${namespace.variable.name}

09/07/12                  http://coderinsights.blogspot.in   11
Basic Conventions
• build.xml
      – Central repository of your top-level tasks
• build-*.xml
      – Can be included into build.xml.
      – Usually for grouping by target (dev, staging,prod)
        or task (migrate, test, etc.)
• build.properties
      – Technically an INI file that contains variables to be
        included by build files.

09/07/12                http://coderinsights.blogspot.in     12
Basic build.xml
  <?xml version="1.0" encoding="UTF-8"?>
  <project name=“opx" default="default" basedir=".">
      <property file="build.properties" />
      <target name="default">
          <echo message="Hello World!" />
      </target>
  </project>




09/07/12              http://coderinsights.blogspot.in   13
Basic build.properties
  source.directory = /mnt/work/

  ## Database Configuration
  db.user = username
  db.pass = password
  db.host = localhost
  db.name = database


   Usage:
   $phing –propertyfile build.properties




09/07/12                        http://coderinsights.blogspot.in   14
Most Useful Elements
• Filesets: define once,use many
      <fileset id="src_crons" dir="${dir.crons_path}/statistic-engine/">
              <include name="*.php"/>
              <exclude name="populate_opx_tables.php" />
      </fileset>


• Mappers & Filters: Transform files during
  copy/move/…
      <copy todir="${build}">
             <fileset refid="files"/>
                     <mapper type="glob" from="*.txt" to="*.new.txt"/>
                     <filterchain>
                             <replaceregexp>
                             <regexp pattern="rn" replace="n"/>
                     <expandproperties/>
                     </replaceregexp>
             </filterchain>
      </copy>



09/07/12                                        http://coderinsights.blogspot.in   15
Executing External Tools
• Nearly all file transfer tools will be external
  commands
• For this we need the Exec task
      <exec command="cp file1 file2" />




09/07/12                http://coderinsights.blogspot.in   16
Examples
SVN, Git
<svncopy username=“pavan“ password="test” repositoryurl="svn://localhost/phing/trunk/“
    todir="svn://localhost/phing/tags/1.0"/>

<svnexport repositoryurl="svn://localhost/project/trunk/” todir="/home/pavan/dev"/>

<svnlastrevision repositoryurl="svn://localhost/project/trunk/” propertyname="lastrev"/>
<echo>Last revision: ${lastrev}</echo>

<svnlastrevision repositoryurl="${deploy.svn}” property="deploy.rev"/>

<svnexport repositoryurl="${deploy.svn}" todir="/www/releases/build-${deploy.rev}"/>




09/07/12                           http://coderinsights.blogspot.in                        17
Examples
Packaging – Tar/Zip
<tar compression="gzip" destFile="package.tgz" basedir="build"/>
    <zip destfile="htmlfiles.zip">
    <fileset dir=".">
            <include name="**/*.html"/>
    </fileset>
</zip>




09/07/12                           http://coderinsights.blogspot.in   18
Examples
Documentation:
      – DocBlox
      – PhpDocumentor
      – ApiGen

<docblox title="Phing API Documentation"
output="docs" quiet="true">
<fileset dir="../../classes">
     <include name="**/*.php"/>
</fileset>
</docblox>


09/07/12                          http://coderinsights.blogspot.in   19
Examples
• SCP/FTP
<scp username="john" password="smith" host="webserver" todir="/www/htdocs/project/">
    <fileset dir="test">
            <include name="*.html"/>
    </fileset>
</scp>

<ftpdeploy host="server01” username="john" password="smit" dir="/var/www">
    <fileset dir=".">
            <include name="*.html"/>
    </fileset>
</ftpdeploy>




09/07/12                         http://coderinsights.blogspot.in                      20
Database Migrations
• Set of delta SQL files (1-create-post.sql)
• Tracks current version of your db in changelog
  table
• Generates do and undo SQL files
CREATE TABLE changelog (
change_number BIGINT NOT NULL,
delta_set VARCHAR(10) NOT NULL,
start_dt TIMESTAMP NOT NULL,
complete_dt TIMESTAMP NULL,
applied_by VARCHAR(100) NOT NULL,
description VARCHAR(500) NOT NULL
)

09/07/12                  http://coderinsights.blogspot.in   21
Database Migrations
• Delta scripts with do (up) & undo (down) parts
-- //
CREATE TABLE ‘post‘ (
‘title‘ VARCHAR(255),
‘time_created‘ DATETIME,
‘content‘ MEDIUMTEXT
);
-- //@UNDO
DROP TABLE ‘post‘;
-- //




09/07/12                   http://coderinsights.blogspot.in   22
Database Migrations
<dbdeploy
url="sqlite:test.db"
dir="deltas"
outputfile="deploy.sql"
undooutputfile="undo.sql"/>

<pdosqlexec
src="deploy.sql"
url="sqlite:test.db"/>

Buildfile: /home/pavan/dbdeploy/build.xml
Demo > migrate:
[dbdeploy] Getting applied changed numbers from DB:
mysql:host=localhost;dbname=demo
[dbdeploy] Current db revision: 0
[dbdeploy] Checkall:
[pdosqlexec] Executing file: /home/michiel/dbdeploy/deploy.sql
[pdosqlexec] 3 of 3 SQL statements executed successfully
BUILD FINISHED



09/07/12                                       http://coderinsights.blogspot.in   23
Database Migrations
-- Fragment begins: 1 --
INSERT INTO changelog
(change_number, delta_set, start_dt, applied_by, description)
VALUES (1, ’Main’, NOW(), ’dbdeploy’,
’1-create_initial_schema.sql’);
--//
CREATE TABLE ‘post‘ (
‘title‘ VARCHAR(255),
‘time_created‘ DATETIME,
‘content‘ MEDIUMTEXT
);
UPDATE changelog
SET complete_dt = NOW()
WHERE change_number = 1
AND delta_set = ’Main’;
-- Fragment ends: 1 --

09/07/12                        http://coderinsights.blogspot.in   24
Database Migrations
-- Fragment begins: 1 --
DROP TABLE ‘post‘;
--//
DELETE FROM changelog
WHERE change_number = 1
AND delta_set = ’Main’;
-- Fragment ends: 1 --




09/07/12                   http://coderinsights.blogspot.in   25
Phing Way




09/07/12   http://coderinsights.blogspot.in   26
Pitfalls
• Cleanup Deleted Source Files
      – Usually only a problem when you have * include
        patterns
• Undefined properties not raised as an error
• Little to no IDE support (Minimal support
  using Ant Plugin for Eclipse)



09/07/12              http://coderinsights.blogspot.in   27
More!!
SAMPLE
https://bitbucket.org/arnavawasthi/php-phing
WEBSITE
http://phing.info
MAILING LISTS
users@phing.tigris.org
dev@phing.tigris.org

09/07/12         http://coderinsights.blogspot.in   28

Contenu connexe

Tendances

Putting Phing to Work for You
Putting Phing to Work for YouPutting Phing to Work for You
Putting Phing to Work for Youhozn
 
Automated Deployment With Phing
Automated Deployment With PhingAutomated Deployment With Phing
Automated Deployment With PhingDaniel Cousineau
 
Best Practices in PHP Application Deployment
Best Practices in PHP Application DeploymentBest Practices in PHP Application Deployment
Best Practices in PHP Application DeploymentShahar Evron
 
11 tools for your PHP devops stack
11 tools for your PHP devops stack11 tools for your PHP devops stack
11 tools for your PHP devops stackKris Buytaert
 
Propel Your PHP Applications
Propel Your PHP ApplicationsPropel Your PHP Applications
Propel Your PHP Applicationshozn
 
Practical PHP Deployment with Jenkins
Practical PHP Deployment with JenkinsPractical PHP Deployment with Jenkins
Practical PHP Deployment with JenkinsAdam Culp
 
Virtual Bolt Workshop - 6 May
Virtual Bolt Workshop - 6 MayVirtual Bolt Workshop - 6 May
Virtual Bolt Workshop - 6 MayPuppet
 
Zend Framework 1.8 workshop
Zend Framework 1.8 workshopZend Framework 1.8 workshop
Zend Framework 1.8 workshopNick Belhomme
 
Modulesync- How vox pupuli manages 133 modules, Tim Meusel
Modulesync- How vox pupuli manages 133 modules, Tim MeuselModulesync- How vox pupuli manages 133 modules, Tim Meusel
Modulesync- How vox pupuli manages 133 modules, Tim MeuselPuppet
 
Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016Clark Everetts
 
Virtual Bolt Workshop - Dell - April 8 2020
Virtual Bolt Workshop - Dell - April 8 2020Virtual Bolt Workshop - Dell - April 8 2020
Virtual Bolt Workshop - Dell - April 8 2020Puppet
 
Puppet Virtual Bolt Workshop - 23 April 2020 (Singapore)
Puppet Virtual Bolt Workshop - 23 April 2020 (Singapore)Puppet Virtual Bolt Workshop - 23 April 2020 (Singapore)
Puppet Virtual Bolt Workshop - 23 April 2020 (Singapore)Puppet
 
Vagrant move over, here is Docker
Vagrant move over, here is DockerVagrant move over, here is Docker
Vagrant move over, here is DockerNick Belhomme
 
Zend con 2016 bdd with behat for beginners
Zend con 2016   bdd with behat for beginnersZend con 2016   bdd with behat for beginners
Zend con 2016 bdd with behat for beginnersAdam Englander
 
Easily Manage Patching and Application Updates with Chocolatey + Puppet - Apr...
Easily Manage Patching and Application Updates with Chocolatey + Puppet - Apr...Easily Manage Patching and Application Updates with Chocolatey + Puppet - Apr...
Easily Manage Patching and Application Updates with Chocolatey + Puppet - Apr...Puppet
 
PHP Quality Assurance Workshop PHPBenelux
PHP Quality Assurance Workshop PHPBeneluxPHP Quality Assurance Workshop PHPBenelux
PHP Quality Assurance Workshop PHPBeneluxNick Belhomme
 
Drupal 8 - Corso frontend development
Drupal 8 - Corso frontend developmentDrupal 8 - Corso frontend development
Drupal 8 - Corso frontend developmentsparkfabrik
 
Frequently asked questions answered frequently - but now for the last time
Frequently asked questions answered frequently - but now for the last timeFrequently asked questions answered frequently - but now for the last time
Frequently asked questions answered frequently - but now for the last timeAndreas Jung
 
Laravel 4 package development
Laravel 4 package developmentLaravel 4 package development
Laravel 4 package developmentTihomir Opačić
 
Getting started with Django 1.8
Getting started with Django 1.8Getting started with Django 1.8
Getting started with Django 1.8rajkumar2011
 

Tendances (20)

Putting Phing to Work for You
Putting Phing to Work for YouPutting Phing to Work for You
Putting Phing to Work for You
 
Automated Deployment With Phing
Automated Deployment With PhingAutomated Deployment With Phing
Automated Deployment With Phing
 
Best Practices in PHP Application Deployment
Best Practices in PHP Application DeploymentBest Practices in PHP Application Deployment
Best Practices in PHP Application Deployment
 
11 tools for your PHP devops stack
11 tools for your PHP devops stack11 tools for your PHP devops stack
11 tools for your PHP devops stack
 
Propel Your PHP Applications
Propel Your PHP ApplicationsPropel Your PHP Applications
Propel Your PHP Applications
 
Practical PHP Deployment with Jenkins
Practical PHP Deployment with JenkinsPractical PHP Deployment with Jenkins
Practical PHP Deployment with Jenkins
 
Virtual Bolt Workshop - 6 May
Virtual Bolt Workshop - 6 MayVirtual Bolt Workshop - 6 May
Virtual Bolt Workshop - 6 May
 
Zend Framework 1.8 workshop
Zend Framework 1.8 workshopZend Framework 1.8 workshop
Zend Framework 1.8 workshop
 
Modulesync- How vox pupuli manages 133 modules, Tim Meusel
Modulesync- How vox pupuli manages 133 modules, Tim MeuselModulesync- How vox pupuli manages 133 modules, Tim Meusel
Modulesync- How vox pupuli manages 133 modules, Tim Meusel
 
Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016
 
Virtual Bolt Workshop - Dell - April 8 2020
Virtual Bolt Workshop - Dell - April 8 2020Virtual Bolt Workshop - Dell - April 8 2020
Virtual Bolt Workshop - Dell - April 8 2020
 
Puppet Virtual Bolt Workshop - 23 April 2020 (Singapore)
Puppet Virtual Bolt Workshop - 23 April 2020 (Singapore)Puppet Virtual Bolt Workshop - 23 April 2020 (Singapore)
Puppet Virtual Bolt Workshop - 23 April 2020 (Singapore)
 
Vagrant move over, here is Docker
Vagrant move over, here is DockerVagrant move over, here is Docker
Vagrant move over, here is Docker
 
Zend con 2016 bdd with behat for beginners
Zend con 2016   bdd with behat for beginnersZend con 2016   bdd with behat for beginners
Zend con 2016 bdd with behat for beginners
 
Easily Manage Patching and Application Updates with Chocolatey + Puppet - Apr...
Easily Manage Patching and Application Updates with Chocolatey + Puppet - Apr...Easily Manage Patching and Application Updates with Chocolatey + Puppet - Apr...
Easily Manage Patching and Application Updates with Chocolatey + Puppet - Apr...
 
PHP Quality Assurance Workshop PHPBenelux
PHP Quality Assurance Workshop PHPBeneluxPHP Quality Assurance Workshop PHPBenelux
PHP Quality Assurance Workshop PHPBenelux
 
Drupal 8 - Corso frontend development
Drupal 8 - Corso frontend developmentDrupal 8 - Corso frontend development
Drupal 8 - Corso frontend development
 
Frequently asked questions answered frequently - but now for the last time
Frequently asked questions answered frequently - but now for the last timeFrequently asked questions answered frequently - but now for the last time
Frequently asked questions answered frequently - but now for the last time
 
Laravel 4 package development
Laravel 4 package developmentLaravel 4 package development
Laravel 4 package development
 
Getting started with Django 1.8
Getting started with Django 1.8Getting started with Django 1.8
Getting started with Django 1.8
 

En vedette

öZkan şAhin
öZkan şAhinöZkan şAhin
öZkan şAhinyardimt
 
SöZcüKte Anlam
SöZcüKte AnlamSöZcüKte Anlam
SöZcüKte Anlamyardimt
 
Tugbapalta
TugbapaltaTugbapalta
Tugbapaltayardimt
 
CüMlenyn Yapisi
CüMlenyn YapisiCüMlenyn Yapisi
CüMlenyn Yapisiyardimt
 
Group Profile
Group ProfileGroup Profile
Group Profileajaybc
 
Fler Sunusu
Fler SunusuFler Sunusu
Fler Sunusuyardimt
 
Are you a life-long learner?
Are you a life-long learner?Are you a life-long learner?
Are you a life-long learner?Jeremy Williams
 
「Rubyで描くビジネスモデル」池澤 一廣
「Rubyで描くビジネスモデル」池澤 一廣「Rubyで描くビジネスモデル」池澤 一廣
「Rubyで描くビジネスモデル」池澤 一廣toRuby
 
Test First, Refresh Second: Web App TDD in Grails
Test First, Refresh Second: Web App TDD in GrailsTest First, Refresh Second: Web App TDD in Grails
Test First, Refresh Second: Web App TDD in GrailsTim Berglund
 
Kelime Tuerleri
Kelime TuerleriKelime Tuerleri
Kelime Tuerleriyardimt
 
Hurricanes In Sandwich
Hurricanes In  SandwichHurricanes In  Sandwich
Hurricanes In SandwichLucyGauthier
 
Yapilarina GöRe Isimler
Yapilarina GöRe IsimlerYapilarina GöRe Isimler
Yapilarina GöRe Isimleryardimt
 
Steps to change address online.
Steps to change address online.Steps to change address online.
Steps to change address online.Wassim Merheby
 
Increased FDI in defence manufacturing Press Note (7), 2014 series.
Increased FDI in defence manufacturing Press Note (7), 2014 series.Increased FDI in defence manufacturing Press Note (7), 2014 series.
Increased FDI in defence manufacturing Press Note (7), 2014 series.Ankur Gupta
 
Mevlananin Ogutlari
Mevlananin OgutlariMevlananin Ogutlari
Mevlananin Ogutlariyardimt
 
大川祐介
大川祐介大川祐介
大川祐介toRuby
 
Paragrafyn Yapysy
Paragrafyn YapysyParagrafyn Yapysy
Paragrafyn Yapysyyardimt
 

En vedette (20)

öZkan şAhin
öZkan şAhinöZkan şAhin
öZkan şAhin
 
Meat 2.0 vr7
Meat 2.0 vr7Meat 2.0 vr7
Meat 2.0 vr7
 
SöZcüKte Anlam
SöZcüKte AnlamSöZcüKte Anlam
SöZcüKte Anlam
 
Tugbapalta
TugbapaltaTugbapalta
Tugbapalta
 
CüMlenyn Yapisi
CüMlenyn YapisiCüMlenyn Yapisi
CüMlenyn Yapisi
 
Group Profile
Group ProfileGroup Profile
Group Profile
 
Fler Sunusu
Fler SunusuFler Sunusu
Fler Sunusu
 
Are you a life-long learner?
Are you a life-long learner?Are you a life-long learner?
Are you a life-long learner?
 
「Rubyで描くビジネスモデル」池澤 一廣
「Rubyで描くビジネスモデル」池澤 一廣「Rubyで描くビジネスモデル」池澤 一廣
「Rubyで描くビジネスモデル」池澤 一廣
 
Economy in a nutshell
Economy in a nutshellEconomy in a nutshell
Economy in a nutshell
 
Art 245 photo montage
Art 245 photo montageArt 245 photo montage
Art 245 photo montage
 
Test First, Refresh Second: Web App TDD in Grails
Test First, Refresh Second: Web App TDD in GrailsTest First, Refresh Second: Web App TDD in Grails
Test First, Refresh Second: Web App TDD in Grails
 
Kelime Tuerleri
Kelime TuerleriKelime Tuerleri
Kelime Tuerleri
 
Hurricanes In Sandwich
Hurricanes In  SandwichHurricanes In  Sandwich
Hurricanes In Sandwich
 
Yapilarina GöRe Isimler
Yapilarina GöRe IsimlerYapilarina GöRe Isimler
Yapilarina GöRe Isimler
 
Steps to change address online.
Steps to change address online.Steps to change address online.
Steps to change address online.
 
Increased FDI in defence manufacturing Press Note (7), 2014 series.
Increased FDI in defence manufacturing Press Note (7), 2014 series.Increased FDI in defence manufacturing Press Note (7), 2014 series.
Increased FDI in defence manufacturing Press Note (7), 2014 series.
 
Mevlananin Ogutlari
Mevlananin OgutlariMevlananin Ogutlari
Mevlananin Ogutlari
 
大川祐介
大川祐介大川祐介
大川祐介
 
Paragrafyn Yapysy
Paragrafyn YapysyParagrafyn Yapysy
Paragrafyn Yapysy
 

Similaire à Build Automation of PHP Applications

Staging Drupal 8 31 09 1 3
Staging Drupal 8 31 09 1 3Staging Drupal 8 31 09 1 3
Staging Drupal 8 31 09 1 3Drupalcon Paris
 
Open Writing! Collaborative Authoring for CloudStack Documentation by Jessica...
Open Writing! Collaborative Authoring for CloudStack Documentation by Jessica...Open Writing! Collaborative Authoring for CloudStack Documentation by Jessica...
Open Writing! Collaborative Authoring for CloudStack Documentation by Jessica...buildacloud
 
Open writing-cloud-collab
Open writing-cloud-collabOpen writing-cloud-collab
Open writing-cloud-collabKaren Vuong
 
Stress Free Deployment - Confoo 2011
Stress Free Deployment  - Confoo 2011Stress Free Deployment  - Confoo 2011
Stress Free Deployment - Confoo 2011Bachkoutou Toutou
 
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis OverviewLeo Lorieri
 
Apache ant
Apache antApache ant
Apache antkoniik
 
Take your database source code and data under control
Take your database source code and data under controlTake your database source code and data under control
Take your database source code and data under controlMarcin Przepiórowski
 
Documentation Insight技术架构与开发历程
Documentation Insight技术架构与开发历程Documentation Insight技术架构与开发历程
Documentation Insight技术架构与开发历程jeffz
 
Automating complex infrastructures with Puppet
Automating complex infrastructures with PuppetAutomating complex infrastructures with Puppet
Automating complex infrastructures with PuppetKris Buytaert
 
Best Practices for Development Deployment & Distributions: Capital Camp + Gov...
Best Practices for Development Deployment & Distributions: Capital Camp + Gov...Best Practices for Development Deployment & Distributions: Capital Camp + Gov...
Best Practices for Development Deployment & Distributions: Capital Camp + Gov...Phase2
 
BP-6 Repository Customization Best Practices
BP-6 Repository Customization Best PracticesBP-6 Repository Customization Best Practices
BP-6 Repository Customization Best PracticesAlfresco Software
 
Gianluca Varisco - DevOoops (Increase awareness around DevOps infra security)
Gianluca Varisco - DevOoops (Increase awareness around DevOps infra security)Gianluca Varisco - DevOoops (Increase awareness around DevOps infra security)
Gianluca Varisco - DevOoops (Increase awareness around DevOps infra security)Codemotion
 
WorkFlow: An Inquiry Into Productivity by Timothy Bolton
WorkFlow:  An Inquiry Into Productivity by Timothy BoltonWorkFlow:  An Inquiry Into Productivity by Timothy Bolton
WorkFlow: An Inquiry Into Productivity by Timothy BoltonMiva
 
An introduction to maven gradle and sbt
An introduction to maven gradle and sbtAn introduction to maven gradle and sbt
An introduction to maven gradle and sbtFabio Fumarola
 
XPages -Beyond the Basics
XPages -Beyond the BasicsXPages -Beyond the Basics
XPages -Beyond the BasicsUlrich Krause
 
Pure Speed Drupal 4 Gov talk
Pure Speed Drupal 4 Gov talkPure Speed Drupal 4 Gov talk
Pure Speed Drupal 4 Gov talkBryan Ollendyke
 

Similaire à Build Automation of PHP Applications (20)

Write php deploy everywhere tek11
Write php deploy everywhere   tek11Write php deploy everywhere   tek11
Write php deploy everywhere tek11
 
Intro to-ant
Intro to-antIntro to-ant
Intro to-ant
 
Staging Drupal 8 31 09 1 3
Staging Drupal 8 31 09 1 3Staging Drupal 8 31 09 1 3
Staging Drupal 8 31 09 1 3
 
Open Writing! Collaborative Authoring for CloudStack Documentation by Jessica...
Open Writing! Collaborative Authoring for CloudStack Documentation by Jessica...Open Writing! Collaborative Authoring for CloudStack Documentation by Jessica...
Open Writing! Collaborative Authoring for CloudStack Documentation by Jessica...
 
Open writing-cloud-collab
Open writing-cloud-collabOpen writing-cloud-collab
Open writing-cloud-collab
 
Django
DjangoDjango
Django
 
Stress Free Deployment - Confoo 2011
Stress Free Deployment  - Confoo 2011Stress Free Deployment  - Confoo 2011
Stress Free Deployment - Confoo 2011
 
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
 
Apache ant
Apache antApache ant
Apache ant
 
Take your database source code and data under control
Take your database source code and data under controlTake your database source code and data under control
Take your database source code and data under control
 
Documentation Insight技术架构与开发历程
Documentation Insight技术架构与开发历程Documentation Insight技术架构与开发历程
Documentation Insight技术架构与开发历程
 
Write php deploy everywhere
Write php deploy everywhereWrite php deploy everywhere
Write php deploy everywhere
 
Automating complex infrastructures with Puppet
Automating complex infrastructures with PuppetAutomating complex infrastructures with Puppet
Automating complex infrastructures with Puppet
 
Best Practices for Development Deployment & Distributions: Capital Camp + Gov...
Best Practices for Development Deployment & Distributions: Capital Camp + Gov...Best Practices for Development Deployment & Distributions: Capital Camp + Gov...
Best Practices for Development Deployment & Distributions: Capital Camp + Gov...
 
BP-6 Repository Customization Best Practices
BP-6 Repository Customization Best PracticesBP-6 Repository Customization Best Practices
BP-6 Repository Customization Best Practices
 
Gianluca Varisco - DevOoops (Increase awareness around DevOps infra security)
Gianluca Varisco - DevOoops (Increase awareness around DevOps infra security)Gianluca Varisco - DevOoops (Increase awareness around DevOps infra security)
Gianluca Varisco - DevOoops (Increase awareness around DevOps infra security)
 
WorkFlow: An Inquiry Into Productivity by Timothy Bolton
WorkFlow:  An Inquiry Into Productivity by Timothy BoltonWorkFlow:  An Inquiry Into Productivity by Timothy Bolton
WorkFlow: An Inquiry Into Productivity by Timothy Bolton
 
An introduction to maven gradle and sbt
An introduction to maven gradle and sbtAn introduction to maven gradle and sbt
An introduction to maven gradle and sbt
 
XPages -Beyond the Basics
XPages -Beyond the BasicsXPages -Beyond the Basics
XPages -Beyond the Basics
 
Pure Speed Drupal 4 Gov talk
Pure Speed Drupal 4 Gov talkPure Speed Drupal 4 Gov talk
Pure Speed Drupal 4 Gov talk
 

Dernier

How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 

Dernier (20)

How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 

Build Automation of PHP Applications

  • 1. Phing Automating PHP build deployment 09/07/12 http://coderinsights.blogspot.in 1
  • 2. Old Way 09/07/12 http://coderinsights.blogspot.in 2
  • 3. Why use Build Automation? “We are human, We get bored, We forget things, We make mistakes” • Improve product quality • Consolidate scripts • Eliminate repetitive tasks • Minimize error (bad builds) • Eliminate dependencies (Easier handover) • Highly extendible • Saves time 09/07/12 http://coderinsights.blogspot.in 3
  • 4. What is [PHing Is Not Gnumake] • It's a PHP project build tool based on Apache Ant • Opensource • Mostly Cross platform • Uses XML build files • No required external dependencies • Built & optimised for PHP5 09/07/12 http://coderinsights.blogspot.in 4
  • 5. What can you do? • Lots –Not just for deployment • SVN tasks • PHPUnit/SimpleTest • Code analysis tasks • PhpDocumentor • Zip/Unzip • File manipulation • Various OS tasks 09/07/12 http://coderinsights.blogspot.in 5
  • 6. Features 09/07/12 http://coderinsights.blogspot.in 6
  • 7. Phing Philosophy • Build scripts contains "Targets" – Targets should be small and specialized. – Example Targets: • clean – Clear temporary and cached files • copy – Copy files to their intended destination • migrate – Upgrade the database schema 09/07/12 http://coderinsights.blogspot.in 7
  • 8. Phing Philosophy • Targets can have dependencies – Target "live" can depend on clean, copy, and migrate – Meaning, when we run the "live" target, it first runs clean, copy, then migrate • And any tasks they depend on 09/07/12 http://coderinsights.blogspot.in 8
  • 9. Installing Phing • pear channel-discover pear.phing.info • pear install phing/Phing • Want all the dependencies? – pear config-set preferred_state alpha – pear install –alldeps phing/Phing – pear config-set preferred_state stable – pear install phing/phingdocs • Also available from: – SVN – Zip Download 09/07/12 http://coderinsights.blogspot.in 9
  • 10. Running Phing • $> phing –v – Lists Phing version • Phing expects to find a file "build.xml" in the current directory – build.xml defines the targets – You can use the "-f <filename>" flag to specify an alternate build file like • $> phing -f build-live.xml 09/07/12 http://coderinsights.blogspot.in 10
  • 11. Syntax • Build File uses XML • Standard Elements – Task: code that performs a specific function – Target: groups of tasks – Project: root node • Variables – ${variablename} – Conventions • Psuedo-Namespaces using periods • ${namespace.variable.name} 09/07/12 http://coderinsights.blogspot.in 11
  • 12. Basic Conventions • build.xml – Central repository of your top-level tasks • build-*.xml – Can be included into build.xml. – Usually for grouping by target (dev, staging,prod) or task (migrate, test, etc.) • build.properties – Technically an INI file that contains variables to be included by build files. 09/07/12 http://coderinsights.blogspot.in 12
  • 13. Basic build.xml <?xml version="1.0" encoding="UTF-8"?> <project name=“opx" default="default" basedir="."> <property file="build.properties" /> <target name="default"> <echo message="Hello World!" /> </target> </project> 09/07/12 http://coderinsights.blogspot.in 13
  • 14. Basic build.properties source.directory = /mnt/work/ ## Database Configuration db.user = username db.pass = password db.host = localhost db.name = database Usage: $phing –propertyfile build.properties 09/07/12 http://coderinsights.blogspot.in 14
  • 15. Most Useful Elements • Filesets: define once,use many <fileset id="src_crons" dir="${dir.crons_path}/statistic-engine/"> <include name="*.php"/> <exclude name="populate_opx_tables.php" /> </fileset> • Mappers & Filters: Transform files during copy/move/… <copy todir="${build}"> <fileset refid="files"/> <mapper type="glob" from="*.txt" to="*.new.txt"/> <filterchain> <replaceregexp> <regexp pattern="rn" replace="n"/> <expandproperties/> </replaceregexp> </filterchain> </copy> 09/07/12 http://coderinsights.blogspot.in 15
  • 16. Executing External Tools • Nearly all file transfer tools will be external commands • For this we need the Exec task <exec command="cp file1 file2" /> 09/07/12 http://coderinsights.blogspot.in 16
  • 17. Examples SVN, Git <svncopy username=“pavan“ password="test” repositoryurl="svn://localhost/phing/trunk/“ todir="svn://localhost/phing/tags/1.0"/> <svnexport repositoryurl="svn://localhost/project/trunk/” todir="/home/pavan/dev"/> <svnlastrevision repositoryurl="svn://localhost/project/trunk/” propertyname="lastrev"/> <echo>Last revision: ${lastrev}</echo> <svnlastrevision repositoryurl="${deploy.svn}” property="deploy.rev"/> <svnexport repositoryurl="${deploy.svn}" todir="/www/releases/build-${deploy.rev}"/> 09/07/12 http://coderinsights.blogspot.in 17
  • 18. Examples Packaging – Tar/Zip <tar compression="gzip" destFile="package.tgz" basedir="build"/> <zip destfile="htmlfiles.zip"> <fileset dir="."> <include name="**/*.html"/> </fileset> </zip> 09/07/12 http://coderinsights.blogspot.in 18
  • 19. Examples Documentation: – DocBlox – PhpDocumentor – ApiGen <docblox title="Phing API Documentation" output="docs" quiet="true"> <fileset dir="../../classes"> <include name="**/*.php"/> </fileset> </docblox> 09/07/12 http://coderinsights.blogspot.in 19
  • 20. Examples • SCP/FTP <scp username="john" password="smith" host="webserver" todir="/www/htdocs/project/"> <fileset dir="test"> <include name="*.html"/> </fileset> </scp> <ftpdeploy host="server01” username="john" password="smit" dir="/var/www"> <fileset dir="."> <include name="*.html"/> </fileset> </ftpdeploy> 09/07/12 http://coderinsights.blogspot.in 20
  • 21. Database Migrations • Set of delta SQL files (1-create-post.sql) • Tracks current version of your db in changelog table • Generates do and undo SQL files CREATE TABLE changelog ( change_number BIGINT NOT NULL, delta_set VARCHAR(10) NOT NULL, start_dt TIMESTAMP NOT NULL, complete_dt TIMESTAMP NULL, applied_by VARCHAR(100) NOT NULL, description VARCHAR(500) NOT NULL ) 09/07/12 http://coderinsights.blogspot.in 21
  • 22. Database Migrations • Delta scripts with do (up) & undo (down) parts -- // CREATE TABLE ‘post‘ ( ‘title‘ VARCHAR(255), ‘time_created‘ DATETIME, ‘content‘ MEDIUMTEXT ); -- //@UNDO DROP TABLE ‘post‘; -- // 09/07/12 http://coderinsights.blogspot.in 22
  • 23. Database Migrations <dbdeploy url="sqlite:test.db" dir="deltas" outputfile="deploy.sql" undooutputfile="undo.sql"/> <pdosqlexec src="deploy.sql" url="sqlite:test.db"/> Buildfile: /home/pavan/dbdeploy/build.xml Demo > migrate: [dbdeploy] Getting applied changed numbers from DB: mysql:host=localhost;dbname=demo [dbdeploy] Current db revision: 0 [dbdeploy] Checkall: [pdosqlexec] Executing file: /home/michiel/dbdeploy/deploy.sql [pdosqlexec] 3 of 3 SQL statements executed successfully BUILD FINISHED 09/07/12 http://coderinsights.blogspot.in 23
  • 24. Database Migrations -- Fragment begins: 1 -- INSERT INTO changelog (change_number, delta_set, start_dt, applied_by, description) VALUES (1, ’Main’, NOW(), ’dbdeploy’, ’1-create_initial_schema.sql’); --// CREATE TABLE ‘post‘ ( ‘title‘ VARCHAR(255), ‘time_created‘ DATETIME, ‘content‘ MEDIUMTEXT ); UPDATE changelog SET complete_dt = NOW() WHERE change_number = 1 AND delta_set = ’Main’; -- Fragment ends: 1 -- 09/07/12 http://coderinsights.blogspot.in 24
  • 25. Database Migrations -- Fragment begins: 1 -- DROP TABLE ‘post‘; --// DELETE FROM changelog WHERE change_number = 1 AND delta_set = ’Main’; -- Fragment ends: 1 -- 09/07/12 http://coderinsights.blogspot.in 25
  • 26. Phing Way 09/07/12 http://coderinsights.blogspot.in 26
  • 27. Pitfalls • Cleanup Deleted Source Files – Usually only a problem when you have * include patterns • Undefined properties not raised as an error • Little to no IDE support (Minimal support using Ant Plugin for Eclipse) 09/07/12 http://coderinsights.blogspot.in 27

Notes de l'éditeur

  1. We are human We get bored We forget things We make mistakes Repetitive tasks like Versioncontrol (Unit)Testing Configuring Packaging Uploading DBchanges
  2. Phing is Recursive acronym In its simplest form, Phing allows you to copy code from your source control repository (SVN or Git) to your server via SSH, and perform pre and post-deploy functions like restarting a webserver, busting cache, renaming files, running database migrations and so on. With Phing it’s also possible to deploy to many machines at once. Original PHP4 version by Andreas Aderhold Cross-platform(for Windows) Build Systems Apache ANT Capastrano Plain PHP or BASH or BAT Files
  3. Interface to various popular (PHP)tools
  4. Introduced facade targets • Moved all the properties out • Used properties for configurability • Defined and reused elements with ids • Use of reflexives and replacements • Separating build files
  5. Optional documentation Pear install phing/phingdocs
  6. Other useful options: – Help (-h) – Specify properties (-D propname=value) – List targets (-l) – Get more output (-verbose or -debug)
  7. Task : code that performs a specific function (svncheckout, mkdir,etc.) Target : groups of tasks, can optionally depend on other targets Project : root node, contains multiple targets
  8. Mappers: Change filename Flatten directories Filters: Strip comments, whitespace Replace values Perform XSLT transformation Translation(i18n)