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