Upgrade to Pro — share decks privately, control downloads, hide ads and more …

MageTitans 2014: Separation of Code and State

MageTitans 2014: Separation of Code and State

Experimental mode of Magento development where configuration and sample data is stored in YAML files, allowing a "destroy and rebuild" approach to development which aids automated testing, mid-build demonstrations and cross-environment configuration management.

Rick Steckles

November 01, 2014
Tweet

Other Decks in Programming

Transcript

  1. SEPARATION OF CODE AND STATE VERSION CONTROL YOUR MAGENTO CONFIGURATION

    Rick Steckles Technical Director at CTI Digital @rick_steckles
  2. WHAT IS STATE? Configuration and data Some configuration is in

    local.xml ...everything else is in the database! < c o n n e c t i o n > < h o s t > < ! - - [ C D A T A [ l o c a l h o s t ] ] - - > < / h o s t > < u s e r n a m e > < ! - - [ C D A T A [ r o b ] ] - - > < / u s e r n a m e > < p a s s w o r d > < ! - - [ C D A T A [ i l o v e m a g e n t o ] ] - - > < / p a s s w o r d > < d b n a m e > < ! - - [ C D A T A [ e c o m m e r c e ] ] - - > < / d b n a m e > < i n i t s t a t e m e n t s > < ! - - [ C D A T A [ S E T N A M E S u t f 8 ] ] - - > < / i n i t s t a t e m e n t s > < m o d e l > < ! - - [ C D A T A [ m y s q l 4 ] ] - - > < / m o d e l > < t y p e > < ! - - [ C D A T A [ p d o _ m y s q l ] ] - - > < / t y p e > < a c t i v e > 1 < / a c t i v e > < / c o n n e c t i o n >
  3. WHAT'S IN THE DATABASE? Websites and stores Attributes and attribute

    groups c o r e _ c o n f i g _ d a t a values CMS pages and blocks Price rules Products Categories Customers Orders
  4. WHO CARES? Automated testing requires consistent state Centralised control of

    configuration Standardise configuration across environments Sample data (products, categories, CMS pages) for demonstration/testing purposes
  5. THE SOLUTION! (?) Configuration and data in files Bespoke extension

    to apply/sync configuration and data "Destroy and rebuild" approach to development phase Centralised control of configuration during life of site
  6. BACKGROUND Virtual machines (vagrant) for local development Local platform matches

    QA/stage/live environments Standard tool suite for all developers Faster onboarding / project setup Git version control QA/stage/live environments Continuous Integration
  7. MAGENTO EXTENSION (CONFIGURATOR) Parses .yaml files and sets/updates data and

    configuration Runs as a setup script (when Magento is installed) Shell script wrapper to run from command line Runs as part of the automated CI process after deployment
  8. CONFIGURATION: STORES - s t o r e s :

    - e n g l i s h : n a m e : E n g l i s h - s p a n i s h : n a m e : S p a n i s h c o r e _ c o n f i g : - p a t h : g e n e r a l / l o c a l e / c o d e v a l u e : e s _ E S . . .
  9. CONFIGURATION: WEBSITES - w e b s i t e

    s : - u k : n a m e : U K s t o r e _ v i e w s : - e n g l i s h c o r e _ c o n f i g : - p a t h : g e n e r a l / l o c a l e / t i m e z o n e v a l u e : E u r o p e / L o n d o n - p a t h : g e n e r a l / c o u n t r y / d e f a u l t v a l u e : G B - s p a i n : n a m e : S p a i n s t o r e _ v i e w s : - e n g l i s h - s p a n i s h c o r e _ c o n f i g : - p a t h : g e n e r a l / l o c a l e / t i m e z o n e v a l u e : E u r o p e / L o n d o n - p a t h : g e n e r a l / c o u n t r y / d e f a u l t v a l u e : E S . . .
  10. CONFIGURATION: WEBSITE GROUPS (INHERITANCE) - w e b s i

    t e _ g r o u p s : - r e d _ t h e m e : c o r e _ c o n f i g : - p a t h : d e s i g n / p a c k a g e / n a m e v a l u e : r e d - b l u e _ t h e m e : c o r e _ c o n f i g : - p a t h : d e s i g n / p a c k a g e / n a m e v a l u e : b l u e . . .
  11. CONFIGURATION: WEBSITE GROUPS (INHERITANCE) CTD. - w e b s

    i t e s : - u k : n a m e : U K i n h e r i t : - r e d _ t h e m e - p a y p a l s t o r e _ v i e w s : - e n g l i s h . . .
  12. CONFIGURATION: PRODUCT ATTRIBUTES - a t t r i b

    u t e _ s e t s : - n a m e : B o o k i n h e r i t : D e f a u l t g r o u p s : - n a m e : G e n e r a l a t t r i b u t e s : - n a m e : s e a r c h _ w e i g h t : 5 i s _ g l o b a l : 1 l a b e l : T i t l e - w e i g h t : i s _ g l o b a l : 1 i s _ r e q u i r e d : 0 - i s b n 1 0 : i s _ g l o b a l : 1 l a b e l : I S B N ( 1 0 - d i g i t ) t y p e : t e x t c o n f i g u r a b l e : 0 i s _ v i s i b l e _ o n _ f r o n t : 1 i s _ u s e d _ f o r _ p r i c e _ r u l e s : 1 i s _ u s e d _ f o r _ p r o m o _ r u l e s : 1 p r o d u c t _ t y p e s : - s i m p l e - c o n f i g u r a b l e . . .
  13. CONFIGURATION: c o r e _ c o n f

    i g _ d a t a Part of website structure (location determines scope) - p a t h : s y s t e m / l o g / c l e a n _ a f t e r _ d a y v a l u e : 1 4 - p a t h : s y s t e m / l o g / e n a b l e d v a l u e : 1
  14. SAMPLE DATA: PRODUCTS/CATEGORIES - c a t e g o

    r i e s : - n a m e : T e s t P r o d u c t s d e s c r i p t i o n : S a m p l e p r o d u c t s f o r d e m o s / t e s t i n g u r l _ k e y : t e s t - p r o d u c t s p r o d u c t s : - u r l _ k e y : " m y - t e s t - b o o k " s k u : " T E S T B O O K 0 0 1 " i m a g e f i l e : " b o o k - 0 1 2 3 4 5 6 7 8 9 . j p g " n a m e : " M y T e s t B o o k " a t t r i b u t e _ s e t : " B o o k " t y p e : " s i m p l e " w e b s i t e s : - u k - s p a i n p r i c e : 1 9 . 0 8 q t y : 1 0 0 a t t r i b u t e _ v a l u e s : i s b n 1 0 : " 0 1 2 3 4 5 6 7 8 9 " . . .
  15. SAMPLE DATA: SHIPPING RATES c o u n t r

    y , r e g i o n , d e s t _ c i t y , d e s t _ z i p , d e s t _ z i p _ t o , c o n d i t i o n _ f r o m _ v a l u e , c o n d i t i o n _ t o _ v a l u e , p r i c I T A , * , * , * , * , 0 , 1 0 0 0 0 0 , 4 , S t a n d a r d ( 3 - 5 D a y s ) S G P , * , * , * , * , 0 , 1 0 0 0 0 0 , 7 . 2 , S t a n d a r d ( 6 – 1 0 D a y s ) A U S , * , * , * , * , 0 , 1 0 0 0 0 0 , 1 5 , S t a n d a r d ( 7 – 1 2 D a y s ) . . .
  16. SAMPLE DATA: CMS PAGES/BLOCKS - p a g e s

    : - a b o u t - u s : - - w e b s i t e s : - u k - s p a i n - t i t l e : A b o u t O u r B o o k s h o p - v e r s i o n _ c o n t r o l : 1 - t e m p l a t e : o n e _ c o l u m n - m e t a _ k e y w o r d s : - m e t a _ d e s c r i p t i o n : - h e a d i n g : A b o u t O u r B o o k s h o p - c o n t e n t _ f i l e : a b o u t - u s . h t m l
  17. "DESTROY AND REBUILD" Fabric scripts on local development VMs 'f

    a b r e b u i l d ' destroys everything! Drop/recreate database Delete local.xml Re-install Magento (via n 9 8 - m a g e r u n ) Run setup scripts (extensions) Clear caches, etc. Run to test before pushing code to repo Run after pulling new code from repo Doesn't take long, if website/store structure is relatively simple...
  18. IN-LIFE SUPPORT: CONFIGURATION MANAGEMENT Same "destroy/rebuild" mechanism used on QA/stage/live

    servers during development When functionality is complete: "Destroy/rebuild" is turned off for Stage and Live Extension still used for persistent configuration Sample data, etc. in YAML files is ignored
  19. IN PRACTISE Can start projects with a standard configuration set

    Ties in with Magento requirements capture process Reduces/eliminates problems caused by different data in local DB/other devs DB/stage Standard base for automated testing (Behat etc.) Sample data and CMS content for client demonstrations during build Consistent way of rolling out new attributes, configuration, etc. to stage/live
  20. NEXT STEPS Clean up code, refactor, test with CE Document

    and make available on GitHub Add/refine functionality during the course of each project