Vagrantfile 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. # -*- mode: ruby -*-
  2. # vi: set ft=ruby :
  3. # This file is for use by Vagrant (http://www.vagrantup.com/).
  4. # It will establish a debian-based (Ubuntu) virtual machine for development.
  5. # The virtual machine environment attempts to match the production environment
  6. # as closely as possible.
  7. # This file was generated by `vagrant up` and consequently modified.
  8. # Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
  9. VAGRANTFILE_API_VERSION = "2"
  10. # Copy the vagrant SSH key into the VM so vagrant can SSH to localhost within
  11. # the VM. Continued in the shell script below.
  12. # http://serverfault.com/questions/491343/how-can-i-move-my-deploy-key-into-vagrant#comment549259_491345
  13. git_ssh_key = File.read(ENV['HOME'] + '/.vagrant.d/insecure_private_key');
  14. # build a shell script that installs prereqs, copies over the host secrets,
  15. # configures the database, sets up the user/group associations, creates a self
  16. # signed SSL cert, pulls in the code from the host machine, sets up some
  17. # external dependency configs, and then runs fabric.
  18. shellscript = <<SCRIPT
  19. cat >>/home/vagrant/.ssh/insecure_private_key <<EOF
  20. #{git_ssh_key}
  21. EOF
  22. chown vagrant:vagrant /home/vagrant/.ssh/insecure_private_key
  23. chmod 600 /home/vagrant/.ssh/insecure_private_key
  24. cat >>/home/vagrant/.ssh/config <<EOF
  25. Host localhost
  26. User vagrant
  27. IdentityFile ~/.ssh/insecure_private_key
  28. Host 127.0.0.1
  29. User vagrant
  30. IdentityFile ~/.ssh/insecure_private_key
  31. EOF
  32. chmod 644 /home/vagrant/.ssh/config
  33. cat >/home/vagrant/localhost.conf <<EOF
  34. [req]
  35. default_keyfile=localhost.key.pem
  36. encrypt_key=no
  37. default_bits=512
  38. prompt=no
  39. utf8=yes
  40. distinguished_name=dn
  41. [dn]
  42. C=US
  43. ST=Massachusetts
  44. L=Cambridge
  45. O=FinalsClub Foundation
  46. CN=localhost
  47. emailAddress=info@karmanotes.org
  48. EOF
  49. cd /home/vagrant
  50. openssl req -new -config localhost.conf -out localhost.csr.pem
  51. openssl x509 -req -in localhost.csr.pem -signkey localhost.key.pem -out localhost.cert.pem
  52. chown vagrant:vagrant localhost*
  53. cd -
  54. export DEBIAN_FRONTEND=noninteractive
  55. add-apt-repository -y ppa:coolwanglu/pdf2htmlex # pdf2htmlex
  56. apt-get update
  57. apt-get upgrade -y
  58. apt-get install -y python-pip postgresql python-virtualenv libffi-dev \
  59. git nginx postgresql-server-dev-9.1 libxslt1-dev \
  60. libxml2-dev libmemcached-dev python-dev rabbitmq-server \
  61. p7zip-full pdf2htmlex
  62. cat >> `dpkg -L pdf2htmlex | grep pdf2htmlEX.js` <<PDF2HTMLEXHACK
  63. Viewer.prototype['rescale'] = Viewer.prototype.rescale;
  64. Viewer.prototype['scroll_to'] = Viewer.prototype.scroll_to;
  65. PDF2HTMLEXHACK
  66. echo "CREATE USER vagrant WITH CREATEROLE CREATEDB LOGIN; CREATE DATABASE karmaworld OWNER vagrant;" | su postgres -c "psql"
  67. mkdir -m 775 -p /var/www
  68. chown -R :www-data /var/www
  69. usermod -a -G www-data vagrant
  70. su vagrant -c "git clone /vagrant karmaworld"
  71. SECRETPATH="karmaworld/secret"
  72. su vagrant -c "cp /vagrant/$SECRETPATH/* karmaworld/$SECRETPATH/"
  73. CFILE="karmaworld/$SECRETPATH/db_settings.py"
  74. cat > $CFILE <<CONFIG
  75. #!/usr/bin/env python
  76. # -*- coding:utf8 -*-
  77. # Copyright (C) 2012 FinalsClub Foundation
  78. """
  79. DO NOT check this file into source control.
  80. """
  81. PROD_DB_NAME = 'karmaworld'
  82. PROD_DB_USERNAME = 'vagrant'
  83. PROD_DB_PASSWORD = ''
  84. CONFIG
  85. chown vagrant:vagrant karmaworld/$SECRETPATH/*.py
  86. cat > /etc/nginx/sites-available/karmaworld <<CONFIG
  87. server {
  88. listen 80;
  89. server_name localhost;
  90. return 301 https://\\\$host:6659\\\$request_uri;
  91. }
  92. server {
  93. listen 443;
  94. ssl on;
  95. # don't do virtual hosting, handle all requests regardless of header
  96. server_name localhost;
  97. client_max_body_size 20M;
  98. ssl_certificate /home/vagrant/localhost.cert.pem;
  99. ssl_certificate_key /home/vagrant/localhost.key.pem;
  100. location / {
  101. # pass traffic through to gunicorn
  102. proxy_pass http://127.0.0.1:8000;
  103. # pass HTTP(S) status through to Django
  104. proxy_set_header X-Forwarded-SSL \\\$https;
  105. proxy_set_header X-Forwarded-Protocol \\\$scheme;
  106. proxy_set_header X-Forwarded-Proto \\\$scheme;
  107. # pass nginx site back to Django
  108. proxy_set_header Host \\\$http_host;
  109. }
  110. }
  111. CONFIG
  112. rm /etc/nginx/sites-enabled/default
  113. ln -s /etc/nginx/sites-available/karmaworld /etc/nginx/sites-enabled/karmaworld
  114. sudo service nginx restart
  115. cp karmaworld/confs/prod/supervisor /etc/init.d
  116. chmod 755 /etc/init.d/supervisor
  117. update-rc.d supervisor defaults
  118. pip install fabric
  119. SCRIPT
  120. # end of script
  121. Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  122. # All Vagrant configuration is done here. The most common configuration
  123. # options are documented and commented below. For a complete reference,
  124. # please see the online documentation at vagrantup.com.
  125. # Every Vagrant virtual environment requires a box to build off of.
  126. config.vm.box = "Official Ubuntu 12.04 daily Cloud Image i386"
  127. #config.vm.box = "Official Ubuntu 12.04 daily Cloud Image amd64"
  128. #config.vm.box = "Official Ubuntu 12.10 daily Cloud Image i386"
  129. #config.vm.box = "Official Ubuntu 12.10 daily Cloud Image amd64"
  130. #config.vm.box = "Official Ubuntu 13.04 daily Cloud Image i386"
  131. #config.vm.box = "Official Ubuntu 13.04 daily Cloud Image amd64"
  132. #config.vm.box = "Official Ubuntu 13.10 daily Cloud Image i386"
  133. #config.vm.box = "Official Ubuntu 13.10 daily Cloud Image amd64"
  134. # The url from where the 'config.vm.box' box will be fetched if it
  135. # doesn't already exist on the user's system.
  136. config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-i386-vagrant-disk1.box"
  137. #config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-amd64-vagrant-disk1.box"
  138. #config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/quantal/current/quantal-server-cloudimg-i386-vagrant-disk1.box"
  139. #config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/quantal/current/quantal-server-cloudimg-amd64-vagrant-disk1.box"
  140. #config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/raring/current/raring-server-cloudimg-i386-vagrant-disk1.box"
  141. #config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/raring/current/raring-server-cloudimg-amd64-vagrant-disk1.box"
  142. #config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/saucy/current/saucy-server-cloudimg-i386-vagrant-disk1.box"
  143. #config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/saucy/current/saucy-server-cloudimg-amd64-vagrant-disk1.box"
  144. # Create a forwarded port mapping which allows access to a specific port
  145. # within the machine from a port on the host machine. In the example below,
  146. # accessing "localhost:8080" will access port 80 on the guest machine.
  147. # config.vm.network :forwarded_port, guest: 80, host: 8080
  148. # OM (sanskrit) KW (KarmaWorld) on a phone: 66 59
  149. config.vm.network :forwarded_port, guest: 443, host: 6659, auto_correct: true
  150. config.vm.network :forwarded_port, guest: 80, host: 16659, auto_correct: true
  151. # Create a private network, which allows host-only access to the machine
  152. # using a specific IP.
  153. #config.vm.network :private_network, ip: "192.168.66.59"
  154. # Create a public network, which generally matched to bridged network.
  155. # Bridged networks make the machine appear as another physical device on
  156. # your network.
  157. # Used to directly access the internet for downloading updates and so forth.
  158. config.vm.network :public_network
  159. # If true, then any SSH connections made will enable agent forwarding.
  160. # Default value: false
  161. # config.ssh.forward_agent = true
  162. # Share an additional folder to the guest VM. The first argument is
  163. # the path on the host to the actual folder. The second argument is
  164. # the path on the guest to mount the folder. And the optional third
  165. # argument is a set of non-required options.
  166. # config.vm.synced_folder "../data", "/vagrant_data"
  167. # Setup scripts
  168. config.vm.provision "shell", inline: shellscript
  169. # Provider-specific configuration so you can fine-tune various
  170. # backing providers for Vagrant. These expose provider-specific options.
  171. # Example for VirtualBox:
  172. #
  173. # config.vm.provider :virtualbox do |vb|
  174. # # Don't boot with headless mode
  175. # vb.gui = true
  176. #
  177. # # Use VBoxManage to customize the VM. For example to change memory:
  178. # vb.customize ["modifyvm", :id, "--memory", "1024"]
  179. # end
  180. #
  181. # View the documentation for the provider you're using for more
  182. # information on available options.
  183. # Enable provisioning with Puppet stand alone. Puppet manifests
  184. # are contained in a directory path relative to this Vagrantfile.
  185. # You will need to create the manifests directory and a manifest in
  186. # the file base.pp in the manifests_path directory.
  187. #
  188. # An example Puppet manifest to provision the message of the day:
  189. #
  190. # # group { "puppet":
  191. # # ensure => "present",
  192. # # }
  193. # #
  194. # # File { owner => 0, group => 0, mode => 0644 }
  195. # #
  196. # # file { '/etc/motd':
  197. # # content => "Welcome to your Vagrant-built virtual machine!
  198. # # Managed by Puppet.\n"
  199. # # }
  200. #
  201. # config.vm.provision :puppet do |puppet|
  202. # puppet.manifests_path = "manifests"
  203. # puppet.manifest_file = "site.pp"
  204. # end
  205. # Enable provisioning with chef solo, specifying a cookbooks path, roles
  206. # path, and data_bags path (all relative to this Vagrantfile), and adding
  207. # some recipes and/or roles.
  208. #
  209. # config.vm.provision :chef_solo do |chef|
  210. # chef.cookbooks_path = "../my-recipes/cookbooks"
  211. # chef.roles_path = "../my-recipes/roles"
  212. # chef.data_bags_path = "../my-recipes/data_bags"
  213. # chef.add_recipe "mysql"
  214. # chef.add_role "web"
  215. #
  216. # # You may also specify custom JSON attributes:
  217. # chef.json = { :mysql_password => "foo" }
  218. # end
  219. # Enable provisioning with chef server, specifying the chef server URL,
  220. # and the path to the validation key (relative to this Vagrantfile).
  221. #
  222. # The Opscode Platform uses HTTPS. Substitute your organization for
  223. # ORGNAME in the URL and validation key.
  224. #
  225. # If you have your own Chef Server, use the appropriate URL, which may be
  226. # HTTP instead of HTTPS depending on your configuration. Also change the
  227. # validation key to validation.pem.
  228. #
  229. # config.vm.provision :chef_client do |chef|
  230. # chef.chef_server_url = "https://api.opscode.com/organizations/ORGNAME"
  231. # chef.validation_key_path = "ORGNAME-validator.pem"
  232. # end
  233. #
  234. # If you're using the Opscode platform, your validator client is
  235. # ORGNAME-validator, replacing ORGNAME with your organization name.
  236. #
  237. # If you have your own Chef Server, the default validation client name is
  238. # chef-validator, unless you changed the configuration.
  239. #
  240. # chef.validation_client_name = "ORGNAME-validator"
  241. end