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