Automated Deployment With PhingOr: How I Will Replace You With A Very Small Shell ScriptZendCon '09Automated Deployment With Phing - Daniel Cousineau1
WhoDaniel CousineauSenior Software Applications Developer	Texas A&M University	Division of Student Affairs	Department of IThttp://www.toosweettobesour.com/@dcousineauZendCon '09Automated Deployment With Phing - Daniel Cousineau2
The ProblemZendCon '09Automated Deployment With Phing - Daniel Cousineau3
Human beings make mistakesZendCon '09Automated Deployment With Phing - Daniel Cousineau4
We aren’t as accurate each repetitionZendCon '09Automated Deployment With Phing - Daniel Cousineau5
Machines don’t have this problemZendCon '09Automated Deployment With Phing - Daniel Cousineau6
They do the same thing every time (supposedly)ZendCon '09Automated Deployment With Phing - Daniel Cousineau7
At Any Given TimeNew CodeNew ConfigurationNew Database SchemaNew Static FilesZendCon '09Automated Deployment With Phing - Daniel Cousineau8
A Lot To RememberDid you remember to upload ALL new files?Did you remember to update your DB?Did you remember to correct your config?ZendCon '09Automated Deployment With Phing - Daniel Cousineau9
Even WorseDid 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 '09Automated Deployment With Phing - Daniel Cousineau10
The SolutionZendCon '09Automated Deployment With Phing - Daniel Cousineau11
Automation!Build scripts!We are programmers after all…ZendCon '09Automated Deployment With Phing - Daniel Cousineau12
ZendCon '09Automated Deployment With Phing - Daniel Cousineau13Don’t Do More Work Than You Have To!
ZendCon '09Automated Deployment With Phing - Daniel Cousineau14Work Hard At Being Lazy!
What is Automation?Automated deployment means a single commandLocks your live siteUploads changed filesClears caches and temporary filesUpdates the database schemaRuns other cron tasksUnlocks your live siteZendCon '09Automated Deployment With Phing - Daniel Cousineau15
Why Do We Automate?Deployment is trickyRepetition degrades qualityShe sells sea shells by the sea shoreZendCon '09Automated Deployment With Phing - Daniel Cousineau16
When Is Automation Used?All the time!StagingLiveProbably best to use it on your dev box too!ZendCon '09Automated Deployment With Phing - Daniel Cousineau17
The BasicsZendCon '09Automated Deployment With Phing - Daniel Cousineau18
Tools of the TradeBuild SystemPhingApache ANTCapastranoPlain PHP or BASH or BAT FilesFile TransferRsync (*NIX Environments)Xcopy (Windows Environments)Configuration ManagementDatabase MigrationDBDeployDoctrineZendCon '09Automated Deployment With Phing - Daniel Cousineau19
Phing PhilosophyBuild scripts contains "Targets"Targets should be small and specialized.Example Targets:cleanClear temporary and cached filescopyCopy files to their intended destinationmigrateUpgrade the database schemaZendCon '09Automated Deployment With Phing - Daniel Cousineau20
Phing PhilosophyTargets can have dependenciesTarget "live" can depend on clean, copy, and migrateMeaning, when we run the "live" target, it first runs clean, copy, then migrateAnd any tasks they depend onZendCon '09Automated Deployment With Phing - Daniel Cousineau21
Installing Phingpear channel-discover pear.phing.infopear install phing/PhingWant all the little dependencies?pear config-set preferred_state alphapear install –alldepsphing/Phingpear config-set preferred_state stableZendCon '09Automated Deployment With Phing - Daniel Cousineau22
Running Phing$> phing –vLists Phing versionPhing expects to find a file "build.xml" in the current directorybuild.xml defines the targetsYou can use the "-f <filename>" flag to specify an alternate build file like$> phing -f build-live.xmlZendCon '09Automated Deployment With Phing - Daniel Cousineau23
SyntaxXMLIf you don’t already know it, you have bigger problemsVariables${variablename}ConventionsPsuedo-Namespaces using periods${namespace.variable.name}ZendCon '09Automated Deployment With Phing - Daniel Cousineau24
Basic Conventionsbuild.xmlCentral repository of your top-level tasksbuild-*.xmlCan be included into build.xml. Usually for grouping by target (dev, staging, live) or task (migrate, test, etc.)build.propertiesTechnically an INI file that contains variables to be included by build files.ZendCon '09Automated Deployment With Phing - Daniel Cousineau25
Basic build.xmlZendCon '09Automated Deployment With Phing - Daniel Cousineau26<?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.propertiesZendCon '09Automated Deployment With Phing - Daniel Cousineau27source.directory = /src## Database Configurationdb.user = usernamedb.pass = passworddb.host = localhostdb.name = database
File TransferZendCon '09Automated Deployment With Phing - Daniel Cousineau28
TechniquesBuilt in Phing Copy TaskCross PlatformSlowNot over networkVersion Control Checkout/UpdateSyncs deleted filesUser created files usually ignoredRsyncGreat for *NIX environments.Almost guaranteed to be installed onLinux, BSD, Mac OSXCan be installed on WindowsXcopyGood for Windows environmentsFaster than Phing CopyNot over networkZendCon '09Automated Deployment With Phing - Daniel Cousineau29
PitfallsCleanup Deleted Source FilesUsually only a problem when you have * include patternsZendCon '09Automated Deployment With Phing - Daniel Cousineau30
PitfallsUser created files are a HUGE pitfall/htdocs/images/uploadSync programs usually will delete content your deployment machine doesn’t haveWhat if user upload are mixed in with files you want to manage?SolutionsKeep user created content completely separated. The further up the file tree and consolidated the better.Separate static file server, Amazon S3, or other style CDNsZendCon '09Automated Deployment With Phing - Daniel Cousineau31
Executing External ToolsNearly all file transfer tools will be external commandsFor this we need the Exec taskZendCon '09Automated Deployment With Phing - Daniel Cousineau32<exec command="cp file1 file2" />
RsyncSo many different options you’re best off finding your own tutorials or reading MAN pagesrsync -aCvz	-e 'ssh -i /path/to/ssh-key'	${project.basedir}/srcuser@domain: ${staging.deployment.directory}/ZendCon '09Automated Deployment With Phing - Daniel Cousineau33
Rsync Options Of Note-a	archive-modeRecursive copy, preserve everything, etc.-C	cvs-excludeIgnore .cvs, .svn, and other version control artifacts-v	verboseKnow EXACTLY what’s going on-z	compressCompress information transmitted-e	alternative remote shellUse a custom SSH command (namely use key-pair)ZendCon '09Automated Deployment With Phing - Daniel Cousineau34
XcopyBest when your live deployment process involves copying to a network share on Windows machinesxcopy	${project.basedir}${source.directory}\*	${staging.deployment.directory}	/D /I /Y /S /E	/Exclude:${project.basedir}\staging.deployment.excludeZendCon '09Automated Deployment With Phing - Daniel Cousineau35
Xcopy Options Of Note/dUpdate only those files that are different (timestamps)/iCreates target directories if they don’t exist/yDo not prompt/sCopy all directories and sub-directories…/e…Even if the directories are empty	/excludeExclude files based on glob patternsZendCon '09Automated Deployment With Phing - Daniel Cousineau36
Xcopy Exclude File ExampleZendCon '09Automated Deployment With Phing - Daniel Cousineau37\tmp\\uploads\
Configuration ManagementZendCon '09Automated Deployment With Phing - Daniel Cousineau38
TechniquesCheck incoming domainwww.domain.com means load production configurationlocalhost/domain.com means load development configurationCheck for an environment fileContents of DOCUMENT_ROOT/.env determine configurationCopy over during deploymentZendCon '09Automated Deployment With Phing - Daniel Cousineau39
Check Incoming Domain	ProsNo chance for errorConsDetection is a weak linkEspecially when development, staging, and live have different web servers (e.g. Apache to IIS)ZendCon '09Automated Deployment With Phing - Daniel Cousineau40
Check for an Environment FileProsConsistent regardless of Server or OS changesEasy to repairQuick FTP or SSHEasy TestingJust swap file contentsConsForget to copy changes?ZendCon '09Automated Deployment With Phing - Daniel Cousineau41
Copy Over During DeploymentProsImages and CSS now manageableReduce redundancySimple to repurpose regular push commandConsDifficult to manageForget to copy changes?ZendCon '09Automated Deployment With Phing - Daniel Cousineau42
Which one to choose?Depends on your application architectureDepends on your environmentYou’ll know what’s best for your projectI use a combination of Environment File and Copy Over During DeploymentZendCon '09Automated Deployment With Phing - Daniel Cousineau43
Database MigrationZendCon '09Automated Deployment With Phing - Daniel Cousineau44
Database Deployment Philosophy“Versions” often referred to as “Deltas”Each Delta has an UP and a DOWN scriptUP makes the changesDOWN reverts the changesEach change should be a non-destructive schema changeUnless of course you need data alterationZendCon '09Automated Deployment With Phing - Daniel Cousineau45
DBDeploy PhilosophyEach delta is 2 native SQL scriptsSeparated by --//@undoDatabase version is stored in a special tableVersion X was applied at TIMESTAMP…Beware corruption!ZendCon '09Automated Deployment With Phing - Daniel Cousineau46
DBDeploy Under The HoodConnect to the database, read from changelog table, get the most current revision installedRetrieve all delta files newer that the current revisionRevision numbers are based off of alphabetic sorting, name your files accordinglyPull all the “UP” changes and concatenate them to a migration scriptUp to YOU to run the migration scriptZendCon '09Automated Deployment With Phing - Daniel Cousineau47
Installing DBDeployIs Phing already installed? Great! So is DBDeploy…Create the changelog tableTrack the current version of your DBZendCon '09Automated Deployment With Phing - Daniel Cousineau48CREATE 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.sqlZendCon '09Automated Deployment With Phing - Daniel Cousineau49--//  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 MigrationFirst add a task to your Phing build fileZendCon '09Automated Deployment With Phing - Daniel Cousineau50<target name="migrate"></target>
Run MigrationGenerate the SQL migration fileZendCon '09Automated Deployment With Phing - Daniel Cousineau51<target name="migrate">  <dbdeployurl="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 MigrationExecute the SQL scriptZendCon '09Automated Deployment With Phing - Daniel Cousineau52<target name="migrate">  <dbdeployurl="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>
PitfallsMake sure you have a good CLI app for loading a SQL file/usr/bin/mysqlmysql.exeBuild 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 '09Automated Deployment With Phing - Daniel Cousineau53
Doctrine Database MigrationsIntegrated into the Doctrine CLI tool./doctrine migrateSame philosophiesBUT, deltas are PHP objects that contain an UP and a DOWN methodRun using the Phing exec taskZendCon '09Automated Deployment With Phing - Daniel Cousineau54
Other Database Migration Toolshttp://www.liquibase.org/ZendCon '09Automated Deployment With Phing - Daniel Cousineau55
Closing ThoughtsZendCon '09Automated Deployment With Phing - Daniel Cousineau56
Further ResourcesThe people around youMore people than you know automate their deploymentThere are many, many different techniquesMy techniques may suck for your particular setup#phpcon freenodeMany of the speakers hang out thereMany smart people hang out thereI HANG OUT THERE!Therefore I am smartZendCon '09Automated Deployment With Phing - Daniel Cousineau57
Further ResourcesBlogshttp://phpdeveloper.orgDocumentationhttp://phing.infohttp://dbdeploy.comGoogleExperimentationPushing to a local directoryPushing to a virtual machineZendCon '09Automated Deployment With Phing - Daniel Cousineau58
Questions?ZendCon '09Automated Deployment With Phing - Daniel Cousineau59
http://joind.in/937

Automated Deployment With Phing

  • 1.
    Automated Deployment WithPhingOr: How I Will Replace You With A Very Small Shell ScriptZendCon '09Automated Deployment With Phing - Daniel Cousineau1
  • 2.
    WhoDaniel CousineauSenior SoftwareApplications Developer Texas A&M University Division of Student Affairs Department of IThttp://www.toosweettobesour.com/@dcousineauZendCon '09Automated Deployment With Phing - Daniel Cousineau2
  • 3.
    The ProblemZendCon '09AutomatedDeployment With Phing - Daniel Cousineau3
  • 4.
    Human beings makemistakesZendCon '09Automated Deployment With Phing - Daniel Cousineau4
  • 5.
    We aren’t asaccurate each repetitionZendCon '09Automated Deployment With Phing - Daniel Cousineau5
  • 6.
    Machines don’t havethis problemZendCon '09Automated Deployment With Phing - Daniel Cousineau6
  • 7.
    They do thesame thing every time (supposedly)ZendCon '09Automated Deployment With Phing - Daniel Cousineau7
  • 8.
    At Any GivenTimeNew CodeNew ConfigurationNew Database SchemaNew Static FilesZendCon '09Automated Deployment With Phing - Daniel Cousineau8
  • 9.
    A Lot ToRememberDid you remember to upload ALL new files?Did you remember to update your DB?Did you remember to correct your config?ZendCon '09Automated Deployment With Phing - Daniel Cousineau9
  • 10.
    Even WorseDid youclear 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 '09Automated Deployment With Phing - Daniel Cousineau10
  • 11.
    The SolutionZendCon '09AutomatedDeployment With Phing - Daniel Cousineau11
  • 12.
    Automation!Build scripts!We areprogrammers after all…ZendCon '09Automated Deployment With Phing - Daniel Cousineau12
  • 13.
    ZendCon '09Automated DeploymentWith Phing - Daniel Cousineau13Don’t Do More Work Than You Have To!
  • 14.
    ZendCon '09Automated DeploymentWith Phing - Daniel Cousineau14Work Hard At Being Lazy!
  • 15.
    What is Automation?Automateddeployment means a single commandLocks your live siteUploads changed filesClears caches and temporary filesUpdates the database schemaRuns other cron tasksUnlocks your live siteZendCon '09Automated Deployment With Phing - Daniel Cousineau15
  • 16.
    Why Do WeAutomate?Deployment is trickyRepetition degrades qualityShe sells sea shells by the sea shoreZendCon '09Automated Deployment With Phing - Daniel Cousineau16
  • 17.
    When Is AutomationUsed?All the time!StagingLiveProbably best to use it on your dev box too!ZendCon '09Automated Deployment With Phing - Daniel Cousineau17
  • 18.
    The BasicsZendCon '09AutomatedDeployment With Phing - Daniel Cousineau18
  • 19.
    Tools of theTradeBuild SystemPhingApache ANTCapastranoPlain PHP or BASH or BAT FilesFile TransferRsync (*NIX Environments)Xcopy (Windows Environments)Configuration ManagementDatabase MigrationDBDeployDoctrineZendCon '09Automated Deployment With Phing - Daniel Cousineau19
  • 20.
    Phing PhilosophyBuild scriptscontains "Targets"Targets should be small and specialized.Example Targets:cleanClear temporary and cached filescopyCopy files to their intended destinationmigrateUpgrade the database schemaZendCon '09Automated Deployment With Phing - Daniel Cousineau20
  • 21.
    Phing PhilosophyTargets canhave dependenciesTarget "live" can depend on clean, copy, and migrateMeaning, when we run the "live" target, it first runs clean, copy, then migrateAnd any tasks they depend onZendCon '09Automated Deployment With Phing - Daniel Cousineau21
  • 22.
    Installing Phingpear channel-discoverpear.phing.infopear install phing/PhingWant all the little dependencies?pear config-set preferred_state alphapear install –alldepsphing/Phingpear config-set preferred_state stableZendCon '09Automated Deployment With Phing - Daniel Cousineau22
  • 23.
    Running Phing$> phing–vLists Phing versionPhing expects to find a file "build.xml" in the current directorybuild.xml defines the targetsYou can use the "-f <filename>" flag to specify an alternate build file like$> phing -f build-live.xmlZendCon '09Automated Deployment With Phing - Daniel Cousineau23
  • 24.
    SyntaxXMLIf you don’talready know it, you have bigger problemsVariables${variablename}ConventionsPsuedo-Namespaces using periods${namespace.variable.name}ZendCon '09Automated Deployment With Phing - Daniel Cousineau24
  • 25.
    Basic Conventionsbuild.xmlCentral repositoryof your top-level tasksbuild-*.xmlCan be included into build.xml. Usually for grouping by target (dev, staging, live) or task (migrate, test, etc.)build.propertiesTechnically an INI file that contains variables to be included by build files.ZendCon '09Automated Deployment With Phing - Daniel Cousineau25
  • 26.
    Basic build.xmlZendCon '09AutomatedDeployment With Phing - Daniel Cousineau26<?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.propertiesZendCon '09AutomatedDeployment With Phing - Daniel Cousineau27source.directory = /src## Database Configurationdb.user = usernamedb.pass = passworddb.host = localhostdb.name = database
  • 28.
    File TransferZendCon '09AutomatedDeployment With Phing - Daniel Cousineau28
  • 29.
    TechniquesBuilt in PhingCopy TaskCross PlatformSlowNot over networkVersion Control Checkout/UpdateSyncs deleted filesUser created files usually ignoredRsyncGreat for *NIX environments.Almost guaranteed to be installed onLinux, BSD, Mac OSXCan be installed on WindowsXcopyGood for Windows environmentsFaster than Phing CopyNot over networkZendCon '09Automated Deployment With Phing - Daniel Cousineau29
  • 30.
    PitfallsCleanup Deleted SourceFilesUsually only a problem when you have * include patternsZendCon '09Automated Deployment With Phing - Daniel Cousineau30
  • 31.
    PitfallsUser created filesare a HUGE pitfall/htdocs/images/uploadSync programs usually will delete content your deployment machine doesn’t haveWhat if user upload are mixed in with files you want to manage?SolutionsKeep user created content completely separated. The further up the file tree and consolidated the better.Separate static file server, Amazon S3, or other style CDNsZendCon '09Automated Deployment With Phing - Daniel Cousineau31
  • 32.
    Executing External ToolsNearlyall file transfer tools will be external commandsFor this we need the Exec taskZendCon '09Automated Deployment With Phing - Daniel Cousineau32<exec command="cp file1 file2" />
  • 33.
    RsyncSo many differentoptions you’re best off finding your own tutorials or reading MAN pagesrsync -aCvz -e 'ssh -i /path/to/ssh-key' ${project.basedir}/srcuser@domain: ${staging.deployment.directory}/ZendCon '09Automated Deployment With Phing - Daniel Cousineau33
  • 34.
    Rsync Options OfNote-a archive-modeRecursive copy, preserve everything, etc.-C cvs-excludeIgnore .cvs, .svn, and other version control artifacts-v verboseKnow EXACTLY what’s going on-z compressCompress information transmitted-e alternative remote shellUse a custom SSH command (namely use key-pair)ZendCon '09Automated Deployment With Phing - Daniel Cousineau34
  • 35.
    XcopyBest when yourlive deployment process involves copying to a network share on Windows machinesxcopy ${project.basedir}${source.directory}\* ${staging.deployment.directory} /D /I /Y /S /E /Exclude:${project.basedir}\staging.deployment.excludeZendCon '09Automated Deployment With Phing - Daniel Cousineau35
  • 36.
    Xcopy Options OfNote/dUpdate only those files that are different (timestamps)/iCreates target directories if they don’t exist/yDo not prompt/sCopy all directories and sub-directories…/e…Even if the directories are empty /excludeExclude files based on glob patternsZendCon '09Automated Deployment With Phing - Daniel Cousineau36
  • 37.
    Xcopy Exclude FileExampleZendCon '09Automated Deployment With Phing - Daniel Cousineau37\tmp\\uploads\
  • 38.
    Configuration ManagementZendCon '09AutomatedDeployment With Phing - Daniel Cousineau38
  • 39.
    TechniquesCheck incoming domainwww.domain.commeans load production configurationlocalhost/domain.com means load development configurationCheck for an environment fileContents of DOCUMENT_ROOT/.env determine configurationCopy over during deploymentZendCon '09Automated Deployment With Phing - Daniel Cousineau39
  • 40.
    Check Incoming Domain ProsNochance for errorConsDetection is a weak linkEspecially when development, staging, and live have different web servers (e.g. Apache to IIS)ZendCon '09Automated Deployment With Phing - Daniel Cousineau40
  • 41.
    Check for anEnvironment FileProsConsistent regardless of Server or OS changesEasy to repairQuick FTP or SSHEasy TestingJust swap file contentsConsForget to copy changes?ZendCon '09Automated Deployment With Phing - Daniel Cousineau41
  • 42.
    Copy Over DuringDeploymentProsImages and CSS now manageableReduce redundancySimple to repurpose regular push commandConsDifficult to manageForget to copy changes?ZendCon '09Automated Deployment With Phing - Daniel Cousineau42
  • 43.
    Which one tochoose?Depends on your application architectureDepends on your environmentYou’ll know what’s best for your projectI use a combination of Environment File and Copy Over During DeploymentZendCon '09Automated Deployment With Phing - Daniel Cousineau43
  • 44.
    Database MigrationZendCon '09AutomatedDeployment With Phing - Daniel Cousineau44
  • 45.
    Database Deployment Philosophy“Versions”often referred to as “Deltas”Each Delta has an UP and a DOWN scriptUP makes the changesDOWN reverts the changesEach change should be a non-destructive schema changeUnless of course you need data alterationZendCon '09Automated Deployment With Phing - Daniel Cousineau45
  • 46.
    DBDeploy PhilosophyEach deltais 2 native SQL scriptsSeparated by --//@undoDatabase version is stored in a special tableVersion X was applied at TIMESTAMP…Beware corruption!ZendCon '09Automated Deployment With Phing - Daniel Cousineau46
  • 47.
    DBDeploy Under TheHoodConnect to the database, read from changelog table, get the most current revision installedRetrieve all delta files newer that the current revisionRevision numbers are based off of alphabetic sorting, name your files accordinglyPull all the “UP” changes and concatenate them to a migration scriptUp to YOU to run the migration scriptZendCon '09Automated Deployment With Phing - Daniel Cousineau47
  • 48.
    Installing DBDeployIs Phingalready installed? Great! So is DBDeploy…Create the changelog tableTrack the current version of your DBZendCon '09Automated Deployment With Phing - Daniel Cousineau48CREATE 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.sqlZendCon'09Automated Deployment With Phing - Daniel Cousineau49--//  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 MigrationFirst adda task to your Phing build fileZendCon '09Automated Deployment With Phing - Daniel Cousineau50<target name="migrate"></target>
  • 51.
    Run MigrationGenerate theSQL migration fileZendCon '09Automated Deployment With Phing - Daniel Cousineau51<target name="migrate"> <dbdeployurl="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 MigrationExecute theSQL scriptZendCon '09Automated Deployment With Phing - Daniel Cousineau52<target name="migrate"> <dbdeployurl="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.
    PitfallsMake sure youhave a good CLI app for loading a SQL file/usr/bin/mysqlmysql.exeBuild 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 '09Automated Deployment With Phing - Daniel Cousineau53
  • 54.
    Doctrine Database MigrationsIntegratedinto the Doctrine CLI tool./doctrine migrateSame philosophiesBUT, deltas are PHP objects that contain an UP and a DOWN methodRun using the Phing exec taskZendCon '09Automated Deployment With Phing - Daniel Cousineau54
  • 55.
    Other Database MigrationToolshttp://www.liquibase.org/ZendCon '09Automated Deployment With Phing - Daniel Cousineau55
  • 56.
    Closing ThoughtsZendCon '09AutomatedDeployment With Phing - Daniel Cousineau56
  • 57.
    Further ResourcesThe peoplearound youMore people than you know automate their deploymentThere are many, many different techniquesMy techniques may suck for your particular setup#phpcon freenodeMany of the speakers hang out thereMany smart people hang out thereI HANG OUT THERE!Therefore I am smartZendCon '09Automated Deployment With Phing - Daniel Cousineau57
  • 58.
    Further ResourcesBlogshttp://phpdeveloper.orgDocumentationhttp://phing.infohttp://dbdeploy.comGoogleExperimentationPushing toa local directoryPushing to a virtual machineZendCon '09Automated Deployment With Phing - Daniel Cousineau58
  • 59.
    Questions?ZendCon '09Automated DeploymentWith Phing - Daniel Cousineau59
  • 60.

Editor's Notes

  • #5 Image Credit: http://www.acadweb.wwu.edu/dbrunner/
  • #6 Image Credit: http://commons.wikimedia.org/wiki/File:Archery_target.jpg
  • #61 Image Credit: http://www.drmcninja.com/junk/highfiveshirt.png