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 # gold: {ROOTDIR}/gold
14 # All plugins are optional. A plugin will only be installed if it is listed
15 # in `plugins` AND it is located in a directory that both follows the plugin
16 # naming convention and is correctly located on the host machine. The general
17 # rule for naming each plugin directory is that "reddit-plugin-NAME" should be
18 # in the directory {ROOTDIR}/NAME.
20 # This VagrantFile allows for the creation of two VMs:
21 # * default: the primary VM, with all services necessary to run reddit
22 # locally against the local codebase.
23 # * travis: Testing-only VM suitable for running `nosetests` and debugging
24 # issues encountered without having to wait for travis-ci to pick
25 # up the build. This will *not* be the same environment as
26 # travis, but it should be useful for repairing broken tests.
28 # To start your vagrant box simply enter `vagrant up` from {ROOTDIR}/reddit.
29 # You can then ssh into it with `vagrant ssh`.
31 # avahi-daemon is installed on the guest VM so you can access your local install
32 # at https://reddit.local. If that fails you'll need to update your host
33 # machine's hosts file (/etc/hosts) to include the line:
34 # 192.168.56.111 reddit.local
36 # If you want to create additional vagrant boxes you can copy this file
37 # elsewhere, but be sure to update `code_share_host_path` to be the absolute
40 vagrant_user = "vagrant"
43 this_path = File.absolute_path(__FILE__)
44 reddit_dir = File.expand_path("..", this_path)
45 code_share_host_path = File.expand_path("..", reddit_dir)
46 code_share_guest_path = "/media/reddit_code"
52 # overlayfs directories
53 overlay_mount = "/home/#{vagrant_user}/src"
54 overlay_lower = code_share_guest_path
55 overlay_upper = "/home/#{vagrant_user}/.overlay"
58 guest_ip = "192.168.56.111"
61 hostname = "reddit.local"
64 Vagrant.configure(2) do |config|
65 config.vm.box = "trusty-cloud-image"
66 config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box"
68 # mount the host shared folder
69 config.vm.synced_folder code_share_host_path, code_share_guest_path, mount_options: ["ro"]
71 config.vm.provider "virtualbox" do |vb|
75 # ubuntu cloud image has no swapfile by default, set one up
76 config.vm.provision "shell", inline: <<-SCRIPT
77 if ! grep -q swapfile /etc/fstab; then
78 echo 'swapfile not found. Adding swapfile.'
79 fallocate -l #{guest_swap}M /swapfile
83 echo '/swapfile none swap defaults 0 0' >> /etc/fstab
85 echo 'swapfile found. No changes made.'
89 # set up the overlay filesystem
90 config.vm.provision "shell", inline: <<-SCRIPT
91 if [ ! -d #{overlay_mount} ]; then
92 echo "creating overlay mount directory #{overlay_mount}"
93 sudo -u #{vagrant_user} mkdir #{overlay_mount}
96 if [ ! -d #{overlay_upper} ]; then
97 echo "creating overlay upper directory #{overlay_upper}"
98 sudo -u #{vagrant_user} mkdir #{overlay_upper}
101 echo "mounting overlayfs (lower: #{overlay_lower}, upper: #{overlay_upper}, mount: #{overlay_mount})"
102 mount -t overlayfs overlayfs -o lowerdir=#{overlay_lower},upperdir=#{overlay_upper} #{overlay_mount}
105 # NOTE: This VM exists solely to assist in writing tests. It does not actually
106 # install travis but rather builds a minimal vm with only the services
107 # available under a travis build to aid in test debugging (via `nosetests`)
109 # $ vagrant up travis
110 # $ vagrant ssh travis
111 # vagrant@travis$ cd src/reddit/r2 && nosetests
112 config.vm.define "travis", autostart: false do |travis|
113 travis.vm.hostname = "travis"
115 travis.vm.provision "shell", inline: <<-SCRIPT
116 if [ ! -f /var/local/reddit_installed ]; then
117 echo "running install script"
118 cd /home/#{vagrant_user}/src/reddit
119 ./install/travis.sh vagrant
120 touch /var/local/reddit_installed
122 echo "install script already run"
127 # NB: this is the primary VM. To build run
129 # [though 'vagrant up default' will also work, the 'default' is redudnant]
130 # Once built, avahi-daemon should guarantee the instance will be accessible
131 # from https://reddit.local/
132 config.vm.define "default", primary: true do |redditlocal|
133 redditlocal.vm.hostname = hostname
134 # host-only network interface
135 redditlocal.vm.network "private_network", ip: guest_ip
137 # rabbitmq web interface
138 config.vm.network "forwarded_port", guest: 15672, host: 15672
141 plugin_string = plugins.join(" ")
142 redditlocal.vm.provision "shell", inline: <<-SCRIPT
143 if [ ! -f /var/local/reddit_installed ]; then
144 echo "running install script"
145 cd /home/#{vagrant_user}/src/reddit
146 REDDIT_PLUGINS="#{plugin_string}" REDDIT_DOMAIN="#{hostname}" ./install/reddit.sh
147 touch /var/local/reddit_installed
149 echo "install script already run"
154 redditlocal.vm.provision "shell", inline: <<-SCRIPT
155 if [ ! -f /var/local/test_data_injected ]; then
156 cd /home/#{vagrant_user}/src/reddit
157 sudo -u #{vagrant_user} reddit-run scripts/inject_test_data.py -c 'inject_test_data()'
158 touch /var/local/test_data_injected
160 echo "inject test data already run"
163 # HACK: stop and start everything (otherwise sometimes there's an issue with
164 # ports being in use?)
170 redditlocal.vm.provision "shell", inline: <<-SCRIPT
171 if [ ! -f /var/local/additional_setup ]; then
172 apt-get install -y ipython avahi-daemon
173 touch /var/local/additional_setup
175 echo "additional setup already run"
179 # DONE: let this run whenever provision is run so that the user can see
181 redditlocal.vm.provision "shell", inline: <<-SCRIPT
182 cd /home/#{vagrant_user}/src/reddit
183 REDDIT_DOMAIN="#{hostname}" ./install/done.sh