core.rb 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. def provision_bootstrap(config, role)
  2. # Find all environment variables that begin with
  3. # TFB_* and pass them as an argument. This is a hack to
  4. # let our bootstrap script use environment variables that
  5. # were originally defined on the host
  6. # Skip any potentially sensitive variables
  7. env_arg = ""
  8. skip= ['TFB_AWS_ACCESS_KEY', 'TFB_AWS_SECRET_KEY', 'TFB_AWS_KEY_NAME', 'TFB_AWS_KEY_PATH']
  9. ENV.each do |key, array|
  10. if (key.start_with?("TFB") && !skip.include?(key))
  11. env_arg.concat key
  12. env_arg.concat "="
  13. env_arg.concat array
  14. env_arg.concat "\n"
  15. end
  16. end
  17. env_arg = env_arg.strip
  18. # TODO this will break if the environment contains the ' delimiter,
  19. # so at some point we need to escape the ' character here and unescape
  20. # it in bootstrap.sh
  21. config.vm.provision "shell" do |sh|
  22. sh.path = "../vagrant-common/bootstrap.sh"
  23. sh.privileged = false
  24. sh.args = "'#{env_arg}' '#{role}'"
  25. end
  26. end
  27. def provider_aws(config, role, ip_address='172.16.0.16')
  28. config.vm.provider :aws do |aws, override|
  29. aws.access_key_id = ENV['TFB_AWS_ACCESS_KEY']
  30. aws.secret_access_key = ENV['TFB_AWS_SECRET_KEY']
  31. aws.keypair_name = ENV['TFB_AWS_KEY_NAME']
  32. override.ssh.private_key_path = ENV['TFB_AWS_KEY_PATH']
  33. # Use a boilerplate box - this will be replaced by the AMI
  34. override.vm.box = "dummy"
  35. override.vm.box_url = "https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box"
  36. # From http://cloud-images.ubuntu.com/trusty/current/
  37. # This is 64-bit Ubuntu 14.04 US east EBS
  38. # See http://cloud-images.ubuntu.com/vagrant/trusty/current/
  39. # for comparison to the Ubuntu Vagrant VirtualBox boxes
  40. aws.ami = "ami-f6bf659e"
  41. override.ssh.username = "ubuntu"
  42. aws.private_ip_address = ip_address
  43. aws.associate_public_ip = true
  44. aws.region = ENV.fetch('TFB_AWS_REGION', 'us-east-1')
  45. aws.subnet_id = ENV['TFB_AWS_SUBNET'] # subnet-2737230f for me
  46. aws.security_groups = [ENV['TFB_AWS_SEC_GROUP']] # sg-871240e2
  47. aws.instance_type = ENV.fetch('TFB_AWS_EC2_TYPE', 'm1.large')
  48. aws.tags = {
  49. 'Project' => 'FrameworkBenchmarks',
  50. 'TFB_role' => role
  51. }
  52. # Setup disk. Defauly is 15GB General Purpose SSD
  53. # Double the default volume size, as we download and
  54. # install a *lot* of stuff
  55. # Documentation is at http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-blockdev-template.html
  56. aws.block_device_mapping = [{ 'DeviceName' => '/dev/sda1',
  57. 'Ebs.VolumeSize' => 15 ,
  58. 'Ebs.DeleteOnTermination' => ENV.fetch('TFB_AWS_EBS_DELETE', true),
  59. 'Ebs.VolumeType' => ENV.fetch('TFB_AWS_EBS_TYPE', 'gp2')
  60. }]
  61. if ENV.fetch('TFB_AWS_EBS_TYPE', 'standard') == 'io1'
  62. aws.block_device_mapping[0]['Ebs.Iops'] = ENV.fetch('TFB_AWS_EBS_IO', '1000')
  63. end
  64. if ENV.fetch('TFB_FORCE_SYNC', "false") == "true"
  65. override.vm.synced_folder "../..", "/FrameworkBenchmarks"
  66. end
  67. end
  68. end
  69. def provider_virtualbox(config, role, ip_address='172.16.0.16')
  70. config.vm.network "private_network", ip: ip_address
  71. config.vm.provider :virtualbox do |vb, override|
  72. override.vm.hostname = "TFB-#{role}"
  73. # Valid values are 32 and 64
  74. arch = ENV.fetch('TFB_VB_ARCH','64')
  75. # Value values are precise, trusty, etc
  76. code = ENV.fetch('TFB_VB_CODE','trusty')
  77. override.vm.box = "ubuntu/" + code + arch
  78. if ENV.fetch('TFB_SHOW_VM', false)
  79. vb.gui = true
  80. end
  81. vb.memory = ENV.fetch('TFB_VB_MEM', 2048)
  82. vb.cpus = ENV.fetch('TFB_VB_CPU', 2)
  83. # mount_options addresses issue mitchellh/vagrant#4997
  84. override.vm.synced_folder "../..", "/FrameworkBenchmarks", mount_options: ['fmode=777', 'dmode=777']
  85. if role.eql? "all" or role.eql? "app"
  86. override.vm.network :forwarded_port, guest: 8080, host: 28080
  87. end
  88. end
  89. end