Created
May 15, 2012 16:09
-
-
Save sivy/2702935 to your computer and use it in GitHub Desktop.
This is a sample of how sprint.ly generates a new Vagrant virtual machine to help developers get up to speed quickly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from fabric.api import * | |
| import os | |
| def dev_server(): | |
| print """ | |
| This setup assumes: | |
| * Your SPRINTLY_HOME environment variable is set to the location of the sprint.ly git checkout. | |
| * The Sprint.ly chef setup is checked out to "$SPRINTLY_HOME/../chef" | |
| """ | |
| # is Vagrant installed? | |
| with settings( | |
| hide('warnings', 'running', 'stdout', 'stderr'), | |
| warn_only=True | |
| ): | |
| has_vagrant = local("which vagrant", capture=True) | |
| if not has_vagrant: | |
| print "You must install vagrant from http://http://vagrantup.com in order to set up a development server VM." | |
| return | |
| # is SPRINTLY_HOME setup? | |
| SPRINTLY_HOME = os.environ['SPRINTLY_HOME'] | |
| if not SPRINTLY_HOME: | |
| print "You must set the SPRINTLY_HOME environment variable to tell us where your local clone of the sprintly codebase is." | |
| return | |
| VAGRANT_HOME = "/".join(SPRINTLY_HOME.split("/")[0:-1]) | |
| print "Using %s as VAGRANT_HOME: " % VAGRANT_HOME | |
| with settings( | |
| hide('warnings', 'running', 'stdout', 'stderr'), | |
| warn_only=True | |
| ): | |
| has_sprintly_box = local("vagrant box list | grep sprintly", capture=True) | |
| if not has_sprintly_box: | |
| print "Creating sprintly box based on lucid32. This will take a while." | |
| local ("vagrant box add sprintly http://files.vagrantup.com/lucid32.box", capture=True) | |
| # is vagrant initialized? | |
| dot_vagrant = "%s/%s" % (VAGRANT_HOME, '.vagrant') | |
| has_dot_vagrant = os.path.exists(dot_vagrant) | |
| if not has_dot_vagrant: | |
| print "Initializing Vagrant in %s/ ..." % (VAGRANT_HOME) | |
| with settings( | |
| hide('warnings', 'running', 'stdout', 'stderr'), | |
| warn_only=True | |
| ): | |
| with lcd(SPRINTLY_HOME): | |
| local ("vagrant init", capture=True) | |
| vagrantfile = "%s/%s" % (VAGRANT_HOME, 'Vagrantfile') | |
| has_vagrantfile = os.path.exists(vagrantfile) | |
| if not has_vagrantfile: | |
| print "creating Vagrantfile in %s" % vagrantfile | |
| template = """ | |
| # -*- mode: ruby -*- | |
| # vi: set ft=ruby : | |
| Vagrant::Config.run do |config| | |
| # Every Vagrant virtual environment requires a box to build off of. | |
| config.vm.box = "sprintly" | |
| # Assign this VM to a host-only network IP, allowing you to access it | |
| # via the IP. Host-only networks can talk to the host machine as well as | |
| # any other machines on the same network, but cannot be accessed (through this | |
| # network interface) by any external networks. | |
| config.vm.network :hostonly, "33.33.33.10" | |
| config.vm.host_name = '%s' | |
| config.vm.share_folder "SPRINTLY_HOME", "/var/sprint.ly", "#{ENV['SPRINTLY_HOME']}" | |
| # Forward a port from the guest to the host, which allows for outside | |
| # computers to access the VM, whereas host only networking does not. | |
| config.vm.forward_port 80, 8080 | |
| # | |
| user = ENV['OPSCODE_USER'] || ENV['USER'] | |
| base_box = ENV['VAGRANT_BOX'] || 'sprintly' | |
| # The Opscode Platform uses HTTPS. Substitute your organization for | |
| # ORGNAME in the URL and validation key. | |
| # | |
| # If you have your own Chef Server, use the appropriate URL, which may be | |
| # HTTP instead of HTTPS depending on your configuration. Also change the | |
| # validation key to validation.pem. | |
| # | |
| config.vm.provision :chef_client do |chef| | |
| chef.chef_server_url = "https://api.opscode.com/organizations/sprintly-aws" | |
| # get these values from your chef/.chef/knife.rb file | |
| chef.validation_key_path = "#{ENV['SPRINTLY_HOME']}/../chef/.chef/sprintly-aws-validator.pem" | |
| chef.validation_client_name = "sprintly-aws-validator" | |
| chef.provisioning_path = "/etc/chef" | |
| chef.log_level = :info | |
| chef.environment = "sprintly_dev" | |
| chef.add_role('sprintly_vagrant_vm') | |
| end | |
| end | |
| """ | |
| vagrantfilecontents = template % "sprintly-appserver-vm-%s" % os.environ['USER'] | |
| with open(vagrantfile, 'w') as vf: | |
| vf.write(vagrantfilecontents) | |
| print "All done! Run 'vagrant up' to bring up your Sprint.ly dev instance." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment