modxpo - continuous integration and deployment

53
Continuous Integration & Deployment Chris Cherrett @chrischerrett [email protected] Bournemouth, UK

Upload: chris-cherrett

Post on 08-May-2015

1.547 views

Category:

Technology


10 download

DESCRIPTION

Just over a year ago we (Adido) decided to adopt MODX as our primary CMS in favour of our in-house platform Dub3 - one that we'd been using for almost 10 years. As a full-service Digital Agency servicing over 300 clients both in the UK and Europe we faced a number of challenges, whilst also giving ourselves the opportunity to revisit our methods of Continuous Integration & Deployment. We've learned a number of lessons along the way working with MODX, from continuously building new features within teams of multiple developers to deploying to scalable server farms. Jenkins, RunDeck and Rackspace; if you're a fan of these then you'll have an insight into what we'll be exploring in this session, and what our guys at Adido are up to.

TRANSCRIPT

Page 1: MODXpo - Continuous Integration and Deployment

Continuous Integration& Deployment

Chris Cherrett@chrischerrett

[email protected]

Bournemouth, UK

Page 2: MODXpo - Continuous Integration and Deployment

TomProject Manager

LauraDesigner

ChrisDeveloper

MarkPHP

Developer

ThomFrontend

Developer

30+ employees

Marketing, Web Build & Support

Bournemouth, UK

Creative Studio

Page 3: MODXpo - Continuous Integration and Deployment

1 x Project Manager1 x Designer3 x Developers

1 x Support Manager2 x Developers

Creative Studio

Support

Page 4: MODXpo - Continuous Integration and Deployment
Page 5: MODXpo - Continuous Integration and Deployment
Page 6: MODXpo - Continuous Integration and Deployment

ConfessionWe used to be a .NET agency

(and we built a CMS)

Page 7: MODXpo - Continuous Integration and Deployment

• Our primary platform for almost 10 years

• 300+ websites

Time to move on…

• Built in-house

Page 8: MODXpo - Continuous Integration and Deployment

• Community• Customisation• Easier for

clients

Page 9: MODXpo - Continuous Integration and Deployment

How we build websites

How we deploy websites

Opportunities to review

Page 10: MODXpo - Continuous Integration and Deployment

The .NET days

• SVN for version control (hosted internally)

• Local IIS or Visual Studio Server

• rsync to single ‘demo’ or ‘live’ site

Page 11: MODXpo - Continuous Integration and Deployment

rsync• .bat files initiate

sync• Diff local repo with remote before sync

• If local version out of date, stop and update• Checkout, merge (cross

fingers)• Possible to sync and never commit• Review sync.log on server to identify

offender• Edit .bat to change destination or source DB

Page 12: MODXpo - Continuous Integration and Deployment

Remote Desktop

• Direct access to files on server

• Quick fixes

• Sync would overwrite edits• Short term fix, long term

headaches

• The devil on your shoulder

• All developers had access

Page 13: MODXpo - Continuous Integration and Deployment

Dedicated Servers

• Expensive

• Not immediately scalable

Page 14: MODXpo - Continuous Integration and Deployment

This worked fine for a long time

Required an inherent knowledgeof our infrastructure

Room for human error

Not great for growth

Page 15: MODXpo - Continuous Integration and Deployment

Mark

New ideas!

@markwillis82

Page 16: MODXpo - Continuous Integration and Deployment

“create and configure lightweight, reproducibleand portable development environments”

Wrapper around VirtualBox, Chef, & Puppet(now also works with VMware)

Page 17: MODXpo - Continuous Integration and Deployment

Every developer works with exactly the sameenvironment, irrespective of their chosen OS

Centrally configured with Puppet

Files sync with host

Page 18: MODXpo - Continuous Integration and Deployment

> vagrant up

Page 19: MODXpo - Continuous Integration and Deployment

> vagrant up

Page 20: MODXpo - Continuous Integration and Deployment

/dev/Vagrantfile

Page 21: MODXpo - Continuous Integration and Deployment

> vagrant up

localhost:2000

localhost:2002

localhost:2004

> cd dev

CI Server

• Puppet

Page 22: MODXpo - Continuous Integration and Deployment

> vagrant up

localhost:2000

localhost:2002

localhost:2004

> cd dev

CI Server

• Puppet

Live Servers

Page 23: MODXpo - Continuous Integration and Deployment

Alternative MethodDNS wildcards

Page 24: MODXpo - Continuous Integration and Deployment

http://******.chris

nginx config

project1.chris

http://

project2.chris project3.chris project4.chris project5.chris

CI Server

• Puppet

Page 25: MODXpo - Continuous Integration and Deployment

Ok...What’s next ?...

Page 26: MODXpo - Continuous Integration and Deployment

Version ControlKeep your work safe

Page 27: MODXpo - Continuous Integration and Deployment
Page 28: MODXpo - Continuous Integration and Deployment

• (Potentially) more reliable than GitHub

• Free Private Repos

Page 29: MODXpo - Continuous Integration and Deployment

Local Environment

• git

• Vagrant (VirtualBox)

• IDE independent

Page 30: MODXpo - Continuous Integration and Deployment

Let’s use those……to go one step further

Page 31: MODXpo - Continuous Integration and Deployment

Continuous Integration

• Prevent integration problems

• Automated testing• Run periodically or after every

commit• …report results – email, HipChat

• Merging can be a scary thing

Page 32: MODXpo - Continuous Integration and Deployment

Continuous Integration

• Branch every feature• Write tests for that feature

• Commit and Push• CI server is waiting for

you…

Jenkins

Page 33: MODXpo - Continuous Integration and Deployment
Page 34: MODXpo - Continuous Integration and Deployment

Jenkins

• ‘Detects’ new commit

(actually, BitBucket tells him)

• runJobs() or createNewJobs()

https://bitbucket.org/adido/jenkins-bitbucket-connector/

• A set of jobs for Master, and every branch

• Parent jobs• Child jobs

Page 35: MODXpo - Continuous Integration and Deployment

Tests

• phplint

• unit tests

• behat

Page 36: MODXpo - Continuous Integration and Deployment

Behat

“Behat is a tool that makes behavior driven development (BDD) possible. With BDD, you write human-readable stories that describe the behavior of your application. These stories can then be auto-tested against your application. And yes,

it’s as cool as it sounds!”

Page 37: MODXpo - Continuous Integration and Deployment

Feature: Your first feature In order to start using Behat As a manager or developer I need to try

Scenario: Successfully describing scenario Given there is something When I do something Then I should see something

Behat

Page 38: MODXpo - Continuous Integration and Deployment

Behat

Feature: A MODX website with multiple contexts

Scenario: Successfully loading the correct context When am on "/" Then I should see "Venues & Centres" And I change to "littledown" context Then I should see "Membership" And I should see ”Swimming" Then I change to "web" context And I should see ”About Us"

Page 39: MODXpo - Continuous Integration and Deployment

Behat /** * @When /^I change to "([^"]*)" context$/ */ public function iChangeToContext($newContext) { $currentUrl = $this->getSession()->getCurrentUrl();

// store the current url as the correct context if($newContext !== "web") { $this->defaultContext = $currentUrl; $newUrl = str_replace("http://", "http://$newContext.", $currentUrl); } else { $newUrl = $this->defaultContext; // switch back to the original url }

$this->getSession()->visit($newUrl); }

Page 40: MODXpo - Continuous Integration and Deployment
Page 41: MODXpo - Continuous Integration and Deployment

Jenkins

• Not just for testing, but also…

• Serving multiple demo sites

Page 42: MODXpo - Continuous Integration and Deployment

Jenkins

• Browse every branch on the CI server• http://feature-1.project.ci-server.com

• http://feature-2.project.ci-server.com

• Requires wildcard DNS administration

Page 43: MODXpo - Continuous Integration and Deployment

What about databases?What can we do there?

Page 44: MODXpo - Continuous Integration and Deployment

Database

/core/config/config.inc.php

$database_type = 'mysql';$database_server = 'db.server';$database_user = ’db_user';$database_password = ’xxxx-xxxx-xxxx';$database_connection_charset = 'utf8';$dbase = ’modx_database_name';$table_prefix = 'modx_';$database_dsn ='mysql:host=db.server;dbname=modx_database_name;charset=utf8';

Page 45: MODXpo - Continuous Integration and Deployment

Database

• Sync database differences• Compare schema

• Compare data

• MySQL Workbench, among others

• Case-by-case basis

Page 46: MODXpo - Continuous Integration and Deployment

Merge & DeployLet’s push this feature live!

Page 47: MODXpo - Continuous Integration and Deployment

• Use BitBucket to create pull requests • Feature is reviewed• Branch is merged with master, and

closed

• Master tests run• On success, site is deployed using

Jenkins• RunDeck• Abstracts out deployment

Page 48: MODXpo - Continuous Integration and Deployment
Page 49: MODXpo - Continuous Integration and Deployment

This sounds like a lot of work…Can we automate this some more?

Page 50: MODXpo - Continuous Integration and Deployment

So, to FinishLet’s go back to the start…

Page 51: MODXpo - Continuous Integration and Deployment

New Projects

Node.js app: “toolbelt”

Page 52: MODXpo - Continuous Integration and Deployment

New Projects

• Clone base MODX repo to local machine

• Remove remote origin from local repo• Add new BitBucket origin to local repo

• Create new BitBucket repo (API)

• Create hook (API)• Push repo

• Jenkins creates Jobs

Page 53: MODXpo - Continuous Integration and Deployment

Thank you#MODXpo