From 193b2e37c15e1c1d385c04cad76e7de2b9bd7fce Mon Sep 17 00:00:00 2001 From: Craig Tracey Date: Tue, 24 Mar 2015 15:26:34 -0400 Subject: [PATCH] Update Vagrantfile to make use of OpenStack provider Updating the Vagrantfile so that builds may be run in an OpenStack cleanroom instance as well as locally via virtualbox. In order to properly configure the vagrant instance, a number of environment variables are utilized. First, all normal OpenStack auth envronment vars are used to create the instance, and then a host of GIFTWRAP_OS_* vars are added to control things like the image being spun up, the networks it is attached to, etc. A postbuild mechanism is added to allow one to do things like ship artifacts to a repo, Swift, etc. --- .gitignore | 1 + Vagrantfile | 52 ++++++++++++++++++++++++++++++++++----- scripts/prepare_debian.sh | 5 ++-- 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 77e237c..546e681 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ pbr*.egg *.pyc *.sw? *.deb +manifests/* diff --git a/Vagrantfile b/Vagrantfile index ed362aa..8623155 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,31 +1,71 @@ # encoding: UTF-8 GIFTWRAP_MANIFEST = ENV['GIFTWRAP_MANIFEST'] || 'examples/manifest.yml' +GIFTWRAP_ARGS = ENV['GIFTWRAP_ARGS'] || '-t package' GIFTWRAP_BUILDBOX_NAME = ENV['GIFTWRAP_BUILDBOX_NAME'] || 'ursula-precise' GIFTWRAP_BUILDBOX_URL = ENV['GIFTWRAP_BUILDBOX_URL'] || 'http://apt.openstack.blueboxgrid.com/vagrant/ursula-precise.box' +GIFTWRAP_POSTBUILD_SCRIPT = ENV['GIFTWRAP_POSTBUILD_SCRIPT'] || "" + +ENV['VAGRANT_DEFAULT_PROVIDER'] = 'virtualbox' Vagrant.configure('2') do |config| config.vm.box = GIFTWRAP_BUILDBOX_NAME config.vm.box_url = GIFTWRAP_BUILDBOX_URL + config.vm.provider :openstack do |os, override| + os.openstack_auth_url = "#{ENV['OS_AUTH_URL']}/tokens" + os.username = ENV['OS_USERNAME'] + os.password = ENV['OS_PASSWORD'] + os.tenant_name = ENV['OS_TENANT_NAME'] + os.openstack_network_url = ENV['OS_NEUTRON_URL'] + + os.flavor = ENV['GIFTWRAP_OS_FLAVOR'] || 'm1.small' + os.image = ENV['GIFTWRAP_OS_IMAGE'] || 'ubuntu-12.04' + + if ENV['GIFTWRAP_OS_NETWORKS'] + os.networks = ENV['GIFTWRAP_OS_NETWORKS'].split(",") + else + os.networks = ['internal'] + end + + override.ssh.username = ENV['GIFTWRAP_OS_USERNAME'] || 'ubuntu' + if ENV['GIFTWRAP_OS_FLOATING_IP_POOL'] + os.floating_ip_pool = ENV['GIFTWRAP_OS_FLOATING_IP_POOL'] + end + if ENV['GIFTWRAP_OS_SECURITY_GROUPS'] + os.security_groups = ENV['GIFTWRAP_SECURITY_GROUPS'].split(",") + end + os.rsync_exclude_paths = [] + os.rsync_cvs_exclude = false + end + config.vm.provision 'shell', inline: <<-EOF + #!/bin/bash + set -x + set -e if [ -f /etc/lsb-release ]; then - . /etc/lsb-release - OS=$DISTRIB_ID + . /etc/lsb-release + OS=$DISTRIB_ID elif [ -f /etc/debian_version ]; then - OS=Debian + OS=Debian elif [ -f /etc/redhat-release ]; then - OS=RedHat + OS=RedHat fi if [ "$OS" == "Debian" ] || [ "$OS" == "Ubuntu" ]; then - /vagrant/scripts/prepare_debian.sh + /vagrant/scripts/prepare_debian.sh fi gem install --no-ri --no-rdoc fpm cd /vagrant python setup.py install - giftwrap build -m #{GIFTWRAP_MANIFEST} + giftwrap build -m #{GIFTWRAP_MANIFEST} #{GIFTWRAP_ARGS} + + if [ ! -z "#{GIFTWRAP_POSTBUILD_SCRIPT}" ]; then + echo "Running postbuild script: '#{GIFTWRAP_POSTBUILD_SCRIPT}'" + #{GIFTWRAP_POSTBUILD_SCRIPT} + fi + EOF config.vm.define 'giftwrap' do |c| diff --git a/scripts/prepare_debian.sh b/scripts/prepare_debian.sh index 866c23f..bdb657c 100755 --- a/scripts/prepare_debian.sh +++ b/scripts/prepare_debian.sh @@ -1,4 +1,5 @@ #!/bin/bash -apt-get update -apt-get install -y build-essential ruby1.9.1-dev git python-pip python-dev python-virtualenv libxml2-dev libxslt-dev libffi-dev libmysqlclient-dev libpq-dev libsqlite3-dev +apt-get -yqq update +apt-get dist-upgrade -y +apt-get install -yqq build-essential ruby1.9.1-dev git python-pip python-dev python-virtualenv libxml2-dev libxslt-dev libffi-dev libmysqlclient-dev libpq-dev libsqlite3-dev