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