environments and version control in ee - the why and how

84
ERIKREAGAN•EECI ENVIRONMENTS & VERSION CONTROL The Why & How

Upload: erik-reagan

Post on 17-May-2015

2.963 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

ENVIRONMENTS & VERSION CONTROL

The Why & How

Page 2: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

WHO IS THIS GUY?

2

EE Reactor team member

Page 3: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

WHO IS THIS GUY?

3

Partner & Lead Developer

Page 4: Environments and Version Control in EE - The Why and How

Survey Submissions

@ERIKREAGAN • EECI 2011

784

Page 5: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 20115

35

24

19

6-10 years

3-5 years

Over 10 years

SURVEY SUBMISSIONSWeb Development Experience

Page 6: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 20116

40191243

3-4 years

SURVEY SUBMISSIONSExpressionEngine Experience

0-2 years

5-7 years

pMachine

None

Page 7: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 20117

666438212019

HTML/CSS/JS markup

SURVEY SUBMISSIONSWeekly Responsibilities

EE site planning

PHP/MySQL development

Add-on development

Content management

Team leader

Page 8: Environments and Version Control in EE - The Why and How

Caught my Monty Python reference

@ERIKREAGAN • EECI 2011

73%8

Page 9: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

VERSION CONTROL

9

Page 10: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

SYNONYMS • Version Control

• Revision Control

• Source Control

10

Page 11: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

COMMON SYSTEMS• Git

• Subversion

• Mercurial

11

Page 12: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

SURVEY STATS

12

Page 13: Environments and Version Control in EE - The Why and How

Devs not currently using a VCS regularly

@ERIKREAGAN • EECI 2011

34%13

Page 14: Environments and Version Control in EE - The Why and How

Devs only using a desktop GUI for VCS

@ERIKREAGAN • EECI 2011

21%14

Page 15: Environments and Version Control in EE - The Why and How

Devs only using command line for VCS

@ERIKREAGAN • EECI 2011

21%15

Page 16: Environments and Version Control in EE - The Why and How

Devs using both CLI and a GUI for VCS

@ERIKREAGAN • EECI 2011

24%16

Page 17: Environments and Version Control in EE - The Why and How

Have used CVS

@ERIKREAGAN • EECI 2011

6%17

Page 18: Environments and Version Control in EE - The Why and How

Have used Mercurial

@ERIKREAGAN • EECI 2011

13%18

Page 19: Environments and Version Control in EE - The Why and How

Have used Subversion

@ERIKREAGAN • EECI 2011

54%19

Page 20: Environments and Version Control in EE - The Why and How

Have used Git

@ERIKREAGAN • EECI 2011

77%20

Page 21: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 201121

WE USE GIT

Linux jQuery Rails Android

Page 22: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 201121

WE USE GITAnd so do the cool kids

Linux jQuery Rails Android

Page 23: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 201121

WE USE GITAnd so do the cool kids

Linux jQuery Rails Android

Page 24: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

OLD WAY

1. Duplicate index.html

2. Test changes

3. (Maybe save a backup of the previous version)

4. Save over old version losing previous state

22

Single Developer

Page 25: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

NEW WAY

1. Change and save the file contents

(Retain history of file for future use)

23

Single Developer

Page 26: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

OLD WAY

1. Bob changes part of index.html

2. Suzie changes a different part of index.html

3. Bob and Suzie carefully merge changes together

4. Overwrite old version of index.html

24

Development Team

Page 27: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

NEW WAY

1. Change and save the file contents

(Retain history of file for future use)

25

Development Team

Page 28: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 201126

Page 29: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 201126

Page 30: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 201126

Page 31: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

KEY CONCEPTS• Track certain files

• Ignore certain files

• Commits (History)

• Branches

• Remote branches

27

Page 32: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

“WHAT DO I TRACK?”VS

“WHAT DO I IGNORE?”

28

Page 33: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

IGNORED FILES• Operating System files

• Caches

• .htaccess (possibly)

• Custom uploads from EE

• Dynamic images (captchas etc)

29

Page 34: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

# Lame OS files Thumbs.db.DS_Store

# EE System cache/system/expressionengine/cache/*

# Local dev database file/config/config.local.php

# Custom Upload Directories/public_html/uploads/*

# Captchas/public_html/images/captchas

# Asset minification/public_html/min

30

.gitignore

Page 35: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 201131

TRACKED FILES• EE System directory

• Add-ons

• Template flat files

• Images, CSS, Javascript & other assets

Page 36: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

COMMITSCreate your history

32

Page 37: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

COMMIT TIPS• Commit o"en (common Git practice)

• Write detailed commit messages

• Review commit log when returning to a project a"er a break of any sort

• Review commits of development team members

33

Page 38: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

BAD COMMIT MESSAGEUpdated config file.

34

Page 39: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

GOOD COMMIT MESSAGEUpdated config file with new Minimee cache path directory

This allows our cache path to be dynamicly absolute based on the environment out code is in.

$config[‘minimee_cache_path’] = $base_path . ‘/min’;

35

Page 40: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

BRANCHINGKeeping things organized

36

Page 41: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

BRANCHING WORKFLOW

Do what works best for you

37

Just make sure you do it for a reason

Page 42: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

REMOTE BRANCHES• Destination for your repository / branch

• “Origin” of your repository / branch

• Server environment for your site

• Other team member’s repository / branch

38

Page 43: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

TOPICAL BRANCHING• master

• dev

• feature/x

• upgrade/y

• bugfix/z

39

Page 44: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 201140

“It's like not wearing a seatbelt in your car because you haven't had an accident yet.

Don't be silly, version your work.”

Iain Urquhart / @iain

Page 45: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

GIT RESOURCES• Book: Pragmatic Version Control Using Git

• peepcode.com/products/git

• whygitisbetterthanx.com

• github.com

• More available with the presentation download

41

Page 46: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

ENVIRONMENTS

42

Page 47: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

AN ENVIRONMENT ISany server running an instance of your site

43

Page 48: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

COMMON ENVIRONMENTS• Production - the public-facing “live” site

• Staging - typically used for a final test

• Development - shared team development

• Local - each developer’s local instance

44

Page 49: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

SURVEY STATS

45

Page 50: Environments and Version Control in EE - The Why and How

Devs currently using a Production Environment

@ERIKREAGAN • EECI 2011

100%46

Page 51: Environments and Version Control in EE - The Why and How

Devs currently using a Staging Environment

@ERIKREAGAN • EECI 2011

59%47

Page 52: Environments and Version Control in EE - The Why and How

Devs currently using a Shared Dev Environment

@ERIKREAGAN • EECI 2011

32%48

Page 53: Environments and Version Control in EE - The Why and How

Devs currently using a Local Dev Environment

@ERIKREAGAN • EECI 2011

77%49

Page 54: Environments and Version Control in EE - The Why and How

Devs who keep using environments post-launch

@ERIKREAGAN • EECI 2011

29%50

Page 55: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 201151

WHY DO YOU USE ENVIRONMENTS?

Page 56: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 201152

“Local development is incredibly fast and you don't have to worry about setting up crazy conditionals and memeber preferences to hide what you are working on on the live site.”

Page 57: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 201153

“Multiple environments allow us to build locally without affecting others and preview new features to clients - without losing the ability to quickly apply updates to the current live site.”

Page 58: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 201154

“Automated deployments and multiple environments are essential to any agile-oriented developer. They save time, reduce errors and streamline site maintenance.”

Page 59: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 201155

GETTING SET UPWhat is potentially unique to each environment?

Page 60: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

GETTING SET UP

• Server paths

• URL root

• EE upload paths

• Debug mode intentions

• URI support (PATH_INFO)

• Cache settings

56

What’s Unique?

Page 61: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

ROBUST CONFIG FILESaves time and adds flexibility

57

Page 62: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

GETTING SET UP

✓ Server paths

✓ URL root

- EE upload paths

✓ Debug mode intentions

✓ URI support (PATH_INFO)

✓Cache settings

58

What can be changed?

Page 63: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

GETTING SET UP

/config/

config.env.php

config.master.php

config.{ENV}.php

/public_html/

/system/

/tpl/

59

Directory and file structure

Page 64: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

GETTING SET UP

if ( ! defined('ENV')){ switch ($_SERVER['HTTP_HOST']) { case 'focuslabllc.com' : define('ENV', 'prod'); define('ENV_FULL', 'Production'); define('ENV_DEBUG', FALSE); break; case 'ohsnap.focuslabllc.com' : define('ENV', 'stage'); define('ENV_FULL', 'Staging'); define('ENV_DEBUG', FALSE); break; default : define('ENV', 'local'); define('ENV_FULL', 'Local'); define('ENV_DEBUG', TRUE); break; }}

60

config.env.php sample

Page 65: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

GETTING SET UP

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/** * Development config overrides & db credentials * * Our database credentials and any environment-specific overrides * * @package Focus Lab Master Config * @version 1.1 * @author Erik Reagan <[email protected]> */

$env_db['hostname'] = 'localhost';$env_db['username'] = '';$env_db['password'] = '';$env_db['database'] = '';

$config['webmaster_email'] = '[email protected]';

/* End of file config.dev.php *//* Location: ./config/config.dev.php */

61

config.dev.php sample

Page 66: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

GETTING SET UP

/** * Template settings * * Working locally we want to reference our template files. * In staging and production we do not use flat files

* (for ever-so-slightly better performance) * This approach requires that we synchronize templates after * each deployment of template changes */$env_config['save_tmpl_files'] = (ENV == 'prod') ? 'n' : 'y';$env_config['tmpl_file_basepath'] = $base_path . '/../tpl/';$env_config['hidden_template_indicator'] = '_';

62

config.master.php sample

Page 67: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

GETTING SET UP

/** * Debugging settings * * These settings are helpful to have in one place * for debugging purposes */$env_config['is_system_on'] = 'y';$env_config['allow_extensions'] = 'y';$env_config['email_debug'] = (ENV_DEBUG) ? 'y' : 'n' ;// Show template debugging if we're not in production$env_config['template_debugging'] = (ENV_DEBUG) ? 'y' : 'n' ;/** * Set debug to '2' if we're in dev mode, otherwise just '1' * * 0: no PHP/SQL errors shown * 1: Errors shown to Super Admins * 2: Errors shown to everyone */$env_config['debug'] = (ENV_DEBUG) ? '2' : '1' ;

63

config.master.php sample

Page 68: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

GETTING SET UP

/** * 3rd Party Add-on config items as needed */$env_config['minimee_cache_path'] = $base_path . '/min';$env_config['minimee_cache_url'] = $base_url . '/min';$env_config['minimee_remote_mode'] = 'auto';$env_config['minimee_debug'] = 'n';// Disable minimee in dev but not in staging and production$env_config['minimee_disable'] = (ENV == 'local') ? 'y' : 'n' ;

// Greeny (auto-updating of upload directory paths)$env_config['greeny_enabled'] = (ENV == 'prod') ? 'false' :

64

config.master.php sample

Page 69: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

FOCUS LABCONFIG SETUPgithub.com/focuslabllc/ee-master-config

65

Page 70: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

MULTI-ENVIRONMENT CHALLENGES

You didn’t think it was that easy, did you?

66

Page 71: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

BACK TO THE SURVEY

67

Page 72: Environments and Version Control in EE - The Why and How

100%@ERIKREAGAN • EECI 201168

Page 73: Environments and Version Control in EE - The Why and How

100%@ERIKREAGAN • EECI 201168

Keeping database changes synced across environments

Page 74: Environments and Version Control in EE - The Why and How

72%@ERIKREAGAN • EECI 201169

Page 75: Environments and Version Control in EE - The Why and How

72%@ERIKREAGAN • EECI 201169

Maintaining custom upload directory paths

Page 76: Environments and Version Control in EE - The Why and How

Devs who say the headaches are worth the trouble

100%@ERIKREAGAN • EECI 201170

Page 77: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 201171

DATABASE ISSUES• New custom fields alter the DB schema

• Installing or updating add-ons can alter the DB schema

• Updating EE can alter the DB schema

Page 78: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

DATABASE ISSUES

• Custom upload directory paths are stored in the DB and cannot be dynamically altered

• Relative upload directory paths work sometimes, but not with all add-ons

• “Content” is very likely changing in the Production environment while you build and test in your other environments

72

Page 79: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 201173

http://expressionengine.com/forums/viewthread/196480/

Page 80: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

QUICK TIPS• You need to understand EE’s database

• Learn about 3rd party add-on’s DB tables

• Establish a ruleset for your workflow

• Understand that there will be exceptions

74

Page 81: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 201175

Schema / Structureflows up stream

Page 82: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 201176

Content flowsdown stream

Page 83: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

FINAL NOTES• These practices make you a better developer

• They help prepare you to work with a team

• They help your team work more efficiently

• You can provide a better service to your clients

77

Page 84: Environments and Version Control in EE - The Why and How

@ERIKREAGAN • EECI 2011

!ERIKREAGANPartner, Focus Lab, LLC!FocusLabLLC

78