One of the best uses of virtualization technology is for creating development environments. Virtual private servers (VPS) are ideal if you need a sandbox to create a new application stack, develop a new web app, or test out the app under a variety of Q/A scenarios.

How can we offer dev environments with low provisioning cost? This is one way:

  • Set up OpenVZ on a RHEL5 server.
  • Set up a web template (Apache, PHP5).
  • Set up a MySQL template
  • For each dev environment, deploy a web and MySQL container.

This 4 step process glosses over many important challenges. For instance:

  • How do you access these machines over the network?
  • How to get the latest code into each deployed web container?
  • How to get the latest MySQL schema & associated dev data into the MySQL container?
  • How to get code and schema changes out of the container and into another environment (e.g.: deploying to production)?
  • How to upgrade/restart the VPS without having to coordinate with each developer?

I’m thinking we can overcome these challenges with some crafty configuration & scripts.

Network access

NAT all VPS servers for more fluid provisioning, less DNS updates. Web nodes occupy one network subnet, DB nodes occupy another. Use a database to track all VPS and build a simple webapp on top that provides bookmarks to each VPS along with CRUD ops.

Getting code into the VPS

Using our git repo, check out a working copy with the latest dev branch. Alternatively, NFS mount staff home directories in each VPS and work off that. I’d prefer the NFS approach, as it makes the VPS more transient: we can destroy and re-create the server using an upgraded template if desired without loosing code.

Getting DB schema into the VPS

Database migrations, similar to Rails (we use PHP for most apps). Moodle CMS also has a form of database migrations which happen via the web, which is a tad simpler. Doctrine ORM supports database migrations, although we use it only for new development and it won’t help our existing code. For older/legacy webapps, we’ll have to maintain a per-tool schema file to bootstrap our webapps.

Getting code and schema updates out of the VPS

Pull code changes using git into a central repo. Put all database migrations in the code, using Doctrine as described above, or schema bootstrap file.

Painless VPS reboots

If all database changes exist in code, and all code exists on the shared NFS server, then destroying & deploying a new VPS from an updated template should not impact a developer. Test data may disappear, which may cause concern.  Ideally, all important data would be saved in-code and easily imported into MySQL, through migrations or bootstrap SQL files.  Alternatively, we could place the MySQL data files on an iSCSI lun, at an additional provisioning cost.

Once we are able to quickly provision new dev environments, why not do the same for production apps? I think we could use the same code bootstrap & database migration code to deploy new application stacks on demand.

,