drupaldevdays barcelona 2012 - staging with git and drush.pdf

47
Staging with git & drush

Upload: vuthuan

Post on 08-Dec-2016

217 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

Staging with git & drush

Page 2: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

freistil IT

Markus Heurung – @muhh

[email protected]

Page 3: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

„Deploying“ the old way

index.phpupdate.phpmodules/includes/sites/…

FTP

workfix

Page 4: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

write-write conflict

multiple developers

index.phpupdate.phpmodules/includes/sites/…

index.phpupdate.phpmodules/includes/sites/…

Page 5: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

SUCKS!

Page 6: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

develop locally!

Page 7: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

XAMPP/MAMP

Acquia Dev Desktop

Linux

Mac OS X

Page 8: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

index.phpupdate.phpmodules/includes/sites/…

index.phpupdate.phpmodules/includes/sites/…

Page 9: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

Version Control

Page 10: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

Git

Page 11: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

Repository

index.phpupdate.phpmodules/includes/sites/…

put your code into git

Page 12: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

Some git basics

$ git add $FILE(S)$ git commit $FILE(S)

Page 13: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

some git basics

$ git add docroot/$ git commit docroot/

Page 14: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

the typical local git workflow

$ [work …]$ git commit -am "meaningful message"$ [work …]$ git add sites/all/modules/custom/stuff/$ git commit -am "added stuff module"

Page 15: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

Repository

index.phpupdate.phpmodules/includes/sites/…

put your code into git

Page 16: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

index.phpupdate.phpmodules/includes/sites/…

transfer commits

local integration

Page 17: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

git remote repositories

Page 18: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

working with remotes

$ git remote add integration \\ [email protected]:test.git

Page 19: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

transfer commits

$ git push integration$ git pull integration

Page 20: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

index.phpupdate.phpmodules/includes/sites/…

transfer commits

local integration

index.phpupdate.phpmodules/includes/sites/…

pull

push

Page 21: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

let the serverdeploy the code

to its docroot

Page 22: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

git knows hooks!

Page 23: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

.git/hooks/post-receive

→ go to docroot and do a git pull

Page 24: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

What about sites/*/files?

Page 25: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

not in git!

Page 26: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

$ echo "sites/*/files" >> .gitignore

let git ignore it

Page 27: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

drush

Page 28: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

some drush basics

$ drush pm-downlaod views$ drush pm-enable views $ drush pm-disable devel_themer$ drush pm-update$ drush updatedb$ drush variable_set site_offline 1

Page 29: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

and most used

$ drush cache-clear all

Page 30: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

drush knows remotes, too!

called site-aliases

Page 31: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

drush site-aliases

aliases.drushrc.php

$aliases['integration'] = array( 'uri' => 'integration.server', 'root' => '/var/www/integration.server/docroot', 'remote-host' => 'integration.server', 'remote-user' => 'integration-user');

Page 32: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

$ drush @integration status

drush site-aliases

Page 33: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

syncing files directory

Page 34: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

use drush to sync files

$ drush rsync \\ default:%files @integration:%files

Page 35: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

syncing the database

Page 36: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

in $aliases['integration']

'databases' => array( 'default' => array( 'default' => array( 'driver' => 'mysql', 'database' => 'integration', 'username' => 'integration', 'password' => 'supersecret', 'host' => 'localhost', 'prefix' => '', 'collation' => 'utf8_general_ci', ), ),),

Page 37: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

in $aliases['integration']

'path-aliases' => array( '%dump-dir' => '/home/integration-user/db-dumps',),'command-specific' => array( 'sql-sync' => array ( 'no-cache' => TRUE, 'sanitize' => TRUE, 'structure-tables' => array( 'common' => array('cache', 'cache_menu', '…', 'sessions', 'watchdog'),),

Page 38: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

sync your database

$ drush sql-sync \\ default @integration

Page 39: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

multiple developers

next problem:

Page 40: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

no problem

Page 41: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

dev A

dev B

integration

index.phpupdate.phpmodules/includes/sites/…

Git is a distributed VCS

Page 42: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

• no forgotten files

• much faster uploads

• version history

• teamwork

• deployment to docroot on the server

• put as much in code as possible

• features, strongarm, install profiles, …

• hook_update_N

summary

Page 43: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

code staging

a possible workflow

Page 44: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

boss

integration

stage

live

dev

dev

dev

dev

Page 46: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

Questions!

Page 47: DrupalDevDays Barcelona 2012 - Staging with git and drush.pdf

Thank you!