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