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 # i18n: {ROOTDIR}/i18n
12 # about: {ROOTDIR}/about
13 # meatspace: {ROOTDIR}/meatspace
14 # liveupdate: {ROOTDIR}/liveupdate
15 # adzerk: {ROOTDIR}/adzerk
16 # donate: {ROOTDIR}/donate
17 # gold: {ROOTDIR}/gold
19 # private internal reddit plugin:
20 # private: {ROOTDIR}/private
22 # The plugins are all optional, but they will get cloned in the VM (and as a
23 # result be uneditable from the host) by the install script if their directory
24 # is missing but is included in `plugins` below. The general rule for naming
25 # each plugin directory is that "reddit-plugin-NAME" should be in the directory
28 # This VagrantFile allows for the creation of two VMs:
29 # * default: the primary VM, with all services necessary to run reddit
30 # locally against the local codebase.
31 # * travis: Testing-only VM suitable for running `nosetests` and debugging
32 # issues encountered without having to wait for travis-ci to pick
33 # up the build. This will *not* be the same environment as
34 # travis, but it should be useful for repairing broken tests.
36 # To start your vagrant box simply enter `vagrant up` from {ROOTDIR}/reddit.
37 # You can then ssh into it with `vagrant ssh`.
39 # avahi-daemon is installed on the guest VM so you can access your local install
40 # at https://reddit.local. If that fails you'll need to update your host
41 # machine's hosts file (/etc/hosts) to include the line:
42 # 192.168.56.111 reddit.local
44 # If you want to create additional vagrant boxes you can copy this file
45 # elsewhere, but be sure to update `code_share_host_path` to be the absolute
48 vagrant_user = "vagrant"
51 this_path = File.absolute_path(__FILE__)
52 reddit_dir = File.expand_path("..", this_path)
53 code_share_host_path = File.expand_path("..", reddit_dir)
54 code_share_guest_path = "/media/reddit_code"
55 plugins = ["meatspace", "about", "liveupdate", "adzerk", "donate", "gold"]
57 # overlayfs directories
58 overlay_mount = "/home/#{vagrant_user}/src"
59 overlay_lower = code_share_guest_path
60 overlay_upper = "/home/#{vagrant_user}/.overlay"
63 guest_ip = "192.168.56.111"
66 hostname = "reddit.local"
69 Vagrant.configure(2) do |config|
70 config.vm.box = "trusty-cloud-image"
71 config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box"
73 # mount the host shared folder
74 config.vm.synced_folder code_share_host_path, code_share_guest_path, mount_options: ["ro"]
76 config.vm.provider "virtualbox" do |vb|
80 # ubuntu cloud image has no swapfile by default, set one up
81 config.vm.provision "shell", inline: <<-SCRIPT
82 if ! grep -q swapfile /etc/fstab; then
83 echo 'swapfile not found. Adding swapfile.'
84 fallocate -l #{guest_swap}M /swapfile
88 echo '/swapfile none swap defaults 0 0' >> /etc/fstab
90 echo 'swapfile found. No changes made.'
94 # set up the overlay filesystem
95 config.vm.provision "shell", inline: <<-SCRIPT
96 if [ ! -d #{overlay_mount} ]; then
97 echo "creating overlay mount directory #{overlay_mount}"
98 sudo -u #{vagrant_user} mkdir #{overlay_mount}
101 if [ ! -d #{overlay_upper} ]; then
102 echo "creating overlay upper directory #{overlay_upper}"
103 sudo -u #{vagrant_user} mkdir #{overlay_upper}
106 echo "mounting overlayfs (lower: #{overlay_lower}, upper: #{overlay_upper}, mount: #{overlay_mount})"
107 mount -t overlayfs overlayfs -o lowerdir=#{overlay_lower},upperdir=#{overlay_upper} #{overlay_mount}
110 # NOTE: This VM exists solely to assist in writing tests. It does not actually
111 # install travis but rather builds a minimal vm with only the services
112 # available under a travis build to aid in test debugging (via `nosetests`)
114 # $ vagrant up travis
115 # $ vagrant ssh travis
116 # vagrant@travis$ cd src/reddit/r2 && nosetests
117 config.vm.define "travis", autostart: false do |travis|
118 travis.vm.hostname = "travis"
120 plugin_string = plugins.join(" ")
121 travis.vm.provision "shell", inline: <<-SCRIPT
122 if [ ! -f /var/local/reddit_installed ]; then
123 echo "running install script"
124 cd /home/#{vagrant_user}/src/reddit
125 ./install/travis.sh vagrant
126 touch /var/local/reddit_installed
128 echo "install script already run"
133 # NB: this is the primary VM. To build run
135 # [though 'vagrant up default' will also work, the 'default' is redudnant]
136 # Once built, avahi-daemon should guarantee the instance will be accessible
137 # from https://reddit.local/
138 config.vm.define "default", primary: true do |redditlocal|
139 redditlocal.vm.hostname = hostname
140 # host-only network interface
141 redditlocal.vm.network "private_network", ip: guest_ip
143 # rabbitmq web interface
144 config.vm.network "forwarded_port", guest: 15672, host: 15672
147 plugin_string = plugins.join(" ")
148 redditlocal.vm.provision "shell", inline: <<-SCRIPT
149 if [ ! -f /var/local/reddit_installed ]; then
150 echo "running install script"
151 cd /home/#{vagrant_user}/src/reddit
152 REDDIT_PLUGINS="#{plugin_string}" REDDIT_DOMAIN="#{hostname}" ./install/reddit.sh
153 touch /var/local/reddit_installed
155 echo "install script already run"
159 # set up private code
160 if File.exist?("#{code_share_host_path}/private/vagrant_setup.sh")
161 redditlocal.vm.provision "shell",
162 path: "#{code_share_host_path}/private/vagrant_setup.sh",
167 redditlocal.vm.provision "shell", inline: <<-SCRIPT
168 if [ ! -f /var/local/test_data_injected ]; then
169 cd /home/#{vagrant_user}/src/reddit
170 sudo -u #{vagrant_user} reddit-run scripts/inject_test_data.py -c 'inject_test_data()'
171 touch /var/local/test_data_injected
173 echo "inject test data already run"
176 # HACK: stop and start everything (otherwise sometimes there's an issue with
177 # ports being in use?)
183 redditlocal.vm.provision "shell", inline: <<-SCRIPT
184 if [ ! -f /var/local/additional_setup ]; then
185 apt-get install -y ipython avahi-daemon
186 touch /var/local/additional_setup
188 echo "additional setup already run"
192 # DONE: let this run whenever provision is run so that the user can see
194 redditlocal.vm.provision "shell", inline: <<-SCRIPT
195 cd /home/#{vagrant_user}/src/reddit
196 REDDIT_DOMAIN="#{hostname}" ./install/done.sh