Establish reliable builds and deployments with Magento
description
Transcript of Establish reliable builds and deployments with Magento
Establish reliable builds and deployments Meet Magento Switzerland 2014
Marco Bamert Zurich, October 24, 2014
© Unic - Slide 3
• Marco Bamert
• Started working at www.unic.com in 2007
• Senior Application Engineer
• First Magento project 2008, Magento ever since
Me
© Unic - Slide 4
• Desire to automate builds arose during the 2nd Magento project
• First attempt with Scripts, then Maven which worked for quite some time
• Until we more and more needed to customize it
• So we decided to rebuild it from scratch with everything we learnt
History
© Unic - Slide 5
Click to edit Master title style
A standardized and automated way of putting different parts together to get a running Magento site on a server.
Pragmatic definition of a build framework
© Unic - Slide 6
Which Parts?
Build Framework
Common Modules
3rd Party Modules
Magento Core
Libraries
Only really project specific stuff Shared stuff that should no be touched
© Unic - Slide 7
• Have a standardized way of building and deploying projects and common modules
• Project setup should not take more than 20 minutes (all inclusive)
• Don’t depend on external resources for build and deployments
• Have everything in control and integrate with tools currently in use
• Have a flexible framework that works “out of the box” but is customizable - in a standardized way
• Use the same framework on every environment, except for releases
• Project should know as little as possible about the framework
• Ability to automate the whole build and deployment pipeline
Goals
© Unic - Slide 8
Tools in use
Sprint planning, issue management, release planning
Git, Code Reviews
Continuous integration server
Will replace Jenkins over the next weeks
Repository Manager
© Unic - Slide 9
Click to edit Master title style
Repository Manager ? - A repository manager stores and organizes binary software components for use in development, deployment, and provisioning. http://www.sonatype.com/nexus/why-nexus/why-use-a-repo-manager
© Unic - Slide 10
• Faster and more reliable builds
• Caching
• Eliminating Risk
• Compliance
• Lifecycle Management
• Specific Access Restrictions
Why use an artifact storage like Nexus?
© Unic - Slide 11
• PHing Is Not GNU make; it's a PHP project build system or build tool based on Apache Ant
• Written in PHP
• Easily extendable with custom Tasks
• http://www.phing.info/
Tools:
© Unic - Slide 12
• Some general dependencies
• A lot of properties
• Some 3rd party libraries (like SpycLib)
• Phing targets split into several files
• Custom Tasks
Build Framework – Architecture
© Unic - Slide 13
<project name="Database" basedir="../../"> <includepath classpath="${application.startdir}/build/tasks/Database"/> <taskdef name="createDatabase" classname="CreateDatabaseTask"/>
<target name="create-‐database” description="Create the database and user for the project” hidden="true” depends="drop-‐database">
<customHook hook="before-‐create-‐database"/>
<createDatabase databaseName="${project.database.name}" databaseUsername="${project.database.username}" databasePassword="${project.database.password}" databaseAdminUsername="${database.admin.username}" databaseAdminPassword="${database.admin.password}" databaseServer="${database.host}"/>
<createDatabaseUser ...
<grantDatabasePrivileges ...
Build Framework – Code Sample
© Unic - Slide 14
# Main Project Settings project.name=Magento Template Project
# Release Settings project.release.groupId=com.unic.magento.template project.release.artifactId=project project.release.version=1.0-‐SNAPSHOT
# Magento Version magento.core.type=enterprise magento.core.version=1.14.0.1
# Project Database Settings project.database.name=template_project project.database.username=template_project
# Parameters for installing Magento install.domain=template.local
Configuration: Project settings
© Unic - Slide 15
Configuration: Dependencies
• Similar to composer.json
• Ability to overwrite / skip dependencies from the build framework
• Require-dev node to only include some deps in DEV environments
require:
com.unic.magento.commons/cms:
version: 3.0.0
repository: unic-‐commons-‐releases
com.unic.magento.commons/datatrans:
version: 4.0.0
repository: unic-‐commons-‐releases
© Unic - Slide 16
Configuration: core_config_data
• Environment specific yaml files
• Inheritance
• PRD > ACC > DEV > USER
• Used for “Magento Configuration”
• Customer specific modules have proper configuration in config.xml
# -‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐ # CATALOG # -‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐
catalog/price/scope: default: 0: 1
catalog/frontend/list_mode: default: 0: grid
catalog/frontend/list_allow_all: default: 0: 1
© Unic - Slide 17
Build process: Tell the project how to build itself
$ phing init-‐build-‐framework ...
Project > install-‐build-‐framework: [httpget] Fetching https://nexus.unic.com/nexus/service/local/artifact/maven/redirect?r=unic-‐commons-‐releases&g=com.unic.magento&a=build-‐framework&v=LATEST&e=zip ...
BUILD FINISHED
© Unic - Slide 18
Build process: Do the work
1. Get information about the environment
2. Read properties (Inheritance!)
3. Create fresh database
4. Download and install Magento
5. Download and extract all dependencies
6. Link project source to document root
7. Install sample data
8. Ensure proper configuration
9. Start Working
$ phing install
© Unic - Slide 19
1. Project is build on Jenkins (automatically or manually)
2. Compress important stuff, ignore the rest
3. Upload the compressed Artifact to Nexus
Build process: Artifact creation – Step 1
© Unic - Slide 20
• Artifact is uploaded to the artifact storage and is ready for deployments.
Build process: Artifact creation – Step 1
© Unic - Slide 21
• Only the server itself knows the passwords and configuration
• Most of the configuration is standardized but can be configured to specific needs
• Server specific local.xml is stored on the server and injected into the deployed version
Build process: Configure the server – Step 2
© Unic - Slide 22
Build process: Configure the server – Step 2
# Repository and Artifact Settings release.groupId=com.unic.magento.template release.artifactId=project release.snapshot.repository=unic-‐commons-‐snapshots release.releases.repository=unic-‐commons-‐releases
# Deployment Settings server.environment=prd server.data.directory=/var/www/deployment-‐test-‐data deployment.name=deployment-‐test
# Database Settings (used only for backup task) database.username=build database.password=build database.name=template_project
© Unic - Slide 23
Build process: Deploy the project – Step 3
1. Connect to server
2. Issue release command
$ phing release –Dversion=1.2.0
© Unic - Slide 24
1. Download, verify and extract the requested version
2. Insert environment specific local.xml
3. Set permissions, create symlinks
4. Trigger maintenance window (and create backup)
5. Apply database schema update
6. Ensure configuration for environment
7. Change symlink to new version
8. Write log information about release
9. Unset maintenance window
10. Clean up releases
Build process: Deploy the project – Step 3
© Unic - Slide 25
Build process: Deploy the project – Step 3
/var/www/project
1.0.0 1.1.0 1.2.0 1.2.0 1.1.0
© Unic - Slide 26
© Unic - Slide 27
http://amzn.to/1nfmZpp
Get more
© Unic - Slide 28
• Phing (http://www.phing.info/)
• Nexus (http://www.sonatype.com/nexus)
• git-flow (https://github.com/nvie/gitflow)
• Atlassian Stash (https://www.atlassian.com/software/stash)
• Atlassian Jira (https://www.atlassian.com/software/jira)
• TeamCity (http://www.jetbrains.com/teamcity/)
Resources & links
© Unic - Seite 29
Hohlstrasse 536 8048 Zürich Tel +41 44 560 12 12 Fax +41 44 560 12 13 [email protected] www.unic.com
Unic AG
© Unic - Seite 30
Marco Bamert Senior Application Engineer