Think

Read the inside scoop about working on the web and running a tech company.



8
Comments

SVN: Magento Best Practice


Who: Anyone who works with Magento (especially clients who are running a store) and could benefit from a more in-depth understanding of Magento best practices.
What: SVN and Magento (a sweet relationship)
Why: Because whether you are a client or a developer, your life can be made easier by using SVN and reaping its benefits

Quick Summary:

  1. High-level explanation of SVN
  2. Who should use SVN
  3. Why it should be used
  4. Specific things to watch out for with Magento
  5. Bonus: optional tools

SVN-Environment Relationships

1. A high-level explanation SVN

SVN” (aka “Subversion”) changes and improves the development process. It is an “enhancement” to “CVS” which allows developers to maintain local, staging, and production environments. This is a best proactive for most software development (and Magento) projects. SVN relates to “Git” (though some prefer one more than the other) and is free to use.

Simply put, SVN is a tool that keeps a revision history of code over a period of time. You keep project code located within the repository and pull a copy of the entire code with one simple command (a total of about 6 seconds). In addition, any updates to the code are committed to the repository, which allows anyone who is “linked” to the repository to sync their code with the latest changes via one click of a button. A simultaneous, multi-user environment is thus organized for development and proper administration.

Just to reiterate – there are an incredible number of benefits to SVN… too many to mention here.

2. Who should use SVN

Everyone who works with Magento should use SVN. As a rule of thumb, SVN should be used in any significant software development project (unless you use Git).

3. Why SVN should be used

SVN allows multiple developers to build simultaneously in an organized fashion with a detailed history of the progress. This ensures that the live storefront (production environment) is always intricately cared for (read open for business). Every developer has experienced early on in their career the inevitable mistake of removing a file via FTP, only left to realize that file is lost in space and no longer retrievable. But large cocktails are no longer necessary to cope with such an event thanks to SVN. The developer’s life becomes easier; and the client’s business is safer. When used properly, SVN ensures reliability, integrity, speed, and fall-back recovery.

4. Specific things to watch out for with Magento

In our experience, there are a few specifics to watch out for when using SVN with Magento. Without getting too technical, here are a few things we’ve learned along the way:

+ You need to watch out for the caching within Magento. Utilizing SVN:Ignore is the key to allowing the local environment to cache correctly. I would recommend setting SVN to “ignore” for the following (at least) when maintaining separate environments:

  • app/etc/local.xml (or use SVN lock instead for this)
  • media/catalog/product/cache
  • var/

+ If you use Beanstalk then you can streamline SVN managing with the “Deployment” tool within BeanstalkApp’s repository storage.

+ Use a test script. We’ve learned the hard way to stick to a quality test script as we merge different branches into the main SVN repository (used for production). Maintain a staging environment and use the test script from every angle prior to going “live” to production with the new changes.

+ For phases of a project, it helps to create a “branch” for each phase and a staging environment for each branch (assuming the project is large enough to call for it). This makes it easier to rollback and merge updates.

+ We prefer to keep the entire Magento directory maintained via a SVN repo. We do this so that we can upgrade, modify, and perform other changes locally prior to streamlining the changes to the staging and production environments.

5. Bonus: optional tools

At Elias, we fancy apps that make our lives easier. We invest a lot of time researching and trying out new apps to see how well they fit our business. So far we have found a few SVN tools that are worth mentioning. (Note: these may be Apple-specific. Forgive us):

  • VersionsApp: A high-quality desktop application that allows one to manage repositories locally for streamlined management of code.
  • BeanstalkApp: A sweet as online SVN storage service to host repositories full of code, revisions, and a great interface for management.
  • Coda App: A quality code editor that integrates with SVN
  • TextMate: Another quality code editor with SVN integration
  • MAMP: A personal Mac server with Apache, Mysql and PHP
  • VirtualHostX: A virtual hosting utility that works well with MAMP
  • VirtualBox: A sweet virtualization product to run multiple operating systems
  • Spoon.net: A browser-compatibility testing tool we’re just becoming familiar with

Those of you who are already familiar with SVN know that there is obviously much more to rave about. This post is intended to be a simplified “business use-case” for SVN and explanation of why it is a Magento best practice. We welcome you to chime in with other suggestions for us all to benefit from!







  • http://balexandre.com Bruno Alexandre

    Hi love SVN, and I use Beanstalk together with yet another fantastic Mac SVN Client called Cornerstone (in my opinion better than Versions) but…

    there is always a but :)

    in my Magento theme I’m just using Dropbox… I can always replace edited files with old versions as well… it’s kinda, have a SVN without needed to commit/update all the time :D

  • http://bradysewall.com Brady

    Great overview on Magento & SVN!

    I’ve been looking for a “proper” way to setup Magento on a local development computer (via MAMP) with the ability to push changes to a cloud-based staging site, as well as the live production site.

    Currently I have Magento running fine on a local MAMP setup and when I want to make changes live, I upload via FTP. Of course this doesn’t seem like the ideal setup.

    I would be very interested in finding out more specifics on how to set this up with Magento.

    Also, I’m using Coda for my webdev app, which has native SVN support. I’ve read it’s better to use an IDE for Magento development, such as NetBeans, Eclipse PDT or ZendStudio. What is your view on the best app for Magento development?

    Thank you!

  • http://www.bami.ch bami.ch

    It’s good to bring up this topic – I guess there are still a lot of developers that do Magento projects the “editor and ftp”-way.

    So far, we (the company I work for) made good experiences with ZendStudio and different SVN branches: every developer has his own codebase, eighter on a shared development server or his workstation – they all commit against trunk if a specific task or bugfix has been done. The trunk is merged periodically to a test- and qa-branch which is checked out to a test-server for testing.
    There’s also the live-branch: change requests and bugfixes are combined to releases, merged to the live-branch (or tags) which gets (after testing of course) checked out to the live system.

    personally, I think there’s no way to develop in a team without such workflows – so again, thanks for this post.

  • Lee Taylor

    Hey all, thanks for adding into this post. It’s beneficial to hear how others are operating in the midst of advancing technologies such as Magento, SVN, and other web dev-related tools.

    Regarding workflow, we actually teeter between using TextMate and Coda for our development environments. They both allow SVN integration, and are lightweight enough (yet complete enough) for us to continue developing in. By personal preference, I choose these apps over NetBeans or Eclipse PDT the majority of the time, mainly because we enjoy the versatility these apps provide. I do know Zend Studio provides some incredible helpful “structure” to development in regards to extending the Zend Framework: http://www.zend.com/en/products/studio/comparison

    @bami.ch does a great job in explaining a little more about the SVN approach to utilizing branches, merging, and production use for the repository trunk. Nice work @bami.ch!

    Cheers,
    Lee

  • http://moox.fr/ Mr.MoOx

    Thanks for this article.
    I want to know something about database. When I install a module on my local copy, if I commit and update on my staging and live, can i have any problem with the database ?
    I ask this because the original person who develop the site for my boss tell him that module can break magento database if you install them like this.

  • Lee Taylor

    Hey @Mr.MoOx,

    When we integrate with SVN, we always integrate new modules locally to test and implement, and then commit to SVN where our auto-deployment feature updates the server checkout automatically. So I believe you’re using it the right way.

    Depending on the module installation, normally the database errors can be fixed by refreshing the cache for Magento – or disabling it while doing development.

    Cheers!

  • http://www.webguys.de Tobias Vogt

    Nice posting. We ignore nearly the same files.. But why you don’t ignore the cache stuff of magento-connect?

  • Moe Sweet

    What about “Media” directory? Shouldn’t we ignore it? Coz product photos on dev and live sites cant be the same.
    Can anyone provide a complete list of ignores for magento 1.5?
    Thanks alot.