SlideShare a Scribd company logo
Automated Deployment With Phing Or: How I Will Replace You With A Very Small Shell Script ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 1
Who Daniel Cousineau Senior Software Applications Developer 	Texas A&M University 	Division of Student Affairs 	Department of IT http://www.toosweettobesour.com/ @dcousineau ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 2
The Problem ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 3
Human beings make mistakes ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 4
We aren’t as accurate each repetition ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 5
Machines don’t have this problem ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 6
They do the same thing every time (supposedly) ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 7
At Any Given Time New Code New Configuration New Database Schema New Static Files ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 8
A Lot To Remember Did you remember to upload ALL new files? Did you remember to update your DB? Did you remember to correct your config? ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 9
Even Worse Did you clear your caches? Did you delete that old file/plugin? In the upload process, was your configuration overwritten? Did you upload ALL the changed files? When did you last upload? ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 10
The Solution ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 11
Automation! Build scripts! We are programmers after all… ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 12
ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 13 Don’t Do More Work Than You Have To!
ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 14 Work Hard At Being Lazy!
What is Automation? Automated deployment means a single command Locks your live site Uploads changed files Clears caches and temporary files Updates the database schema Runs other cron tasks Unlocks your live site ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 15
Why Do We Automate? Deployment is tricky Repetition degrades quality She sells sea shells by the sea shore ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 16
When Is Automation Used? All the time! Staging Live Probably best to use it on your dev box too! ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 17
The Basics ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 18
Tools of the Trade Build System Phing Apache ANT Capastrano Plain PHP or BASH or BAT Files File Transfer Rsync (*NIX Environments) Xcopy (Windows Environments) Configuration Management Database Migration DBDeploy Doctrine ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 19
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 ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 20
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 ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 21
Installing Phing pear channel-discover pear.phing.info pear install phing/Phing Want all the little dependencies? pear config-set preferred_state alpha pear install –alldepsphing/Phing pear config-set preferred_state stable ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 22
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 ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 23
Syntax XML If you don’t already know it, you have bigger problems Variables ${variablename} Conventions Psuedo-Namespaces using periods ${namespace.variable.name} ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 24
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, live) or task (migrate, test, etc.) build.properties Technically an INI file that contains variables to be included by build files. ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 25
Basic build.xml ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 26 <?xml version="1.0" encoding="UTF-8"?> <project name="ZendCon" default="default" basedir=".">     <property file="build.properties" />     <target name="default">         <echo message="Howdy World!" />     </target>        </project>
Basic build.properties ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 27 source.directory = /src ## Database Configuration db.user = username db.pass = password db.host = localhost db.name = database
File Transfer ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 28
Techniques Built in Phing Copy Task Cross Platform Slow Not over network Version Control Checkout/Update Syncs deleted files User created files usually ignored Rsync Great for *NIX environments. Almost guaranteed to be installed on Linux, BSD, Mac OSX Can be installed on Windows Xcopy Good for Windows environments Faster than Phing Copy Not over network ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 29
Pitfalls Cleanup Deleted Source Files Usually only a problem when you have * include patterns ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 30
Pitfalls User created files are a HUGE pitfall /htdocs/images/upload Sync programs usually will delete content your deployment machine doesn’t have What if user upload are mixed in with files you want to manage? Solutions Keep user created content completely separated. The further up the file tree and consolidated the better. Separate static file server, Amazon S3, or other style CDNs ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 31
Executing External Tools Nearly all file transfer tools will be external commands For this we need the Exec task ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 32 <exec command="cp file1 file2" />
Rsync So many different options you’re best off finding your own tutorials or reading MAN pages rsync -aCvz 	-e 'ssh -i /path/to/ssh-key' 	${project.basedir}/src user@domain: ${staging.deployment.directory}/ ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 33
Rsync Options Of Note -a	archive-mode Recursive copy, preserve everything, etc. -C	cvs-exclude Ignore .cvs, .svn, and other version control artifacts -v	verbose Know EXACTLY what’s going on -z	compress Compress information transmitted -e	alternative remote shell Use a custom SSH command (namely use key-pair) ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 34
Xcopy Best when your live deployment process involves copying to a network share on Windows machines xcopy 	${project.basedir}${source.directory} 	${staging.deployment.directory} 	/D /I /Y /S /E 	/Exclude:${project.basedir}taging.deployment.exclude ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 35
Xcopy Options Of Note /d Update only those files that are different (timestamps) /i Creates target directories if they don’t exist /y Do not prompt /s Copy all directories and sub-directories… /e …Even if the directories are empty	 /exclude Exclude files based on glob patterns ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 36
Xcopy Exclude File Example ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 37 mpbr />ploadsbr />
Configuration Management ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 38
Techniques Check incoming domain www.domain.com means load production configuration localhost/domain.com means load development configuration Check for an environment file Contents of DOCUMENT_ROOT/.env determine configuration Copy over during deployment ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 39
Check Incoming Domain	 Pros No chance for error Cons Detection is a weak link Especially when development, staging, and live have different web servers (e.g. Apache to IIS) ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 40
Check for an Environment File Pros Consistent regardless of Server or OS changes Easy to repair Quick FTP or SSH Easy Testing Just swap file contents Cons Forget to copy changes? ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 41
Copy Over During Deployment Pros Images and CSS now manageable Reduce redundancy Simple to repurpose regular push command Cons Difficult to manage Forget to copy changes? ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 42
Which one to choose? Depends on your application architecture Depends on your environment You’ll know what’s best for your project I use a combination of Environment File and Copy Over During Deployment ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 43
Database Migration ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 44
Database Deployment Philosophy “Versions” often referred to as “Deltas” Each Delta has an UP and a DOWN script UP makes the changes DOWN reverts the changes Each change should be a non-destructive schema change Unless of course you need data alteration ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 45
DBDeploy Philosophy Each delta is 2 native SQL scripts Separated by --//@undo Database version is stored in a special table Version X was applied at TIMESTAMP… Beware corruption! ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 46
DBDeploy Under The Hood Connect to the database, read from changelog table, get the most current revision installed Retrieve all delta files newer that the current revision Revision numbers are based off of alphabetic sorting, name your files accordingly Pull all the “UP” changes and concatenate them to a migration script Up to YOU to run the migration script ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 47
Installing DBDeploy Is Phing already installed? Great! So is DBDeploy… Create the changelog table Track the current version of your DB ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 48 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   ); ALTER TABLE changelog   ADD CONSTRAINT Pkchangelog PRIMARY KEY (change_number, delta_set);
Basic Delta: 01_init.sql ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 49 --//   CREATE TABLE IF NOT EXISTS `users` (     `id` int(10) unsigned NOT NULL auto_increment,     `handle` varchar(25) NOT NULL default '',     PRIMARY KEY  (`id`),     UNIQUE KEY `users_handle_index` (`handle`)   ) ENGINE=InnoDB  DEFAULT;   --//@UNDO     DROP TABLE IF EXISTS `users`;   --//
Run Migration First add a task to your Phing build file ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 50 <target name="migrate"> </target>
Run Migration Generate the SQL migration file ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 51 <target name="migrate">   <dbdeploy url="mysql:host=${db.host};dbname=${db.name}" userid="${db.user}"     password="${db.pass}"     dir="${project.basedir}/db/deltas" outputfile="${project.basedir}/up.sql" undooutputfile="${project.basedir}/down.sql"   /> </target>
Run Migration Execute the SQL script ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 52 <target name="migrate">   <dbdeploy url="mysql:host=${db.host};dbname=${db.name}" userid="${db.user}"     password="${db.pass}"     dir="${project.basedir}/db/deltas" outputfile="${project.basedir}/up.sql" undooutputfile="${project.basedir}/down.sql"   />   <exec     command="/usr/bin/mysql -h${db.local.host} -u${db.local.user}              -p ${db.local.pass}              ${db.local.name} < ${project.basedir}/up.sql"     dir="${project.basedir}" checkreturn="true">   </target>
Pitfalls Make sure you have a good CLI app for loading a SQL file /usr/bin/mysql mysql.exe Build script travelling across operating systems? Write your own Phing task to execute the migration output? Was the changelog table created in the first place? ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 53
Doctrine Database Migrations Integrated into the Doctrine CLI tool ./doctrine migrate Same philosophies BUT, deltas are PHP objects that contain an UP and a DOWN method Run using the Phing exec task ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 54
Other Database Migration Tools http://www.liquibase.org/ ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 55
Closing Thoughts ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 56
Further Resources The people around you More people than you know automate their deployment There are many, many different techniques My techniques may suck for your particular setup #phpcon freenode Many of the speakers hang out there Many smart people hang out there I HANG OUT THERE! Therefore I am smart ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 57
Further Resources Blogs http://phpdeveloper.org Documentation http://phing.info http://dbdeploy.com Google Experimentation Pushing to a local directory Pushing to a virtual machine ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 58
Questions? ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 59
http://joind.in/937

More Related Content

What's hot

Phing - A PHP Build Tool (An Introduction)
Phing - A PHP Build Tool (An Introduction)Phing - A PHP Build Tool (An Introduction)
Phing - A PHP Build Tool (An Introduction)
Michiel Rook
 
Build Automation of PHP Applications
Build Automation of PHP ApplicationsBuild Automation of PHP Applications
Build Automation of PHP Applications
Pavan Kumar N
 
Best Practices in PHP Application Deployment
Best Practices in PHP Application DeploymentBest Practices in PHP Application Deployment
Best Practices in PHP Application Deployment
Shahar Evron
 
Practical PHP Deployment with Jenkins
Practical PHP Deployment with JenkinsPractical PHP Deployment with Jenkins
Practical PHP Deployment with Jenkins
Adam Culp
 
PHP Quality Assurance Workshop PHPBenelux
PHP Quality Assurance Workshop PHPBeneluxPHP Quality Assurance Workshop PHPBenelux
PHP Quality Assurance Workshop PHPBenelux
Nick Belhomme
 
Propel Your PHP Applications
Propel Your PHP ApplicationsPropel Your PHP Applications
Propel Your PHP Applications
hozn
 
Zend Framework 1.8 workshop
Zend Framework 1.8 workshopZend Framework 1.8 workshop
Zend Framework 1.8 workshop
Nick Belhomme
 
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
Clark Everetts
 
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
Adam Englander
 
Vagrant move over, here is Docker
Vagrant move over, here is DockerVagrant move over, here is Docker
Vagrant move over, here is Docker
Nick Belhomme
 
Virtual Bolt Workshop - 6 May
Virtual Bolt Workshop - 6 MayVirtual Bolt Workshop - 6 May
Virtual Bolt Workshop - 6 May
Puppet
 
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
Kris Buytaert
 
Laravel 4 package development
Laravel 4 package developmentLaravel 4 package development
Laravel 4 package development
Tihomir Opačić
 
Composer - The missing package manager for PHP
Composer - The missing package manager for PHPComposer - The missing package manager for PHP
Composer - The missing package manager for PHP
Tareq Hasan
 
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
Puppet
 
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
 
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
 
Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku
Rapid Prototyping Chatter with a PHP/Hack Canvas App on HerokuRapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku
Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku
Salesforce Developers
 
Fighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnitFighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnit
James Fuller
 
Modern Perl for the Unfrozen Paleolithic Perl Programmer
Modern Perl for the Unfrozen Paleolithic  Perl ProgrammerModern Perl for the Unfrozen Paleolithic  Perl Programmer
Modern Perl for the Unfrozen Paleolithic Perl Programmer
John Anderson
 

What's hot (20)

Phing - A PHP Build Tool (An Introduction)
Phing - A PHP Build Tool (An Introduction)Phing - A PHP Build Tool (An Introduction)
Phing - A PHP Build Tool (An Introduction)
 
Build Automation of PHP Applications
Build Automation of PHP ApplicationsBuild Automation of PHP Applications
Build Automation of PHP Applications
 
Best Practices in PHP Application Deployment
Best Practices in PHP Application DeploymentBest Practices in PHP Application Deployment
Best Practices in PHP Application Deployment
 
Practical PHP Deployment with Jenkins
Practical PHP Deployment with JenkinsPractical PHP Deployment with Jenkins
Practical PHP Deployment with Jenkins
 
PHP Quality Assurance Workshop PHPBenelux
PHP Quality Assurance Workshop PHPBeneluxPHP Quality Assurance Workshop PHPBenelux
PHP Quality Assurance Workshop PHPBenelux
 
Propel Your PHP Applications
Propel Your PHP ApplicationsPropel Your PHP Applications
Propel Your PHP Applications
 
Zend Framework 1.8 workshop
Zend Framework 1.8 workshopZend Framework 1.8 workshop
Zend Framework 1.8 workshop
 
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
 
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
 
Vagrant move over, here is Docker
Vagrant move over, here is DockerVagrant move over, here is Docker
Vagrant move over, here is Docker
 
Virtual Bolt Workshop - 6 May
Virtual Bolt Workshop - 6 MayVirtual Bolt Workshop - 6 May
Virtual Bolt Workshop - 6 May
 
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
 
Laravel 4 package development
Laravel 4 package developmentLaravel 4 package development
Laravel 4 package development
 
Composer - The missing package manager for PHP
Composer - The missing package manager for PHPComposer - The missing package manager for PHP
Composer - The missing package manager for PHP
 
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
 
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
 
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...
 
Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku
Rapid Prototyping Chatter with a PHP/Hack Canvas App on HerokuRapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku
Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku
 
Fighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnitFighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnit
 
Modern Perl for the Unfrozen Paleolithic Perl Programmer
Modern Perl for the Unfrozen Paleolithic  Perl ProgrammerModern Perl for the Unfrozen Paleolithic  Perl Programmer
Modern Perl for the Unfrozen Paleolithic Perl Programmer
 

Similar to Automated Deployment With Phing

Makefiles in 2020 — Why they still matter
Makefiles in 2020 — Why they still matterMakefiles in 2020 — Why they still matter
Makefiles in 2020 — Why they still matter
Simon Brüggen
 
Docker and the Oracle Database
Docker and the Oracle DatabaseDocker and the Oracle Database
Docker and the Oracle Database
Insight Technology, Inc.
 
DCEU 18: Developing with Docker Containers
DCEU 18: Developing with Docker ContainersDCEU 18: Developing with Docker Containers
DCEU 18: Developing with Docker Containers
Docker, Inc.
 
Porting your favourite cmdline tool to Android
Porting your favourite cmdline tool to AndroidPorting your favourite cmdline tool to Android
Porting your favourite cmdline tool to Android
Vlatko Kosturjak
 
Ci For The Web 2.0 Guy Or Gal
Ci For The Web 2.0 Guy Or GalCi For The Web 2.0 Guy Or Gal
Ci For The Web 2.0 Guy Or Gal
Chad Woolley
 
Splunk n-box-splunk conf-2017
Splunk n-box-splunk conf-2017Splunk n-box-splunk conf-2017
Splunk n-box-splunk conf-2017
Mohamad Hassan
 
C# Production Debugging Made Easy
 C# Production Debugging Made Easy C# Production Debugging Made Easy
C# Production Debugging Made Easy
Alon Fliess
 
Software Quality Assurance Tooling - Wintersession 2024
Software Quality Assurance Tooling - Wintersession 2024Software Quality Assurance Tooling - Wintersession 2024
Software Quality Assurance Tooling - Wintersession 2024
Henry Schreiner
 
Ideal Deployment In .NET World
Ideal Deployment In .NET WorldIdeal Deployment In .NET World
Ideal Deployment In .NET World
Dima Pasko
 
Dockerizing Symfony Applications - Symfony Live Berlin 2014
Dockerizing Symfony Applications - Symfony Live Berlin 2014Dockerizing Symfony Applications - Symfony Live Berlin 2014
Dockerizing Symfony Applications - Symfony Live Berlin 2014D
 
OpenSolaris 2009.06 Workshop
OpenSolaris 2009.06 WorkshopOpenSolaris 2009.06 Workshop
OpenSolaris 2009.06 Workshop
Iban Nieto Castillero
 
2016 05-cloudsoft-amp-and-brooklyn-new
2016 05-cloudsoft-amp-and-brooklyn-new2016 05-cloudsoft-amp-and-brooklyn-new
2016 05-cloudsoft-amp-and-brooklyn-new
BradDesAulniers2
 
Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014
biicode
 
AWS EC2 tutorial
AWS EC2 tutorialAWS EC2 tutorial
AWS EC2 tutorial
Alexander Novikov
 
Comment améliorer le quotidien des Développeurs PHP ?
Comment améliorer le quotidien des Développeurs PHP ?Comment améliorer le quotidien des Développeurs PHP ?
Comment améliorer le quotidien des Développeurs PHP ?
AFUP_Limoges
 
Slides Aquarium Paris 2008
Slides Aquarium Paris 2008Slides Aquarium Paris 2008
Slides Aquarium Paris 2008julien.ponge
 
Containerized IDEs.pdf
Containerized IDEs.pdfContainerized IDEs.pdf
Containerized IDEs.pdf
LibbySchulze
 
Midwest php 2013 deploying php on paas- why & how
Midwest php 2013   deploying php on paas- why & howMidwest php 2013   deploying php on paas- why & how
Midwest php 2013 deploying php on paas- why & howdotCloud
 
Part 4 Scripting and Virtualization (due Week 7)Objectives1. .docx
Part 4 Scripting and Virtualization (due Week 7)Objectives1. .docxPart 4 Scripting and Virtualization (due Week 7)Objectives1. .docx
Part 4 Scripting and Virtualization (due Week 7)Objectives1. .docx
karlhennesey
 

Similar to Automated Deployment With Phing (20)

Makefiles in 2020 — Why they still matter
Makefiles in 2020 — Why they still matterMakefiles in 2020 — Why they still matter
Makefiles in 2020 — Why they still matter
 
Docker and the Oracle Database
Docker and the Oracle DatabaseDocker and the Oracle Database
Docker and the Oracle Database
 
DCEU 18: Developing with Docker Containers
DCEU 18: Developing with Docker ContainersDCEU 18: Developing with Docker Containers
DCEU 18: Developing with Docker Containers
 
Porting your favourite cmdline tool to Android
Porting your favourite cmdline tool to AndroidPorting your favourite cmdline tool to Android
Porting your favourite cmdline tool to Android
 
Ci For The Web 2.0 Guy Or Gal
Ci For The Web 2.0 Guy Or GalCi For The Web 2.0 Guy Or Gal
Ci For The Web 2.0 Guy Or Gal
 
Splunk n-box-splunk conf-2017
Splunk n-box-splunk conf-2017Splunk n-box-splunk conf-2017
Splunk n-box-splunk conf-2017
 
C# Production Debugging Made Easy
 C# Production Debugging Made Easy C# Production Debugging Made Easy
C# Production Debugging Made Easy
 
Users guide
Users guideUsers guide
Users guide
 
Software Quality Assurance Tooling - Wintersession 2024
Software Quality Assurance Tooling - Wintersession 2024Software Quality Assurance Tooling - Wintersession 2024
Software Quality Assurance Tooling - Wintersession 2024
 
Ideal Deployment In .NET World
Ideal Deployment In .NET WorldIdeal Deployment In .NET World
Ideal Deployment In .NET World
 
Dockerizing Symfony Applications - Symfony Live Berlin 2014
Dockerizing Symfony Applications - Symfony Live Berlin 2014Dockerizing Symfony Applications - Symfony Live Berlin 2014
Dockerizing Symfony Applications - Symfony Live Berlin 2014
 
OpenSolaris 2009.06 Workshop
OpenSolaris 2009.06 WorkshopOpenSolaris 2009.06 Workshop
OpenSolaris 2009.06 Workshop
 
2016 05-cloudsoft-amp-and-brooklyn-new
2016 05-cloudsoft-amp-and-brooklyn-new2016 05-cloudsoft-amp-and-brooklyn-new
2016 05-cloudsoft-amp-and-brooklyn-new
 
Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014
 
AWS EC2 tutorial
AWS EC2 tutorialAWS EC2 tutorial
AWS EC2 tutorial
 
Comment améliorer le quotidien des Développeurs PHP ?
Comment améliorer le quotidien des Développeurs PHP ?Comment améliorer le quotidien des Développeurs PHP ?
Comment améliorer le quotidien des Développeurs PHP ?
 
Slides Aquarium Paris 2008
Slides Aquarium Paris 2008Slides Aquarium Paris 2008
Slides Aquarium Paris 2008
 
Containerized IDEs.pdf
Containerized IDEs.pdfContainerized IDEs.pdf
Containerized IDEs.pdf
 
Midwest php 2013 deploying php on paas- why & how
Midwest php 2013   deploying php on paas- why & howMidwest php 2013   deploying php on paas- why & how
Midwest php 2013 deploying php on paas- why & how
 
Part 4 Scripting and Virtualization (due Week 7)Objectives1. .docx
Part 4 Scripting and Virtualization (due Week 7)Objectives1. .docxPart 4 Scripting and Virtualization (due Week 7)Objectives1. .docx
Part 4 Scripting and Virtualization (due Week 7)Objectives1. .docx
 

More from Daniel Cousineau

Git, an Illustrated Primer
Git, an Illustrated PrimerGit, an Illustrated Primer
Git, an Illustrated Primer
Daniel Cousineau
 
JavaScript Primer
JavaScript PrimerJavaScript Primer
JavaScript Primer
Daniel Cousineau
 
JavaScript Primer
JavaScript PrimerJavaScript Primer
JavaScript Primer
Daniel Cousineau
 
Disregard Inputs, Acquire Zend_Form
Disregard Inputs, Acquire Zend_FormDisregard Inputs, Acquire Zend_Form
Disregard Inputs, Acquire Zend_Form
Daniel Cousineau
 
jQuery Mobile: For Fun and Profit
jQuery Mobile: For Fun and ProfitjQuery Mobile: For Fun and Profit
jQuery Mobile: For Fun and Profit
Daniel Cousineau
 
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
Daniel Cousineau
 

More from Daniel Cousineau (6)

Git, an Illustrated Primer
Git, an Illustrated PrimerGit, an Illustrated Primer
Git, an Illustrated Primer
 
JavaScript Primer
JavaScript PrimerJavaScript Primer
JavaScript Primer
 
JavaScript Primer
JavaScript PrimerJavaScript Primer
JavaScript Primer
 
Disregard Inputs, Acquire Zend_Form
Disregard Inputs, Acquire Zend_FormDisregard Inputs, Acquire Zend_Form
Disregard Inputs, Acquire Zend_Form
 
jQuery Mobile: For Fun and Profit
jQuery Mobile: For Fun and ProfitjQuery Mobile: For Fun and Profit
jQuery Mobile: For Fun and Profit
 
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
 

Recently uploaded

Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 

Recently uploaded (20)

Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 

Automated Deployment With Phing

  • 1. Automated Deployment With Phing Or: How I Will Replace You With A Very Small Shell Script ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 1
  • 2. Who Daniel Cousineau Senior Software Applications Developer Texas A&M University Division of Student Affairs Department of IT http://www.toosweettobesour.com/ @dcousineau ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 2
  • 3. The Problem ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 3
  • 4. Human beings make mistakes ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 4
  • 5. We aren’t as accurate each repetition ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 5
  • 6. Machines don’t have this problem ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 6
  • 7. They do the same thing every time (supposedly) ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 7
  • 8. At Any Given Time New Code New Configuration New Database Schema New Static Files ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 8
  • 9. A Lot To Remember Did you remember to upload ALL new files? Did you remember to update your DB? Did you remember to correct your config? ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 9
  • 10. Even Worse Did you clear your caches? Did you delete that old file/plugin? In the upload process, was your configuration overwritten? Did you upload ALL the changed files? When did you last upload? ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 10
  • 11. The Solution ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 11
  • 12. Automation! Build scripts! We are programmers after all… ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 12
  • 13. ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 13 Don’t Do More Work Than You Have To!
  • 14. ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 14 Work Hard At Being Lazy!
  • 15. What is Automation? Automated deployment means a single command Locks your live site Uploads changed files Clears caches and temporary files Updates the database schema Runs other cron tasks Unlocks your live site ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 15
  • 16. Why Do We Automate? Deployment is tricky Repetition degrades quality She sells sea shells by the sea shore ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 16
  • 17. When Is Automation Used? All the time! Staging Live Probably best to use it on your dev box too! ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 17
  • 18. The Basics ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 18
  • 19. Tools of the Trade Build System Phing Apache ANT Capastrano Plain PHP or BASH or BAT Files File Transfer Rsync (*NIX Environments) Xcopy (Windows Environments) Configuration Management Database Migration DBDeploy Doctrine ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 19
  • 20. 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 ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 20
  • 21. 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 ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 21
  • 22. Installing Phing pear channel-discover pear.phing.info pear install phing/Phing Want all the little dependencies? pear config-set preferred_state alpha pear install –alldepsphing/Phing pear config-set preferred_state stable ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 22
  • 23. 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 ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 23
  • 24. Syntax XML If you don’t already know it, you have bigger problems Variables ${variablename} Conventions Psuedo-Namespaces using periods ${namespace.variable.name} ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 24
  • 25. 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, live) or task (migrate, test, etc.) build.properties Technically an INI file that contains variables to be included by build files. ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 25
  • 26. Basic build.xml ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 26 <?xml version="1.0" encoding="UTF-8"?> <project name="ZendCon" default="default" basedir="."> <property file="build.properties" /> <target name="default">     <echo message="Howdy World!" /> </target>        </project>
  • 27. Basic build.properties ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 27 source.directory = /src ## Database Configuration db.user = username db.pass = password db.host = localhost db.name = database
  • 28. File Transfer ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 28
  • 29. Techniques Built in Phing Copy Task Cross Platform Slow Not over network Version Control Checkout/Update Syncs deleted files User created files usually ignored Rsync Great for *NIX environments. Almost guaranteed to be installed on Linux, BSD, Mac OSX Can be installed on Windows Xcopy Good for Windows environments Faster than Phing Copy Not over network ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 29
  • 30. Pitfalls Cleanup Deleted Source Files Usually only a problem when you have * include patterns ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 30
  • 31. Pitfalls User created files are a HUGE pitfall /htdocs/images/upload Sync programs usually will delete content your deployment machine doesn’t have What if user upload are mixed in with files you want to manage? Solutions Keep user created content completely separated. The further up the file tree and consolidated the better. Separate static file server, Amazon S3, or other style CDNs ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 31
  • 32. Executing External Tools Nearly all file transfer tools will be external commands For this we need the Exec task ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 32 <exec command="cp file1 file2" />
  • 33. Rsync So many different options you’re best off finding your own tutorials or reading MAN pages rsync -aCvz -e 'ssh -i /path/to/ssh-key' ${project.basedir}/src user@domain: ${staging.deployment.directory}/ ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 33
  • 34. Rsync Options Of Note -a archive-mode Recursive copy, preserve everything, etc. -C cvs-exclude Ignore .cvs, .svn, and other version control artifacts -v verbose Know EXACTLY what’s going on -z compress Compress information transmitted -e alternative remote shell Use a custom SSH command (namely use key-pair) ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 34
  • 35. Xcopy Best when your live deployment process involves copying to a network share on Windows machines xcopy ${project.basedir}${source.directory} ${staging.deployment.directory} /D /I /Y /S /E /Exclude:${project.basedir}taging.deployment.exclude ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 35
  • 36. Xcopy Options Of Note /d Update only those files that are different (timestamps) /i Creates target directories if they don’t exist /y Do not prompt /s Copy all directories and sub-directories… /e …Even if the directories are empty /exclude Exclude files based on glob patterns ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 36
  • 37. Xcopy Exclude File Example ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 37 mpbr />ploadsbr />
  • 38. Configuration Management ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 38
  • 39. Techniques Check incoming domain www.domain.com means load production configuration localhost/domain.com means load development configuration Check for an environment file Contents of DOCUMENT_ROOT/.env determine configuration Copy over during deployment ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 39
  • 40. Check Incoming Domain Pros No chance for error Cons Detection is a weak link Especially when development, staging, and live have different web servers (e.g. Apache to IIS) ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 40
  • 41. Check for an Environment File Pros Consistent regardless of Server or OS changes Easy to repair Quick FTP or SSH Easy Testing Just swap file contents Cons Forget to copy changes? ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 41
  • 42. Copy Over During Deployment Pros Images and CSS now manageable Reduce redundancy Simple to repurpose regular push command Cons Difficult to manage Forget to copy changes? ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 42
  • 43. Which one to choose? Depends on your application architecture Depends on your environment You’ll know what’s best for your project I use a combination of Environment File and Copy Over During Deployment ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 43
  • 44. Database Migration ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 44
  • 45. Database Deployment Philosophy “Versions” often referred to as “Deltas” Each Delta has an UP and a DOWN script UP makes the changes DOWN reverts the changes Each change should be a non-destructive schema change Unless of course you need data alteration ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 45
  • 46. DBDeploy Philosophy Each delta is 2 native SQL scripts Separated by --//@undo Database version is stored in a special table Version X was applied at TIMESTAMP… Beware corruption! ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 46
  • 47. DBDeploy Under The Hood Connect to the database, read from changelog table, get the most current revision installed Retrieve all delta files newer that the current revision Revision numbers are based off of alphabetic sorting, name your files accordingly Pull all the “UP” changes and concatenate them to a migration script Up to YOU to run the migration script ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 47
  • 48. Installing DBDeploy Is Phing already installed? Great! So is DBDeploy… Create the changelog table Track the current version of your DB ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 48 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   ); ALTER TABLE changelog ADD CONSTRAINT Pkchangelog PRIMARY KEY (change_number, delta_set);
  • 49. Basic Delta: 01_init.sql ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 49 --//   CREATE TABLE IF NOT EXISTS `users` (     `id` int(10) unsigned NOT NULL auto_increment,     `handle` varchar(25) NOT NULL default '',     PRIMARY KEY  (`id`),     UNIQUE KEY `users_handle_index` (`handle`)   ) ENGINE=InnoDB  DEFAULT;   --//@UNDO     DROP TABLE IF EXISTS `users`;   --//
  • 50. Run Migration First add a task to your Phing build file ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 50 <target name="migrate"> </target>
  • 51. Run Migration Generate the SQL migration file ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 51 <target name="migrate"> <dbdeploy url="mysql:host=${db.host};dbname=${db.name}" userid="${db.user}" password="${db.pass}" dir="${project.basedir}/db/deltas" outputfile="${project.basedir}/up.sql" undooutputfile="${project.basedir}/down.sql" /> </target>
  • 52. Run Migration Execute the SQL script ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 52 <target name="migrate"> <dbdeploy url="mysql:host=${db.host};dbname=${db.name}" userid="${db.user}" password="${db.pass}" dir="${project.basedir}/db/deltas" outputfile="${project.basedir}/up.sql" undooutputfile="${project.basedir}/down.sql" /> <exec command="/usr/bin/mysql -h${db.local.host} -u${db.local.user} -p ${db.local.pass} ${db.local.name} < ${project.basedir}/up.sql" dir="${project.basedir}" checkreturn="true"> </target>
  • 53. Pitfalls Make sure you have a good CLI app for loading a SQL file /usr/bin/mysql mysql.exe Build script travelling across operating systems? Write your own Phing task to execute the migration output? Was the changelog table created in the first place? ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 53
  • 54. Doctrine Database Migrations Integrated into the Doctrine CLI tool ./doctrine migrate Same philosophies BUT, deltas are PHP objects that contain an UP and a DOWN method Run using the Phing exec task ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 54
  • 55. Other Database Migration Tools http://www.liquibase.org/ ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 55
  • 56. Closing Thoughts ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 56
  • 57. Further Resources The people around you More people than you know automate their deployment There are many, many different techniques My techniques may suck for your particular setup #phpcon freenode Many of the speakers hang out there Many smart people hang out there I HANG OUT THERE! Therefore I am smart ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 57
  • 58. Further Resources Blogs http://phpdeveloper.org Documentation http://phing.info http://dbdeploy.com Google Experimentation Pushing to a local directory Pushing to a virtual machine ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 58
  • 59. Questions? ZendCon '09 Automated Deployment With Phing - Daniel Cousineau 59

Editor's Notes

  1. Image Credit: http://www.acadweb.wwu.edu/dbrunner/
  2. Image Credit: http://commons.wikimedia.org/wiki/File:Archery_target.jpg
  3. Image Credit: http://www.drmcninja.com/junk/highfiveshirt.png