Skip to content

Commit 69698a9

Browse files
committed
Add Travis-CI integration.
The only way to test travis is to deploy to master with a `.travis.yml` file and wait for travis-ci to pick up the change. To do some pre-testing here, the `Vagrantfile` has been split into two distinct machines: * `default` is, as before, the full reddit build (we have an opportunity to rename this) * `travis` is a minimal install with only the packages and services required to run `nosetests` against the codebase. It tries to mimic what will happen when we try to build this on travis-ci's workers. As part of this addition, I've moved `install-reddit.sh` to `install/reddit.sh` and populated that `install` folder with common scripts used for both `default` and `travis` builds.
1 parent 817c1c6 commit 69698a9

15 files changed

+1443
-1003
lines changed

.travis.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
sudo: required
2+
dist: trusty
3+
4+
language: python
5+
6+
python:
7+
- "2.7"
8+
9+
virtualenv:
10+
system_site_packages: true
11+
12+
services:
13+
- postgres
14+
- memcached
15+
- rabbitmq
16+
17+
install:
18+
- sudo install/travis.sh travis .
19+
20+
before_script:
21+
- install/setup_rabbitmq.sh
22+
- install/setup_postgres.sh
23+
- install/setup_cassandra.sh
24+
25+
script:
26+
- cd r2 && nosetests

Vagrantfile

+94-50
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525
# each plugin directory is that "reddit-plugin-NAME" should be in the directory
2626
# {ROOTDIR}/NAME.
2727
#
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.
35+
#
2836
# To start your vagrant box simply enter `vagrant up` from {ROOTDIR}/reddit.
2937
# You can then ssh into it with `vagrant ssh`.
3038
#
@@ -49,7 +57,7 @@ overlay_mount = "/home/#{vagrant_user}/src"
4957
overlay_lower = code_share_guest_path
5058
overlay_upper = "/home/#{vagrant_user}/.overlay"
5159

52-
# vm config
60+
# "default" vm config
5361
guest_ip = "192.168.56.111"
5462
guest_mem = "4096"
5563
guest_swap = "4096"
@@ -62,11 +70,6 @@ Vagrant.configure(2) do |config|
6270
config.vm.box_download_checksum = "0975e1a73226563ec7791c9b2fd114a57e918e401f82f4778a44e43040e39609"
6371
config.vm.box_download_checksum_type = "sha256"
6472

65-
config.vm.hostname = hostname
66-
67-
# host-only network interface
68-
config.vm.network "private_network", ip: guest_ip
69-
7073
# mount the host shared folder
7174
config.vm.synced_folder code_share_host_path, code_share_guest_path, mount_options: ["ro"]
7275

@@ -88,7 +91,7 @@ Vagrant.configure(2) do |config|
8891
fi
8992
SCRIPT
9093

91-
# setup the overlay filesystem
94+
# set up the overlay filesystem
9295
config.vm.provision "shell", inline: <<-SCRIPT
9396
if [ ! -d #{overlay_mount} ]; then
9497
echo "creating overlay mount directory #{overlay_mount}"
@@ -104,49 +107,90 @@ Vagrant.configure(2) do |config|
104107
mount -t overlayfs overlayfs -o lowerdir=#{overlay_lower},upperdir=#{overlay_upper} #{overlay_mount}
105108
SCRIPT
106109

107-
# run install script
108-
plugin_string = plugins.join(" ")
109-
config.vm.provision "shell", inline: <<-SCRIPT
110-
if [ ! -f /var/local/reddit_installed ]; then
111-
echo "running install script"
112-
cd /home/#{vagrant_user}/src/reddit
113-
REDDIT_PLUGINS="#{plugin_string}" REDDIT_DOMAIN="#{hostname}" ./install-reddit.sh
114-
touch /var/local/reddit_installed
115-
else
116-
echo "install script already run"
117-
fi
118-
SCRIPT
119-
120-
# setup private code
121-
if File.exist?("#{code_share_host_path}/private/vagrant_setup.sh")
122-
config.vm.provision "shell",
123-
path: "#{code_share_host_path}/private/vagrant_setup.sh",
124-
args: [vagrant_user]
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`)
113+
# To use:
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"
119+
# run install script
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
127+
else
128+
echo "install script already run"
129+
fi
130+
SCRIPT
125131
end
126132

127-
# inject test data
128-
config.vm.provision "shell", inline: <<-SCRIPT
129-
if [ ! -f /var/local/test_data_injected ]; then
130-
cd /home/#{vagrant_user}/src/reddit
131-
sudo -u #{vagrant_user} reddit-run scripts/inject_test_data.py -c 'inject_test_data()'
132-
touch /var/local/test_data_injected
133-
else
134-
echo "inject test data already run"
135-
fi
136-
137-
# HACK: stop and start everything (otherwise sometimes there's an issue with
138-
# ports being in use?)
139-
reddit-stop
140-
reddit-start
141-
SCRIPT
142-
143-
# additional setup
144-
config.vm.provision "shell", inline: <<-SCRIPT
145-
if [ ! -f /var/local/additional_setup ]; then
146-
apt-get install -y ipython avahi-daemon
147-
touch /var/local/additional_setup
148-
else
149-
echo "additional setup already run"
150-
fi
151-
SCRIPT
133+
# NB: this is the primary VM. To build run
134+
# $ vagrant up
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
142+
143+
# run install script
144+
plugin_string = plugins.join(" ")
145+
redditlocal.vm.provision "shell", inline: <<-SCRIPT
146+
if [ ! -f /var/local/reddit_installed ]; then
147+
echo "running install script"
148+
cd /home/#{vagrant_user}/src/reddit
149+
REDDIT_PLUGINS="#{plugin_string}" REDDIT_DOMAIN="#{hostname}" ./install/reddit.sh
150+
touch /var/local/reddit_installed
151+
else
152+
echo "install script already run"
153+
fi
154+
SCRIPT
155+
156+
# set up private code
157+
if File.exist?("#{code_share_host_path}/private/vagrant_setup.sh")
158+
redditlocal.vm.provision "shell",
159+
path: "#{code_share_host_path}/private/vagrant_setup.sh",
160+
args: [vagrant_user]
161+
end
162+
163+
# inject test data
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
169+
else
170+
echo "inject test data already run"
171+
fi
172+
173+
# HACK: stop and start everything (otherwise sometimes there's an issue with
174+
# ports being in use?)
175+
reddit-stop
176+
reddit-start
177+
SCRIPT
178+
179+
# additional setup
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
184+
else
185+
echo "additional setup already run"
186+
fi
187+
SCRIPT
188+
189+
# DONE: let this run whenever provision is run so that the user can see
190+
# how to proceed.
191+
redditlocal.vm.provision "shell", inline: <<-SCRIPT
192+
cd /home/#{vagrant_user}/src/reddit
193+
REDDIT_DOMAIN="#{hostname}" ./install/done.sh
194+
SCRIPT
195+
end
152196
end

0 commit comments

Comments
 (0)