Supporting development with virtual machines and samba

About a year ago I moved our team to Linux virtual machine development stack. Before that people used to work on their native windows or mac apache stack… those were truly the dark ages. Switching from apache to nginx in production seemed like the perfect catalyst to make the change.

Centos hosts and VMware WorkStation/Fusion

We now have a base Centos Linux vmware machine configured with puppet. Spinning up a whole new machine takes about 5 minutes from the base clone. We have pretty snappy host desktop machine with a dozen or so vms all built running and ready for developers to pick up. When I was first testing out this set up I was hoping to use Proxmox which has a great web based console for management. Unfortunately our office network uses dhcp addresses which Proxmox had issues with. With that consideration VMware Workstation become the next logical choice running on a Centos host. Thankfully VMware guests were able to pick up a dhcp address without an issue. I have always liked Oracle’s VirtualBox but it seems quite sluggish compared to VMware’s products.

VMware has a great command line interface for host machine called vmrun. On the main vm host machine I have a bash script to start all of the vm’s via the vmrun command:

To show all running virtual machines:

Puppet checkout and apply

Puppet allows us to get a machine up to the latest configuration very rapidly. Our manifest set up nginx, mariadb, php and the samba shares for development.

In production we run the standard puppet master setup with registered clients. For these development machines that same setup seemed to have some hiccups. One hiccup was running a puppet update on a local machine over vpn when the host machine was at home. Sometimes in that situation the master could not be found. To keep it simple I decided to go with a simple code checkout into /etc/puppet then run puppet apply manifests/dev.pp This setup also allows us to test and work on our puppet configurations at the same time.

Samba shares for development

To claim a virtual machine a developer ssh’s in and then mounts the file system with SMB. The file performance is very good over our office gigabit network and works wonderfully on Mac Linux and Windows. The samba share uses the nginx/php user account which keeps the file permissions in check. If you are working from home it is best to have a local copy of vmware and a vm. Samba works over vpn but file saves seem a little too laggy for my taste.

Sharing Virtual Machines

Co-development is pretty normal on our team. We will pair up two or more developers to work on large projects. Each developer will mount the file system via samba and work away as normal. Once they are code complete we will do a code review and the files will be committed. This has been a huge time saving and performance booster for our team. Just recently we had to build out 10 new websites over a 2 month period and these machines helped make that possible.

Nginx wildcard 301 redirects with query strings

We switched over to the NGINX web server about six months ago from Apache. It has taken a while to get a handle on redirects and wildcards.

Here is a simple 301 wildcard domain redirect:

Now what happens if you have some ads out there with query string parameters like: http://old.domain-name.com/ad-landing-page?tracker=7879790870987

Those will redirect but lose NGINX’s $query_string value on the destination. Here is a simple workaround using a if $query_string:

What if you need to direct a specific folder path to a new domain with query strings and a wild card? Here is the kitchen sink version:

If the redirect is redirecting to the same domain you can use alias instead of return 301.

There you go. NGINX pretty much has the same amount of granularity when performing redirects that apache has.