Skip to content

Commit

Permalink
Specify plugins to be installed by default on Vagrant builds
Browse files Browse the repository at this point in the history
Plugins must meet the following requirements in order to be installed
on a Vagrant build:

1. Be listed in `plugins` in the Vagrantfile
2. Be cloned to the designated install directory
3. Adhere to plugin naming conventions

This applies to all open-source plugins.
  • Loading branch information
zeantsoi committed Aug 4, 2016
1 parent 5a27265 commit 05b24d4
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 33 deletions.
35 changes: 16 additions & 19 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,19 @@
# r2: {ROOTDIR}/reddit
#
# plugins:
# i18n: {ROOTDIR}/i18n
# about: {ROOTDIR}/about
# meatspace: {ROOTDIR}/meatspace
# liveupdate: {ROOTDIR}/liveupdate
# adzerk: {ROOTDIR}/adzerk
# donate: {ROOTDIR}/donate
# gold: {ROOTDIR}/gold
#
# private internal reddit plugin:
# liveupdate: {ROOTDIR}/liveupdate
# meatspace: {ROOTDIR}/meatspace
# private: {ROOTDIR}/private
#
# The plugins are all optional, but they will get cloned in the VM (and as a
# result be uneditable from the host) by the install script if their directory
# is missing but is included in `plugins` below. The general rule for naming
# each plugin directory is that "reddit-plugin-NAME" should be in the directory
# {ROOTDIR}/NAME.
# All plugins are optional. A plugin will only be installed if it is listed
# in `plugins` AND it is located in a directory that both follows the plugin
# naming convention and is correctly located on the host machine. The general
# rule for naming each plugin directory is that "reddit-plugin-NAME" should be
# in the directory {ROOTDIR}/NAME.
#
# This VagrantFile allows for the creation of two VMs:
# * default: the primary VM, with all services necessary to run reddit
Expand Down Expand Up @@ -52,7 +49,15 @@ this_path = File.absolute_path(__FILE__)
reddit_dir = File.expand_path("..", this_path)
code_share_host_path = File.expand_path("..", reddit_dir)
code_share_guest_path = "/media/reddit_code"
plugins = ["meatspace", "about", "liveupdate", "adzerk", "donate", "gold"]
plugins = [
"about",
"adzerk",
"donate",
"gold",
"liveupdate",
"meatspace",
"private",
]

# overlayfs directories
overlay_mount = "/home/#{vagrant_user}/src"
Expand Down Expand Up @@ -117,7 +122,6 @@ Vagrant.configure(2) do |config|
config.vm.define "travis", autostart: false do |travis|
travis.vm.hostname = "travis"
# run install script
plugin_string = plugins.join(" ")
travis.vm.provision "shell", inline: <<-SCRIPT
if [ ! -f /var/local/reddit_installed ]; then
echo "running install script"
Expand Down Expand Up @@ -156,13 +160,6 @@ Vagrant.configure(2) do |config|
fi
SCRIPT

# set up private code
if File.exist?("#{code_share_host_path}/private/vagrant_setup.sh")
redditlocal.vm.provision "shell",
path: "#{code_share_host_path}/private/vagrant_setup.sh",
args: [vagrant_user]
end

# inject test data
redditlocal.vm.provision "shell", inline: <<-SCRIPT
if [ ! -f /var/local/test_data_injected ]; then
Expand Down
5 changes: 3 additions & 2 deletions install/install.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ REDDIT_SRC=${REDDIT_SRC:-$REDDIT_HOME/src}
# domains. an IP address will suffice if nothing else is available.
REDDIT_DOMAIN=${REDDIT_DOMAIN:-reddit.local}

#The plugins to clone and register in the ini file
REDDIT_PLUGINS=${REDDIT_PLUGINS:-meatspace about liveupdate}
# the plugins to install if they adhere to plugin naming and location
# conventions on the host
REDDIT_PLUGINS=${REDDIT_PLUGINS:-about adzerk donate gold liveupdate meatspace private}

# aptitude configuration
APTITUDE_OPTIONS=${APTITUDE_OPTIONS:-"-y"}
Expand Down
49 changes: 37 additions & 12 deletions install/reddit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ if [[ "2000000" -gt $(awk '/MemTotal/{print $2}' /proc/meminfo) ]]; then
fi
fi

REDDIT_AVAILABLE_PLUGINS=""
for plugin in $REDDIT_PLUGINS; do
if [ -d $REDDIT_SRC/$plugin ]; then
if [[ -z "$REDDIT_PLUGINS" ]]; then
REDDIT_AVAILABLE_PLUGINS+="$plugin"
else
REDDIT_AVAILABLE_PLUGINS+=" $plugin"
fi
echo "plugin $plugin found"
else
echo "plugin $plugin not found"
fi
done

###############################################################################
# Install prerequisites
###############################################################################
Expand All @@ -102,6 +116,12 @@ if [ ! -d $REDDIT_SRC ]; then
chown $REDDIT_USER $REDDIT_SRC
fi

function copy_upstart {
if [ -d ${1}/upstart ]; then
cp ${1}/upstart/* /etc/init/
fi
}

function clone_reddit_repo {
local destination=$REDDIT_SRC/${1}
local repository_url=https://github.com/${2}.git
Expand All @@ -110,13 +130,7 @@ function clone_reddit_repo {
sudo -u $REDDIT_USER -H git clone $repository_url $destination
fi

if [ -d $destination/upstart ]; then
cp $destination/upstart/* /etc/init/
fi
}

function clone_reddit_plugin_repo {
clone_reddit_repo $1 reddit/reddit-plugin-$1
copy_upstart $destination
}

function clone_reddit_service_repo {
Expand All @@ -125,9 +139,6 @@ function clone_reddit_service_repo {

clone_reddit_repo reddit reddit/reddit
clone_reddit_repo i18n reddit/reddit-i18n
for plugin in $REDDIT_PLUGINS; do
clone_reddit_plugin_repo $plugin
done
clone_reddit_service_repo websockets
clone_reddit_service_repo activity

Expand Down Expand Up @@ -159,7 +170,8 @@ function install_reddit_repo {

install_reddit_repo reddit/r2
install_reddit_repo i18n
for plugin in $REDDIT_PLUGINS; do
for plugin in $REDDIT_AVAILABLE_PLUGINS; do
copy_upstart $REDDIT_SRC/$plugin
install_reddit_repo $plugin
done
install_reddit_repo websockets
Expand All @@ -174,7 +186,7 @@ sudo -u $REDDIT_USER make -C $REDDIT_SRC/i18n clean all
pushd $REDDIT_SRC/reddit/r2
sudo -u $REDDIT_USER make clean pyx

plugin_str=$(echo -n "$REDDIT_PLUGINS" | tr " " ,)
plugin_str=$(echo -n "$REDDIT_AVAILABLE_PLUGINS" | tr " " ,)
if [ ! -f development.update ]; then
cat > development.update <<DEVELOPMENT
# after editing this file, run "make ini" to
Expand Down Expand Up @@ -622,6 +634,19 @@ PGPASSWORD=password
CRON
fi

###############################################################################
# Complete plugin setup, if setup.sh exists
###############################################################################
for plugin in $REDDIT_AVAILABLE_PLUGINS; do
if [ -x $REDDIT_SRC/$plugin/setup.sh ]; then
echo "Found setup.sh for $plugin; running setup script"
$REDDIT_SRC/$plugin/setup.sh $REDDIT_SRC $REDDIT_USER
fi
done

###############################################################################
# Finished with install script
###############################################################################
# print this out here. if vagrant's involved, it's gonna do more steps
# afterwards and then re-run this script but that's ok.
$RUNDIR/done.sh

0 comments on commit 05b24d4

Please sign in to comment.