Senior Software Applications Developer Texas A&M University Division of Student Affairs Department of IT http://www.toosweettobesour.com/ @dcousineau Automated Deployment With Phing - Daniel Cousineau ZendCon '09 2
ALL new files? Did you remember to update your DB? Did you remember to correct your config? Automated Deployment With Phing - Daniel Cousineau ZendCon '09 9
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? Automated Deployment With Phing - Daniel Cousineau ZendCon '09 10
your live site Uploads changed files Clears caches and temporary files Updates the database schema Runs other cron tasks Unlocks your live site Automated Deployment With Phing - Daniel Cousineau ZendCon '09 16
be small and specialized. Example Targets: clean Clear temporary and cached files copy Copy files to their intended destination migrate Upgrade the database schema Automated Deployment With Phing - Daniel Cousineau ZendCon '09 21
"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 Automated Deployment With Phing - Daniel Cousineau ZendCon '09 22
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 Automated Deployment With Phing - Daniel Cousineau ZendCon '09 24
you have bigger problems Variables ${variablename} Conventions Psuedo-Namespaces using periods ${namespace.variable.name} Automated Deployment With Phing - Daniel Cousineau ZendCon '09 25
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. Automated Deployment With Phing - Daniel Cousineau ZendCon '09 26
Slow Not over network 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 Version Control Checkout/Update Syncs deleted files User created files usually ignored Automated Deployment With Phing - Daniel Cousineau ZendCon '09 30
/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 consolodated the better. Separate static file server, Amazon S3, or other style CDNs Automated Deployment With Phing - Daniel Cousineau ZendCon '09 31
problem when you have * include patterns Also creates the previous user created file dillema Automated Deployment With Phing - Daniel Cousineau ZendCon '09 32
be external commands For this we need the Exec task <exec command="cp file1 file2" /> Automated Deployment With Phing - Daniel Cousineau ZendCon '09 33
your own tutorials or reading MAN pages rsync -aCvz -e 'ssh -i /path/to/ssh-key' ${project.basedir}/src user@domain: ${staging.deployment.directory}/ Automated Deployment With Phing - Daniel Cousineau ZendCon '09 34
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 35
to a network share on Windows machines xcopy ${project.basedir}${source.directory}\* ${staging.deployment.directory} /D /I /Y /S /E /Exclude:${project.basedir}\staging.deploy ment.exclude Automated Deployment With Phing - Daniel Cousineau ZendCon '09 36
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 37
configuration localhost/domain.com means load development configuration Check for an environment file Contents of DOCUMENT_ROOT/.env determine configuration Copy over during deployment Automated Deployment With Phing - Daniel Cousineau ZendCon '09 40
Cons Detection is a weak link Especially when development, staging, and live have different web servers (e.g. Apache to IIS) Automated Deployment With Phing - Daniel Cousineau ZendCon '09 41
of Server or OS changes Easy to repair Quick FTP or SSH Easy Testing Just swap file contents Cons Forget to copy changes? Automated Deployment With Phing - Daniel Cousineau ZendCon '09 42
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 Automated Deployment With Phing - Daniel Cousineau ZendCon '09 44
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 Automated Deployment With Phing - Daniel Cousineau ZendCon '09 46
Separated by --//@undo Database version is stored in a special table Beware corruption! Automated Deployment With Phing - Daniel Cousineau ZendCon '09 47
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 Automated Deployment With Phing - Daniel Cousineau ZendCon '09 48
DBDeploy… Create the changelog table Track the current version of your DB 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); Automated Deployment With Phing - Daniel Cousineau ZendCon '09 49
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? Automated Deployment With Phing - Daniel Cousineau ZendCon '09 54
./doctrine migrate Same philosophies BUT, deltas are PHP objects that contain an UP and a DOWN method Run using the Phing exec task Automated Deployment With Phing - Daniel Cousineau ZendCon '09 55
than you know automate their deployment There are many, many different techniques My techniques may suck for your particular setup #phpc on freenode Many of the speakers hang out there Many smart people hang out there I HANG OUT THERE! Automated Deployment With Phing - Daniel Cousineau ZendCon '09 58
http://dbdeploy.com Google Experimentation Pushing to a local directory Pushing to a virtual machine Automated Deployment With Phing - Daniel Cousineau ZendCon '09 59