Selaa lähdekoodia

Rename/move more into the vagrant-common folder

Hamilton Turner 11 vuotta sitten
vanhempi
commit
e72bcb4665

+ 17 - 9
toolset/deployment/vagrant-common/bootstrap.sh

@@ -6,25 +6,33 @@
 # same script can work for VirtualBox (username vagrant)
 # and Amazon (username ubuntu)
 
+# Add everything passed in the first argument to our 
+# local environment. This is a hack to let us use 
+# environment variables defined on the host inside the 
+# guest machine
+while read -r line; do  
+  export $line; 
+done <<< "$1"
+
 # Set a number of variables by either pulling them from 
 # the existing environment or using the default values
 # I'm renaming them to indicate that (in this script only)
 # the values are provisioner agnostic
-SERVER_IP=${TFB_AWS_APP_IP:=172.16.0.16}
-CLIENT_IP=${TFB_AWS_LOAD_IP:=172.16.0.17}
-DATABA_IP=${TFB_AWS_DB_IP:=172.16.0.18}
+SERVER_IP=${TFB_AWS_APP_IP:-172.16.0.16}
+CLIENT_IP=${TFB_AWS_LOAD_IP:-172.16.0.17}
+DATABA_IP=${TFB_AWS_DB_IP:-172.16.0.18}
 
-GH_REPO=${TFB_AWS_REPO_SLUG:=TechEmpower/FrameworkBenchmarks}
-GH_BRANCH=${TFB_AWS_REPO_BRANCH:=master}
+GH_REPO=${TFB_AWS_REPO_SLUG:-TechEmpower/FrameworkBenchmarks}
+GH_BRANCH=${TFB_AWS_REPO_BRANCH:-master}
 
 # Are we installing the server machine, the client machine, 
 # the database machine, or all machines? 
-ROLE=${1:=all}
+ROLE=${2:-all}
 
 # Are we installing in production mode, or development mode?
 # It's odd to have ROLE=all and MODE=prod, but I suppose it 
 # could happen so I'm using two variables instead of one
-MODE=${2:=dev}
+MODE=${3:-dev}
 
 # A shell provisioner is called multiple times
 if [ ! -e "~/.firstboot" ]; then
@@ -63,7 +71,7 @@ if [ ! -e "~/.firstboot" ]; then
   if [ "$ROLE" != "all" ]; then
     echo "Updating hostname"
     echo 127.0.0.1 `hostname` | sudo tee --append /etc/hosts
-    myhost=TFB-${1}
+    myhost=TFB-${ROLE}
     echo $myhost | sudo tee --append /etc/hostname
     sudo hostname $myhost
     echo Updated /etc/hosts file to be: 
@@ -124,5 +132,5 @@ if [ ! -e "~/.firstboot" ]; then
   echo "Setting up welcome message"
   sudo rm -f /etc/update-motd.d/51-cloudguest
   sudo rm -f /etc/update-motd.d/98-cloudguest
-  sudo cp /vagrant/custom_motd.sh /etc/update-motd.d/55-tfbwelcome
+  sudo mv /custom_motd.sh /etc/update-motd.d/55-tfbwelcome
 fi

+ 0 - 0
toolset/deployment/vagrant-common/common.rb → toolset/deployment/vagrant-common/checks.rb


+ 98 - 0
toolset/deployment/vagrant-common/core.rb

@@ -0,0 +1,98 @@
+
+def provision_bootstrap(config, role)
+  # Find all environment variables that begin with 
+  # TFB_* and pass them as an argument. This is a hack to 
+  # let our bootstrap script use environment variables that 
+  # were originally defined on the host 
+  env_arg = ""
+  ENV.each do |key, array|
+    if key.start_with? "TFB"
+      env_arg.concat key
+      env_arg.concat "="
+      env_arg.concat array
+      env_arg.concat "\n"
+    end
+  end
+  env_arg = env_arg.strip
+
+  # TODO this will break if the environment contains the ' character, 
+  # so at some point we need to escape the ' character here and unescape
+  # it in bootstrap.sh
+  config.vm.provision "shell" do |sh|
+    sh.path = "../vagrant-common/bootstrap.sh"
+    sh.privileged = false
+    sh.args = "'#{env_arg}' '#{role}'"
+  end
+end
+
+def provider_aws(config, role, ip_address)
+  config.vm.provider :aws do |aws, override|
+    aws.access_key_id = ENV['TFB_AWS_ACCESS_KEY'] 
+    aws.secret_access_key = ENV['TFB_AWS_SECRET_KEY']
+    aws.keypair_name = ENV['TFB_AWS_KEY_NAME']
+    override.ssh.private_key_path = ENV['TFB_AWS_KEY_PATH']
+
+    # Use a boilerplate box - this will be replaced by the AMI
+    override.vm.box = "dummy"
+    override.vm.box_url = "https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box"
+    
+    # From http://cloud-images.ubuntu.com/trusty/current/
+    # This is 64-bit Ubuntu 14.04 US east EBS
+    # See http://cloud-images.ubuntu.com/vagrant/trusty/current/ 
+    # for comparison to the Ubuntu Vagrant VirtualBox boxes 
+    aws.ami = "ami-62c8160a"
+    override.ssh.username = "ubuntu"
+
+
+    aws.region = ENV.fetch('TFB_AWS_REGION', 'us-east-1')
+    
+    aws.private_ip_address = ip_address
+    aws.associate_public_ip = true
+    aws.subnet_id = ENV['TFB_AWS_SUBNET']  # subnet-2737230f for me
+    aws.security_groups = [ENV['TFB_AWS_SEC_GROUP']] # sg-871240e2 
+
+    aws.tags = {
+      'Project' => 'FrameworkBenchmarks',
+      'TFB_role' => role
+     }
+    
+    # Double the default volume size, as we download and 
+    # install a *lot* of stuff
+
+    # TODO use http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-blockdev-template.html
+    # and read the type from the environment
+    aws.block_device_mapping = [{ 'DeviceName' => '/dev/sda1', 'Ebs.VolumeSize' => 15 }]
+
+    aws.instance_type = "m1.small"
+  end
+end
+
+def provider_virtualbox(config, role, ip_address)
+  config.vm.provider :virtualbox do |vb, override|
+    override.vm.hostname = "TFB-#{role}"
+
+    override.vm.box = "ubuntu/trusty64"
+    if ENV.fetch('TFB_VM_ARCH','64') == "32"
+      override.vm.box = "ubuntu/trusty32"
+    end
+
+    # Use a non-standard value here as most home networks are 
+    # 192.168.X.X or 10.X.X.X and we cannot have a collision 
+    # with the host network
+    override.vm.network "private_network", ip: ip_address
+    
+    if ENV.fetch('TFB_SHOW_VM', false)
+      vb.gui = true
+    end
+
+    if ENV.fetch('TFB_VB_MEM', 2048)
+      vb.customize ["modifyvm", :id, "--memory", "2048"]
+    end
+
+    override.vm.synced_folder "../../..", "/FrameworkBenchmarks"
+
+    if role.eql? "all" or role.eql? "app"
+      override.vm.network :forwarded_port, guest: 8080, host: 28080
+    end
+  end
+end

+ 0 - 15
toolset/deployment/vagrant-production/custom_motd.sh

@@ -1,15 +0,0 @@
-#!/bin/sh
-
-echo "$(tput setaf 4)"
-echo "Welcome to the FrameworkBenchmarks project!"
-echo ""
-echo "  To get started, perhaps try this:"
-echo "    \$ cd FrameworkBenchmarks"
-echo "    \$ toolset/run-tests.py --install server --test go"
-echo "    \$ cat results/ec2/latest/logs/go/out.txt"
-echo ""
-echo "  You can get lots of help:"
-echo "    \$ toolset/run-tests.py --help"
-echo ""
-echo "  This Vagrant environment is already setup and ready to go, so you"
-printf "  can safely ignore any flags about users, hosts, or identity files $(tput sgr 0)"

+ 0 - 51
toolset/deployment/vagrant-production/production-env.rb

@@ -1,51 +0,0 @@
-
-def provision_bootstrap(config, role)
-  config.vm.provision "shell" do |sh|
-    sh.path = "bootstrap.sh"
-    sh.privileged = false
-    sh.args = role
-  end
-end
-
-def provider_aws(config, role, ip_address)
-  config.vm.provider :aws do |aws, override|
-    aws.access_key_id = ENV['TFB_AWS_ACCESS_KEY'] 
-    aws.secret_access_key = ENV['TFB_AWS_SECRET_KEY']
-    aws.keypair_name = ENV['TFB_AWS_KEY_NAME']
-    override.ssh.private_key_path = ENV['TFB_AWS_KEY_PATH']
-
-    override.vm.box = "dummy"
-    override.vm.box_url = "https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box"
-    aws.ami = "ami-62c8160a"
-    override.ssh.username = "ubuntu"
-    
-    aws.private_ip_address = ip_address
-    aws.associate_public_ip = true
-    aws.subnet_id = "subnet-2737230f"
-    aws.security_groups = ["sg-871240e2"]
-
-    aws.tags = {
-      'Project' => 'FrameworkBenchmarks',
-      'TFB_role' => role
-     }
-    
-    # Double the default volume size, as we download and 
-    # install a *lot* of stuff
-
-    # TODO use http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-blockdev-template.html
-    # and read the type from the environment
-    aws.block_device_mapping = [{ 'DeviceName' => '/dev/sda1', 'Ebs.VolumeSize' => 15 }]
-
-    aws.instance_type = "m1.small"
-  end
-end
-
-def provider_virtualbox(config, role, ip_address)
-  config.vm.provider :virtualbox do |vb, override|
-    override.vm.hostname = "TFB-#{role}"
-    override.vm.box = "ubuntu/trusty64"
-    override.vm.network "private_network", ip: ip_address
-    
-    override.vm.synced_folder "../../..", "/FrameworkBenchmarks"
-  end
-end