Skip to content
This repository was archived by the owner on Aug 19, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.DS_STORE
*.box
.vagrant
.bashrc
.bashrc
scripts/*.output
scripts/*.fail
7 changes: 6 additions & 1 deletion ReadMe.markdown
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# DocumentCloud Vagrant VM

These Vagrant scripts provide a(n ALPHA-STAGE) development environment for the DocumentCloud platform. [DocumentCloud](http://www.documentcloud.org) itself is a web based platform for uploading, analyzing, annotating and publishing primary source material.
These Vagrant scripts provide a(n ALPHA-STAGE) development environment for the DocumentCloud platform. [DocumentCloud](http://www.documentcloud.org) itself is a web based platform for uploading, analyzing, annotating and publishing primary source material.

Vagrant will execute the [runner script](documentcloud-vagrant/blob/master/scripts/runner) script to provision the box.

The script has several variables that can be modified at the top, such as the user login and password to create.

10 changes: 6 additions & 4 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ Vagrant::Config.run do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.


# This assumes the following directory layout:
username = "ubuntu"
local_app_dir = "/Users/ted/dc/documentcloud/"
local_app_dir = "#{ File.dirname(__FILE__) }/../documentcloud/"

app_root = "/home/#{username}/documentcloud"
rails_env = "development"

Expand All @@ -17,7 +19,7 @@ Vagrant::Config.run do |config|

# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
# config.vm.box_url = "http://domain.com/path/to/above.box"
config.vm.box_url = "http://s3.documentcloud.org/documentcloud.2012.10.15.box"

# Assign this VM to a host-only network IP, allowing you to access it
# via the IP. Host-only networks can talk to the host machine as well as
Expand All @@ -43,7 +45,7 @@ Vagrant::Config.run do |config|
script = <<-SHELL
export USERNAME=#{username};
export RAILS_ENV=#{rails_env};
sh /vagrant/scripts/base.sh;
ruby /vagrant/scripts/runner
SHELL

config.vm.provision :shell, :inline => script
Expand Down
50 changes: 0 additions & 50 deletions scripts/base.sh

This file was deleted.

5 changes: 5 additions & 0 deletions scripts/clone_documentcloud
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

cd /home/$USERNAME

git clone https://github.com/documentcloud/documentcloud.git

Empty file removed scripts/cloudcrowd_node.sh
Empty file.
1 change: 0 additions & 1 deletion scripts/cloudcrowd_server.sh

This file was deleted.

3 changes: 3 additions & 0 deletions scripts/configure_nginx.rb → scripts/configure_nginx
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/ruby

require 'fileutils'
require 'erb'
=begin
Expand Down Expand Up @@ -32,3 +34,4 @@
dc_conf_template = File.open(File.join(here, "erb", "documentcloud.conf.erb")).read
dc_conf.puts ERB.new(dc_conf_template).result(binding)
end

File renamed without changes.
5 changes: 5 additions & 0 deletions scripts/copy_secrets
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

cd /home/$USERNAME/documentcloud

# Ensure that the secrets directory exists
test -e secrets || { cp -r config/server/secrets ./secrets; }
8 changes: 8 additions & 0 deletions scripts/github_keys
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

cd /home/$USERNAME

# approve github ssh host key
grep -q github .ssh/known_hosts 2>/dev/null || ssh-keyscan -t rsa github.com > .ssh/known_hosts



9 changes: 9 additions & 0 deletions scripts/install_dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

apt-get update -q

# Set up system dependencies
BASICS='git build-essential postgresql libpq-dev git sqlite3 libsqlite3-dev libpcre3-dev lzop libxml2-dev libxslt-dev libcurl4-gnutls-dev libitext-java ruby1.8 rubygems'
echo $BASICS | xargs apt-get install -q -y

DOCSPLIT_DEPS='graphicsmagick pdftk xpdf poppler-utils libreoffice libreoffice-java-common tesseract-ocr ghostscript'
echo $DOCSPLIT_DEPS | xargs apt-get install -q -y
16 changes: 16 additions & 0 deletions scripts/install_gems
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

cd /home/$USERNAME/documentcloud

# Install gems
git branch | grep -q bundler
if [ "$?"=="0" ]; then
git checkout bundler
else
git checkout --track -b bundler origin/bundler
fi

git pull
sudo gem install bundler --no-ri --no-rdoc
sudo bundle install

git checkout master
9 changes: 5 additions & 4 deletions scripts/app.sh → scripts/install_nginx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Ensure nginx is installed
test -e /usr/local/nginx || /usr/local/bin/passenger-install-nginx-module --auto --auto-download \
/usr/local/bin/passenger-install-nginx-module --auto --auto-download \
--prefix /usr/local/nginx --extra-configure-flags='--with-http_gzip_static_module --with-http_ssl_module --with-http_stub_status_module'

LINE='export PATH=$PATH:/usr/local/nginx/sbin'
Expand All @@ -8,12 +8,13 @@ grep -q "$LINE" .bashrc 2>/dev/null || echo "$LINE" >> .bashrc
mkdir -p /usr/local/nginx/conf/sites-enabled /var/log/nginx/
mkdir -p /var/log/nginx

ruby /vagrant/scripts/configure_nginx.rb

cd /home/ubuntu/documentcloud

test -e secrets/keys || { cp -r config/server/keys secrets/ ; }

cp config/server/nginx/nginx.init /etc/init.d/nginx

update-rc.d nginx defaults
/etc/init.d/nginx start



5 changes: 0 additions & 5 deletions scripts/keygen.sh

This file was deleted.

13 changes: 13 additions & 0 deletions scripts/pretty_motd
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# replace annoying motd with new one
rm /etc/motd
cat >/etc/motd <<'EOF'

______ _ _____ _ _
| _ \ | | / __ \ | | |
| | | |___ ___ _ _ _ __ ___ ___ _ __ | |_| / \/ | ___ _ _ __| |
| | | / _ \ / __| | | | '_ ` _ \ / _ \ '_ \| __| | | |/ _ \| | | |/ _` |
| |/ / (_) | (__| |_| | | | | | | __/ | | | |_| \__/\ | (_) | |_| | (_| |
|___/ \___/ \___|\__,_|_| |_| |_|\___|_| |_|\__|\____/_|\___/ \__,_|\__,_|

EOF
uname -a | tee -a /etc/motd
54 changes: 54 additions & 0 deletions scripts/provision
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env ruby

DIR='/home/ubuntu/documentcloud/'

require 'optparse'

options = { :login=> 'testing@documentcloud.org', :password=> 'testing42' }

OptionParser.new do |opts|
opts.banner = "Usage: #{$0} [options]"

opts.on("-l", '--login=LOGIN_EMAIL',"User Login to create") do |l|
options[:login] = l
end
opts.on("-p", '--password=PASSWORD', "Password") do |l|
options[:password] = l
end
end.parse!

Dir.chdir DIR

require "./config/environment"
require 'sqlite3'
require 'cloud-crowd'

organization = Organization.find_by_slug( 'test' )
if organization.nil?
organization = Organization.create!({:name=>'Testing',:slug=>'test'})
puts "Created Testing organization, id: #{organization.id}"
end

account = Account.find_by_email( options[:login] )
if account.nil?
account=Account.create!({:organization=>organization,:first_name=>'Testing',:last_name=>'Account', :email=> options[:login], \
:hashed_password=>BCrypt::Password.create( options[:password] ), :role=>Account::ADMINISTRATOR })
puts "Created Testing account. Login: #{options[:login]}, pw: #{options[:password]}, id: #{account.id}"
end

# the cloud crowd test server will need this
db = SQLite3::Database.new( "#{DIR}cloud_crowd.db" )
exists = db.get_first_value( "SELECT name FROM sqlite_master WHERE type='table' AND name='schema_migrations'" )
if exists.nil?
puts "Creating schema_migrations table in #{DIR}cloud_crowd.db and running migrations"
db.execute( "CREATE TABLE schema_migrations (version varchar(255) NOT NULL)" )
end
db.close


CloudCrowd.configure("config/cloud_crowd/development/config.yml")
require 'cloud_crowd/models'
CloudCrowd.configure_database("config/cloud_crowd/development/database.yml", false)
require 'cloud_crowd/schema.rb'


68 changes: 68 additions & 0 deletions scripts/runner
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env ruby

require File.dirname(__FILE__) + '/script'

# This is intended to be ran as part of Vagrant provisioning.
# It will use the Script class (in script.rb)
# to execute the scripts below both in parallel and sequence depending
# on the scripts importance to the following ones.
#
# The end result should configure a Vagrant instance with a
# fully functional DocumentCloud server
#
# The scripts are located in the scripts directory, and can be re-ran if needed
# from there. We've attempted to make them as re-entrant as possible
# but they may not be fully there yet.
#


ENV['RAILS_ENV'] = 'development'
LOGIN = 'test@example.com'
PASSWORD = 'documentcloud'
Script.user = ENV['USERNAME'] = 'ubuntu'
Script.directory = '/vagrant/scripts'
REPOSITORY = 'https://github.com/documentcloud/documentcloud.git'

Script[ :update ].run_weekly :as_root=>true, :wait=>true, :msg=>'Will take >10 minutes'
Script[ :install_dependencies ].run_once :as_root=>true, :wait=>true, :msg=>'Will take >5 minutes'

Script[ :speed_up_ssh ].run_once :as_root=>true
Script[ :pretty_motd ].run_once :as_root=>true
Script[ :github_keys ].run_once
Script[ :copy_secrets ].run_once

Script.wait_for_completion

unless File.directory?( 'documentcloud' )
Script.output do
STDERR.puts "documentcloud directory doesn't exist."
STDERR.puts "Checking it out from #{REPOSITORY}"
Script[:clone_documentcloud].run :wait=>true, :args=>{:repo=>REPOSITORY}
end
end

Script[:install_gems ].run_once :wait=>true

Script[:install_nginx ].run_once :wait=>true, :as_root=>true

Script[:configure_nginx ].run_once :as_root=>true,:shell=>'/usr/bin/ruby'
Script[:configure_postgresql ].run_once :as_root=>true

Script.wait_for_completion

Script[:provision ].run_once :shell=>'/usr/bin/ruby', :wait=>true, :args=>{ :login=> LOGIN, :password=>PASSWORD }
Script[:start_up_everything ].run
Script.wait_for_completion

ip = `/sbin/ifconfig eth1 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`

Script.output do
puts <<-EOS
####################################################################
# All Done.
# A fully configured DocumentCloud should be running on vagrant at
# http://#{ip}
# Log in as: #{LOGIN} with password: #{PASSWORD}
####################################################################
EOS
end
Loading