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/20160122/trusty-server-cloudimg-amd64-vagrant-disk1.box"
72 config.vm.box_download_checksum = "09b0b9b382b918a4172e4eb77b0ad869dc5fd21cf119c935eabc202b44c1b8d7"
73 config.vm.box_download_checksum_type = "sha256"
75 # mount the host shared folder
76 config.vm.synced_folder code_share_host_path, code_share_guest_path, mount_options: ["ro"]
78 config.vm.provider "virtualbox" do |vb|
82 # ubuntu cloud image has no swapfile by default, set one up
83 config.vm.provision "shell", inline: <<-SCRIPT
84 if ! grep -q swapfile /etc/fstab; then
85 echo 'swapfile not found. Adding swapfile.'
86 fallocate -l #{guest_swap}M /swapfile
90 echo '/swapfile none swap defaults 0 0' >> /etc/fstab
92 echo 'swapfile found. No changes made.'
96 # set up the overlay filesystem
97 config.vm.provision "shell", inline: <<-SCRIPT
98 if [ ! -d #{overlay_mount} ]; then
99 echo "creating overlay mount directory #{overlay_mount}"
100 sudo -u #{vagrant_user} mkdir #{overlay_mount}
103 if [ ! -d #{overlay_upper} ]; then
104 echo "creating overlay upper directory #{overlay_upper}"
105 sudo -u #{vagrant_user} mkdir #{overlay_upper}
108 echo "mounting overlayfs (lower: #{overlay_lower}, upper: #{overlay_upper}, mount: #{overlay_mount})"
109 mount -t overlayfs overlayfs -o lowerdir=#{overlay_lower},upperdir=#{overlay_upper} #{overlay_mount}
112 # NOTE: This VM exists solely to assist in writing tests. It does not actually
113 # install travis but rather builds a minimal vm with only the services
114 # available under a travis build to aid in test debugging (via `nosetests`)
116 # $ vagrant up travis
117 # $ vagrant ssh travis
118 # vagrant@travis$ cd src/reddit/r2 && nosetests
119 config.vm.define "travis", autostart: false do |travis|
120 travis.vm.hostname = "travis"
122 plugin_string = plugins.join(" ")
123 travis.vm.provision "shell", inline: <<-SCRIPT
124 if [ ! -f /var/local/reddit_installed ]; then
125 echo "running install script"
126 cd /home/#{vagrant_user}/src/reddit
127 ./install/travis.sh vagrant
128 touch /var/local/reddit_installed
130 echo "install script already run"
135 # NB: this is the primary VM. To build run
137 # [though 'vagrant up default' will also work, the 'default' is redudnant]
138 # Once built, avahi-daemon should guarantee the instance will be accessible
139 # from https://reddit.local/
140 config.vm.define "default", primary: true do |redditlocal|
141 redditlocal.vm.hostname = hostname
142 # host-only network interface
143 redditlocal.vm.network "private_network", ip: guest_ip
145 # rabbitmq web interface
146 config.vm.network "forwarded_port", guest: 15672, host: 15672
149 plugin_string = plugins.join(" ")
150 redditlocal.vm.provision "shell", inline: <<-SCRIPT
151 if [ ! -f /var/local/reddit_installed ]; then
152 echo "running install script"
153 cd /home/#{vagrant_user}/src/reddit
154 REDDIT_PLUGINS="#{plugin_string}" REDDIT_DOMAIN="#{hostname}" ./install/reddit.sh
155 touch /var/local/reddit_installed
157 echo "install script already run"
161 # set up private code
162 if File.exist?("#{code_share_host_path}/private/vagrant_setup.sh")
163 redditlocal.vm.provision "shell",
164 path: "#{code_share_host_path}/private/vagrant_setup.sh",
169 redditlocal.vm.provision "shell", inline: <<-SCRIPT
170 if [ ! -f /var/local/test_data_injected ]; then
171 cd /home/#{vagrant_user}/src/reddit
172 sudo -u #{vagrant_user} reddit-run scripts/inject_test_data.py -c 'inject_test_data()'
173 touch /var/local/test_data_injected
175 echo "inject test data already run"
178 # HACK: stop and start everything (otherwise sometimes there's an issue with
179 # ports being in use?)
185 redditlocal.vm.provision "shell", inline: <<-SCRIPT
186 if [ ! -f /var/local/additional_setup ]; then
187 apt-get install -y ipython avahi-daemon
188 touch /var/local/additional_setup
190 echo "additional setup already run"
194 # DONE: let this run whenever provision is run so that the user can see
196 redditlocal.vm.provision "shell", inline: <<-SCRIPT
197 cd /home/#{vagrant_user}/src/reddit
198 REDDIT_DOMAIN="#{hostname}" ./install/done.sh