Magento has been gaining a lot of momentum in Australia over the last few years, and the need for us to allow developers to collaborate on projects whether they be in Perth, Melbourne or Sydney has pushed us to address a problem many web developers face with every framework they use: workflow. My main goal was to allow multiple developers to work on their own versioned copy of a project and be able to deploy Magento to multiple sites (live, staging, dev) with one click. Here's what I came up with.
Advanced Developer Tools (ADT) for Magento
Springloops.com acount (GitHub, Beanstalk, etc would work too)
Note: To follow and understand this post, you'll need some experience or understanding of Git and Magento.
Setup repo on Springloops
Install your SSH key (copy the contents of ~/.ssh/id_rsa.pub)
Create deployment servers (live and staging, and dev if needed)
Setup GIT repo
git init git config --global user.name "My name" git config --global user.email "email@example.com" (This must be the same email as your Springloops account) touch .gitignore echo "var/*" >> .gitignore echo "media/*" >> .gitignore git add .gitignore git commit -m "Added gitignore" git status git add . git commit -m "Added existing code base" git remote add origin REMOTE_REPO_URL_STRING git push -u origin master git checkout -b staging git push -u origin staging git checkout -b dev git push -u origin dev
The first time you push to live, you'll have to install the DB manually (use a sql dump of your staging site and change base_urls). From then on, DO NEVER MAKE CHANGES TO YOUR LIVE DB manually! Make all your DB changes in Magento install & upgrade scripts! (See further along) This means that all your DB changes will automatically deployed! To allow to have multiple DB environments and still have app/etc/local.xml under source control, you'll need Magento ADT. Then configure your local.xml accordingly (see below)
Multiple database environments
Thanks to our Magento ADT extension (July 2011 release), you can have different DB connections in your local.xml and have them kick-in depending on the hostname you're using. That allows to have the details for live, staging, dev and multiple local devs in one file and under source control. That also means that you can deploy and be sure that the correct DB will be used.
... 1mystagingurl.commysql4SET NAMES utf8pdo_mysql1mydevurl.commysql4SET NAMES utf8pdo_mysql1 ...
So, "default_setup" are your live/default details. Then, add an "extras_setup" section. In there, you can add as many sections as you want (and name them what you want, eg "staging_setup"). You must add a "domain" tag to each to tell when to kick-in.
Magento install & upgrade scripts
To never have to remeber what changes you made through the back-end during development, simply NEVER DO IT! Use install/upgrade scripts instead.
Mage::getModel('core/config_data') ->load(57) ->setValue('blank') ->save();
Mage::getModel('core/config_data') ->setScope('stores') ->setScopeId(1) ->setPath('design/theme/default') ->setValue('shopfortots') ->save(); Design updates (delete)
$design = Mage::getModel('core/design'); $design->load(1); $design->delete(); CMS Page:
Mage::getModel('cms/page') ->load('home') ->setContent($content) ->setStores(array(1)) ->save(); CMS Block:
Mage::getModel('cms/block') ->load('footer_links') ->setContent($content) ->setStores(array(1)) ->save();
Just leave us a comment, and don't forget to follow us on GitHub: https://github.com/DoghouseMedia