diff --git a/Vagrantfile b/Vagrantfile index 6f20288..cde1a87 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,50 +1,24 @@ # -*- mode: ruby -*- # vi: set ft=ruby : -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. - - username = "ubuntu" +Vagrant.configure("2") do |config| local_app_dir = "/Users/ted/dc/documentcloud/" - app_root = "/home/#{username}/documentcloud" + app_root = "/home/vagrant/documentcloud" rails_env = "development" - # Every Vagrant virtual environment requires a box to build off of. - config.vm.box = "documentcloud" - config.ssh.username = username + config.vm.box = "ubuntu/trusty64" + config.vm.network :private_network, ip: "192.168.33.10" + config.vm.synced_folder local_app_dir, app_root - # 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" - - # 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 - # any other machines on the same network, but cannot be accessed (through this - # network interface) by any external networks. - config.vm.network :hostonly, "192.168.33.10" - - # Assign this VM to a bridged network, allowing you to connect directly to a - # network using the host's network device. This makes the VM appear as another - # physical device on your network. - # config.vm.network :bridged - - # Forward a port from the guest to the host, which allows for outside - # computers to access the VM, whereas host only networking does not. - # config.vm.forward_port 80, 8080 - - # Share an additional folder to the guest VM. The first argument is - # an identifier, the second is the path on the guest to mount the - # folder, and the third is the path on the host to the actual folder. - # config.vm.share_folder "v-data", "/vagrant_data", "../data" - config.vm.share_folder "app_root", app_root, local_app_dir + config.vm.provider "virtualbox" do |v| + v.memory = 2048 + end script = <<-SHELL - export USERNAME=#{username}; + export USERNAME=vagrant; export RAILS_ENV=#{rails_env}; sh /vagrant/scripts/base.sh; SHELL - config.vm.provision :shell, :inline => script + config.vm.provision :shell, inline: script end diff --git a/scripts/app.sh b/scripts/app.sh index cb00130..2176df1 100644 --- a/scripts/app.sh +++ b/scripts/app.sh @@ -1,6 +1,6 @@ # Ensure nginx is installed -test -e /usr/local/nginx || /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' +test -e /usr/local/nginx || (gem install passenger && /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' grep -q "$LINE" .bashrc 2>/dev/null || echo "$LINE" >> .bashrc @@ -10,10 +10,6 @@ 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 +cp /home/vagrant/documentcloud/config/server/files/nginx/nginx.init /etc/init.d/nginx update-rc.d nginx defaults /etc/init.d/nginx start diff --git a/scripts/base.sh b/scripts/base.sh index 25b928c..0a7fcbf 100755 --- a/scripts/base.sh +++ b/scripts/base.sh @@ -6,7 +6,7 @@ test $USERNAME || { echo "USERNAME has to be set" >&2; exit 1; } test $RAILS_ENV || { echo "USERNAME has to be set" >&2; exit 1; } # 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' +BASICS='git build-essential postgresql postgresql-contrib libpq-dev git sqlite3 libsqlite3-dev libpcre3-dev lzop libxml2-dev libxslt-dev libcurl4-gnutls-dev libitext-java ruby ruby-dev' echo $BASICS | xargs apt-get install -y DOCSPLIT_DEPS='graphicsmagick pdftk xpdf poppler-utils libreoffice libreoffice-java-common tesseract-ocr ghostscript' @@ -21,22 +21,22 @@ grep -q github .ssh/known_hosts 2>/dev/null || ssh-keyscan -t rsa github.com > . # Install gems cd documentcloud -git checkout --track -b bundler origin/bundler -git pull +#git checkout --track -b bundler origin/bundler +#git pull gem install bundler --no-ri --no-rdoc bundle install -git checkout master -git pull +#git checkout master +#git pull # Ensure that the secrets directory exists -test -e secrets || { cp -r config/server/secrets ./secrets; } +test -e secrets || { cp -r config/server/files/secrets ./secrets; } # disable ssh dns to avoid long pause before login grep -q '^UseDNS no' /etc/ssh/sshd_config || echo 'UseDNS no' >> /etc/ssh/sshd_config /etc/init.d/ssh reload # replace annoying motd with new one -rm /etc/motd +rm -f /etc/motd cat >/etc/motd <<'EOF' ______ _ _____ _ _ diff --git a/scripts/configure_nginx.rb b/scripts/configure_nginx.rb index d8a5f7b..ca05456 100644 --- a/scripts/configure_nginx.rb +++ b/scripts/configure_nginx.rb @@ -1,10 +1,10 @@ require 'fileutils' require 'erb' =begin - cp config/server/nginx/nginx.conf /usr/local/nginx/conf/ - cp config/server/nginx/$RAILS_ENVIRONMENT.conf /usr/local/nginx/conf/sites-enabled/ + cp config/server/files/nginx/nginx.conf /usr/local/nginx/conf/ + cp config/server/files/nginx/$RAILS_ENVIRONMENT.conf /usr/local/nginx/conf/sites-enabled/ # TODO nginx configuration is not rock solid - cp config/server/nginx/nginx.init /etc/init.d/nginx + cp config/server/files/nginx/nginx.init /etc/init.d/nginx update-rc.d nginx defaults =end @@ -18,8 +18,8 @@ end File.open "/usr/local/nginx/conf/sites-enabled/#{rails_env}.conf", "w" do |site_conf| - certpath = "/home/ubuntu/documentcloud/secrets/keys/dev.dcloud.org.crt" - keypath = "/home/ubuntu/documentcloud/secrets/keys/dev.dcloud.org.key" + certpath = "/home/vagrant/documentcloud/secrets/keys/dev.dcloud.org.crt" + keypath = "/home/vagrant/documentcloud/secrets/keys/dev.dcloud.org.key" site_conf_template = File.open(File.join(here, "erb", "site.conf.erb")).read site_conf.puts ERB.new(site_conf_template).result(binding) @@ -27,7 +27,7 @@ File.open "/usr/local/nginx/conf/documentcloud.conf", "w" do |dc_conf| server_name = "dev.dcloud.org" - app_root = "/home/ubuntu/documentcloud/public" + app_root = "/home/vagrant/documentcloud/public" dc_conf_template = File.open(File.join(here, "erb", "documentcloud.conf.erb")).read dc_conf.puts ERB.new(dc_conf_template).result(binding) diff --git a/scripts/db.sh b/scripts/db.sh index bb31922..dabc926 100644 --- a/scripts/db.sh +++ b/scripts/db.sh @@ -1,13 +1,13 @@ # verify that postgres is loaded properly -test $USERNAME || { USERNAME=ubuntu; } +test $USERNAME || { USERNAME=vagrant; } -test -e /etc/postgresql/9.1/main/pg_hba.conf || { echo "Can't find the PostgreSQL 9.1 Client Authentication Configuration File (/etc/postgresql/9.1/main/pg_hba.conf)" >&2; exit 1; } +test -e /etc/postgresql/9.3/main/pg_hba.conf || { echo "Can't find the PostgreSQL 9.3 Client Authentication Configuration File (/etc/postgresql/9.3/main/pg_hba.conf)" >&2; exit 1; } cd /home/$USERNAME/documentcloud # setup dummy postgres environment so that you can verify rails is working -cp config/server/postgres/pg_hba.conf /etc/postgresql/9.1/main/pg_hba.conf +cp config/server/files/postgres/pg_hba.conf /etc/postgresql/9.3/main/pg_hba.conf /etc/init.d/postgresql reload # verify that databases don't already exist @@ -27,7 +27,8 @@ sudo -u postgres createdb dcloud_analytics_$RAILS_ENV echo "CREATE EXTENSION hstore;" | sudo -u postgres psql dcloud_$RAILS_ENV # import development schema to dcloud_#{env} and analytics schema to dcloud_analytics_#{env} -sudo -u postgres psql -f db/development_structure.sql dcloud_$RAILS_ENV 2>&1|grep ERROR +#sudo -u postgres psql -f db/development_structure.sql dcloud_$RAILS_ENV 2>&1|grep ERROR +sudo -u postgres psql -f db/structure.sql dcloud_$RAILS_ENV 2>&1|grep ERROR sudo -u postgres psql -f db/analytics_structure.sql dcloud_analytics_$RAILS_ENV 2>&1|grep ERROR rake db:migrate diff --git a/scripts/erb/nginx.conf.erb b/scripts/erb/nginx.conf.erb index 33e76b7..022c701 100644 --- a/scripts/erb/nginx.conf.erb +++ b/scripts/erb/nginx.conf.erb @@ -10,7 +10,7 @@ events { http { passenger_root <%= passenger_root %>; - passenger_ruby /usr/bin/ruby1.8; + passenger_ruby /usr/bin/ruby; passenger_default_user www-data; passenger_pool_idle_time 0; passenger_max_pool_size 4;