Puppet and Vagrant Boxes building a development, testing and staging flow.
The application development workflow will be supported by a setup of virtual machine "boxes". Each box will have its purpose and its predecessor in order to develop easily and fast for and in the web-stack (means web-applications, web- and mvc-frameworks, interfaces).
To work with this setup you do the following:
To clarify: I will not explain vagrant much or puppet or git or do know how host operating systems work. I will however try to explain how this virtualization box model works.
- Install vagrant
- Install Virtualbox
- Clone $this project and edit to your likes:
- Load all submodules from .gitmodules and get the submodules code from github
Linux / Mac:
sudo apt-get install virtualbox
sudo apt-get install vagrant
git clone git@github.com:dazz/puppet-boxes.git
git submodule init
git submodule update
- Install git-flow (git branching model)
- Initialize with git-flow
- Create a new feature/<branch_name> to start customizing the project to your likes to make a pull request later.
Go with terminal into <project_dir>/boxes/basebox and run all the commands in this directory.
vagrant up
Vagrant will run with the Vagrantfile, download the box from the specified box_url and add it to vagrants boxes (see all with vagrant box list). Run the provisioner Puppet startting with the manifest.pp in the same directory (this is how we do it for every box).
Vagrant will start a virtual machine in Virtualbox with
- IP: 192.168.23.42
- User: vagrant, password: vagrant
You can have a look with vagrant ssh(Linux and Mac) but don't touch anything yet, we are not finished :)
Linux: There is a bug that the VM 'remembers' the previously set mac-address of VM. So when you reuse or copy it, it still knows it's copied. See fix here.
When the vagrant comes back with finished setting up the BASE BOX you stop the vm with
vagrant halt
Run following to package the vm as box. Vagrant will package the vm as a box and put it into the directory that xou are in.
vagrant package basebox --output basebox.box
Tip: (add *.box to your .gitignore)
vagrant box add basebox basebox.box
We add it to the other vagrant boxes so we can reference it as base in another Vagrantfile. If you have a look in ~/.vagrant.d/boxes/ there should now be the basebox folder with your previous packed box
Do the same steps above but for the SETUP BOX:
cd <project_dir>/boxes/setupbox
vagrant up
Vagrant imports the basebox we previously added.
vagrant halt
vagrant package setupbox --output setupbox.box
vagrant box add setupbox setupbox.box
The base box will download the first base box from puppetlabs or your chosen url. Everything that needs to be prepared before all the software will be setup will happen in this step.
You can set your own url here with basebox.vm.box_url, but make sure that you do not maintain this box to stay clear of your project scope. it ends here.
The setup box will take the BASE BOX, install all needed packages and setup users and directories.
In this case:
- Apache2.2
- PHP 5.3 / 5.4
- MySQL (datastorage will go to its own vm, in v2)
The production box takes the SETUP BOX and installs the application and sets all the configuration to run it in production environment.
- Set users and rights for files and directories
- Create database user
- Deploy application (from git repo)
The staging box takes the PRODUCTION BOX and sets up a configuration for. If you have a symfony project this would represent your stage environment where you have everything setup like in your production environment, but with profiling and other tools to see what will be deployed.
- translations
- profiling
- stuff that management or production wants to do or to see before going life
The development box takes the stagebox and sets up the system for development. There will be a lot of tools needed.
- installing stuff: aptitude (I install stuff and put it then into this project after coding)
- text editing: vim
- debugging: xdebug
- shell: zShell, setup .bash_aliases
- git
- git user setup (ssh agent forward)
- git-core
- git flow
- gitk
The test box is for running all the tests. The test box takes the PRODUCTION BOX. We need all the software for running tests and reporting
- user acceptance tests
- unit tests
- functional tests
Now we have the setupbox as base box for every iteration we want to do next:
- PRODUCTION BOX
- STAGE BOX and finally the
- DEVELOPER BOX
In the first two stages we won't do anything by hand, but let machines to the work. How many iterations you will need to have a production close environment to develop in depends on your usecase or the company you work for.
There is a problem with machines of the Debian osfamily with writing the mac-address. Fixed this with the basebox with deleting the generated and its generator file.
Copyright 2012 Anne-Julia Scheuermann
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.