4 # This assumes that the host machine has r2 and all the reddit plugins checked
5 # out and in the correct directories--pay attention to both name and position
6 # relative to the r2 code:
11 # about: {ROOTDIR}/about
12 # adzerk: {ROOTDIR}/adzerk
13 # donate: {ROOTDIR}/donate
14 # gold: {ROOTDIR}/gold
15 # liveupdate: {ROOTDIR}/liveupdate
16 # meatspace: {ROOTDIR}/meatspace
17 # private: {ROOTDIR}/private
19 # All plugins are optional. A plugin will only be installed if it is listed
20 # in `plugins` AND it is located in a directory that both follows the plugin
21 # naming convention and is correctly located on the host machine. The general
22 # rule for naming each plugin directory is that "reddit-plugin-NAME" should be
23 # in the directory {ROOTDIR}/NAME.
25 # This VagrantFile allows for the creation of two VMs:
26 # * default: the primary VM, with all services necessary to run reddit
27 # locally against the local codebase.
28 # * travis: Testing-only VM suitable for running `nosetests` and debugging
29 # issues encountered without having to wait for travis-ci to pick
30 # up the build. This will *not* be the same environment as
31 # travis, but it should be useful for repairing broken tests.
33 # To start your vagrant box simply enter `vagrant up` from {ROOTDIR}/reddit.
34 # You can then ssh into it with `vagrant ssh`.
36 # avahi-daemon is installed on the guest VM so you can access your local install
37 # at https://reddit.local. If that fails you'll need to update your host
38 # machine's hosts file (/etc/hosts) to include the line:
39 # 192.168.56.111 reddit.local
41 # If you want to create additional vagrant boxes you can copy this file
42 # elsewhere, but be sure to update `code_share_host_path` to be the absolute
45 vagrant_user = "vagrant"
48 this_path = File.absolute_path(__FILE__)
49 reddit_dir = File.expand_path("..", this_path)
50 code_share_host_path = File.expand_path("..", reddit_dir)
51 code_share_guest_path = "/media/reddit_code"
62 # overlayfs directories
63 overlay_mount = "/home/#{vagrant_user}/src"
64 overlay_lower = code_share_guest_path
65 overlay_upper = "/home/#{vagrant_user}/.overlay"
68 guest_ip = "192.168.56.111"
71 hostname = "reddit.local"
74 Vagrant.configure(2) do |config|
75 config.vm.box = "trusty-cloud-image"
76 config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box"
78 # mount the host shared folder
79 config.vm.synced_folder code_share_host_path, code_share_guest_path, mount_options: ["ro"]
81 config.vm.provider "virtualbox" do |vb|
85 # ubuntu cloud image has no swapfile by default, set one up
86 config.vm.provision "shell", inline: <<-SCRIPT
87 if ! grep -q swapfile /etc/fstab; then
88 echo 'swapfile not found. Adding swapfile.'
89 fallocate -l #{guest_swap}M /swapfile
93 echo '/swapfile none swap defaults 0 0' >> /etc/fstab
95 echo 'swapfile found. No changes made.'
99 # set up the overlay filesystem
100 config.vm.provision "shell", inline: <<-SCRIPT
101 if [ ! -d #{overlay_mount} ]; then
102 echo "creating overlay mount directory #{overlay_mount}"
103 sudo -u #{vagrant_user} mkdir #{overlay_mount}
106 if [ ! -d #{overlay_upper} ]; then
107 echo "creating overlay upper directory #{overlay_upper}"
108 sudo -u #{vagrant_user} mkdir #{overlay_upper}
111 echo "mounting overlayfs (lower: #{overlay_lower}, upper: #{overlay_upper}, mount: #{overlay_mount})"
112 mount -t overlayfs overlayfs -o lowerdir=#{overlay_lower},upperdir=#{overlay_upper} #{overlay_mount}
115 # NOTE: This VM exists solely to assist in writing tests. It does not actually
116 # install travis but rather builds a minimal vm with only the services
117 # available under a travis build to aid in test debugging (via `nosetests`)
119 # $ vagrant up travis
120 # $ vagrant ssh travis
121 # vagrant@travis$ cd src/reddit/r2 && nosetests
122 config.vm.define "travis", autostart: false do |travis|
123 travis.vm.hostname = "travis"
125 travis.vm.provision "shell", inline: <<-SCRIPT
126 if [ ! -f /var/local/reddit_installed ]; then
127 echo "running install script"
128 cd /home/#{vagrant_user}/src/reddit
129 ./install/travis.sh vagrant
130 touch /var/local/reddit_installed
132 echo "install script already run"
137 # NB: this is the primary VM. To build run
139 # [though 'vagrant up default' will also work, the 'default' is redudnant]
140 # Once built, avahi-daemon should guarantee the instance will be accessible
141 # from https://reddit.local/
142 config.vm.define "default", primary: true do |redditlocal|
143 redditlocal.vm.hostname = hostname
144 # host-only network interface
145 redditlocal.vm.network "private_network", ip: guest_ip
147 # rabbitmq web interface
148 config.vm.network "forwarded_port", guest: 15672, host: 15672
151 plugin_string = plugins.join(" ")
152 redditlocal.vm.provision "shell", inline: <<-SCRIPT
153 if [ ! -f /var/local/reddit_installed ]; then
154 echo "running install script"
155 cd /home/#{vagrant_user}/src/reddit
156 REDDIT_PLUGINS="#{plugin_string}" REDDIT_DOMAIN="#{hostname}" ./install/reddit.sh
157 touch /var/local/reddit_installed
159 echo "install script already run"
164 redditlocal.vm.provision "shell", inline: <<-SCRIPT
165 if [ ! -f /var/local/test_data_injected ]; then
166 cd /home/#{vagrant_user}/src/reddit
167 sudo -u #{vagrant_user} reddit-run scripts/inject_test_data.py -c 'inject_test_data()'
168 touch /var/local/test_data_injected
170 echo "inject test data already run"
173 # HACK: stop and start everything (otherwise sometimes there's an issue with
174 # ports being in use?)
180 redditlocal.vm.provision "shell", inline: <<-SCRIPT
181 if [ ! -f /var/local/additional_setup ]; then
182 apt-get install -y ipython avahi-daemon
183 touch /var/local/additional_setup
185 echo "additional setup already run"
189 # DONE: let this run whenever provision is run so that the user can see
191 redditlocal.vm.provision "shell", inline: <<-SCRIPT
192 cd /home/#{vagrant_user}/src/reddit
193 REDDIT_DOMAIN="#{hostname}" ./install/done.sh