deployment with subversion - lorna mitchell

35
Ibuildings PHP Deployment with Subversion Lorna Mitchell Ibuildings The PHP Professionals

Upload: dpc

Post on 05-Dec-2014

10.336 views

Category:

Technology


2 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Deployment With Subversion - Lorna Mitchell

Ibuildings

PHP Deployment with Subversion

Lorna Mitchell

IbuildingsThe PHP Professionals

Page 2: Deployment With Subversion - Lorna Mitchell

2

About Me

• Lorna Mitchell• PHP Developer/Consultant/Trainer with Ibuildings• ZCE• Member of http://www.phpwomen.org• Personal blog at http://www.lornajane.net

2

Page 3: Deployment With Subversion - Lorna Mitchell

SVN and Deployment

• Deployment process• Deployment mechanism• Subversion• Other tools

3

Page 4: Deployment With Subversion - Lorna Mitchell

In The Beginning

• One Developer• Code on PC• FTP / SCP / Upload to live server• It works!

4

Page 5: Deployment With Subversion - Lorna Mitchell

Early Development Team

• More developers• Development server• Ideally one copy per developer, a testing/staging

server and a live platform

Devarea

Devarea

Devarea

Devarea

Devarea

LIVE

Staging

5

Page 6: Deployment With Subversion - Lorna Mitchell

Deployment Considerations

• Multiple platforms prompt context-aware configuration

• File permissions may need checking, for example on cache directories

• If the live site has uploaded files stored in the file system, need to preserve this content

• Compile step for initialising compiled templates or populating caches

6

Page 7: Deployment With Subversion - Lorna Mitchell

Deployment Plan

• A deployment plan is a recipe for moving code• Step-by-step instructions for setting up a new

version of code• Must always be accompanied by a rollback plan• This process should be as automated as possible

7

Page 8: Deployment With Subversion - Lorna Mitchell

Example Deployment Plan

• Avoid missing steps when putting live

Export from repositoryTar

UntarSet permissionsSwitch symlinks

Upload

8

Page 9: Deployment With Subversion - Lorna Mitchell

Symlinks

Existing live code

existing

New code version

preparing

Live-site (symlink)

New code version

ready

9

Page 10: Deployment With Subversion - Lorna Mitchell

Code Transport

• Copy development code to live• Rsync development code to live• Check out to live and update• Export to live• Patch changes from last live version only – requires

version meta-data

10

Page 11: Deployment With Subversion - Lorna Mitchell

Commit Hooks

• Subversion can run scripts on given events, called “commit hooks” Pre-commit Post-commit

• Run test suite• Coding standards conformance• Syntax check• No “forgetting” any steps

11

Page 12: Deployment With Subversion - Lorna Mitchell

Notifications

• Can use the commit hooks to trigger information• Email team

Diff Changes Test coverage/outcomes

• Ticker/big screen• Nabaztag

12

Page 13: Deployment With Subversion - Lorna Mitchell

Source Control Packages

• Subversion http://subversion.tigris.org • CVS http://www.cvshome.org• GIT http://git.or.cz• Bazaar http://bazaar-vcs.org• Visual Source Safe

13

Page 14: Deployment With Subversion - Lorna Mitchell

Source Control Clients

• Command line tools• TortoiseSVN: http://tortoise.tigris.org • IDE Plugins: for Zend Studio, Komodo, etc• WebSVN: http://websvn.tigris.org

SFM (Safe For Managers)

• Trac: http://trac.edgewall.org/

14

Page 15: Deployment With Subversion - Lorna Mitchell

Source Control Concepts

• Individuals communicate with repository• Keeping place• Collaboration tool• Historic versions

15

Page 16: Deployment With Subversion - Lorna Mitchell

Collaboration

• Two people operate on different files Changes are combined

• Two people change the same file Changes are merged if changes don't overlap

• Allows teams to easily work on different parts of the system

16

Page 17: Deployment With Subversion - Lorna Mitchell

Collaboration Example

$greeting = 'hello world';echo $greeting;

$greeting = 'hey people';echo $greeting;

$greeting = 'hello world';print $greeting;

$greeting = 'hey people';print $greeting;

17

Page 18: Deployment With Subversion - Lorna Mitchell

Conflicts

• Two people edit the same part of the same file Includes both adding a new method to the end of a class

• Subversion will notify you of the conflict and provide: Your most recent version The version from the repository Its best guess at a merge with some notation for where

the overlaps are

18

Page 19: Deployment With Subversion - Lorna Mitchell

Conflict Example

$greeting = 'hello world';echo $greeting;

$greeting = 'hey people';echo $greeting;

$greeting = 'hi universe';echo $greeting;

$greeting = 'hey people';echo $greeting;

19

Page 20: Deployment With Subversion - Lorna Mitchell

Conflict Example

<<<<<<< .mine$greeting = 'hi universe';=======$greeting = 'hey people';>>>>>>> .r366echo $greeting;

greeting.php

$greeting = 'hi universe';echo $greeting;

greeting.php.mine

$greeting = 'hey people';echo $greeting;

greeting.php.r366

$greeting = 'hello world';echo $greeting;

greeting.php.r365

• Correct greeting.php and then let Subversion know you have resolved the conflict

20

Page 21: Deployment With Subversion - Lorna Mitchell

Branching

21

Page 22: Deployment With Subversion - Lorna Mitchell

Branching Example

version 1.1

version 1.2

development branch

Development done,merge in changes

bug fix

bug fixbackport

Delete extrabranch

trunk

22

Page 23: Deployment With Subversion - Lorna Mitchell

Tagging Versions

• Source control tools allow you to label releases, called “tags”

• Subversion has one revision number for a whole repository, incrementing on every commit

• CVS has one revision number per file• In either case its nice to have “client preview” or

“release 4.11” as human readable markers

23

Page 24: Deployment With Subversion - Lorna Mitchell

Repository Structure

• Repository layout choices• Deployment point choices• Affected by process• Dependent on product type

24

Page 25: Deployment With Subversion - Lorna Mitchell

Cyclic Releases

• Periodic release cycle• Need to maintain existing version• Start developing new version• May need to fix bugs in both versions• Use branching

25

Page 26: Deployment With Subversion - Lorna Mitchell

Continuous Releases

• Changes to branch• Branch merged to trunk• Can patch changes from branch to trunk for bug

fixes• Deployment from trunk

26

Page 27: Deployment With Subversion - Lorna Mitchell

Branch Deployment

version 1.1

version 1.2

development branch

testing

deployment!

trunk

27

Page 28: Deployment With Subversion - Lorna Mitchell

Live Branch

• Changes to branch• Branch merged to trunk• Testing performed on trunk• Changes then patched to live branch• Deployment from live branch

28

Page 29: Deployment With Subversion - Lorna Mitchell

Live Branch Deployment

development branch

testing

live branch

approved changes

deployment!

trunk

29

Page 30: Deployment With Subversion - Lorna Mitchell

Database Versioning

• Copying exported versions around Risk losing live data

• Make structure changes to all platforms Put objects in scripts

• Simple patching strategy No direct database operations Numbered patch files in subversion Include patches in script Give database awareness of current patch level Keep an installation script updated with all changes

30

Page 31: Deployment With Subversion - Lorna Mitchell

Database Rollback

• Write patch file• Also write undo file

-- release.2.0.sql

create table friends(

user_id int not null

friend_user_id int not null

created_date timestamp default current_timestamp not null

);

-- release.2.0.undo.sql

drop table friends;

31

Page 32: Deployment With Subversion - Lorna Mitchell

DbMorph

• Tool developed by Maggie Nelson• DbMorph, very early version http://sourceforge.net/

projects/dbmorph • Also see Maggie's homepage

http://objectivelyoriented.com • Slides from her talk at php|tek “Keeping Your

Database and PHP in Sync”

32

Page 33: Deployment With Subversion - Lorna Mitchell

Other Tools

• Phing http://phing.info Project build system based on Apache Ant XML configuration Integration with SVN Available through PEAR

• Phar http://pecl.php.net/package/phar Package management for PHP Like JAR for Java Self-extracting option PECL module

33

Page 34: Deployment With Subversion - Lorna Mitchell

SVN and Deployment

• Deployment process• Deployment mechanism• Subversion• Other tools

34

Page 35: Deployment With Subversion - Lorna Mitchell

Ibuildings

Questions?

Lorna Mitchell - [email protected]