Skip to content

decc/twenty-fifty-wiki

Repository files navigation

2050 COSTS WIKI

This is the code used to collect cost data as part of the DECC 2050 Pathways Project. 

It is a wiki, with some extra models to collect and plot costs.

It is a bit of a bodge.

It is a ruby on rails app.

RUNNING LOCALY

Depends on: 
  Ruby 1.9.2
  sqlite3 # for development
  Mysql # for production, other databases with tinkering

Setup (from inside the app directory):
  gem install bundler
  gem install foreman
  bundle
  bundle exec rake db:migrate RAILS_ENV=development
  bundle exec rake db:migrate RAILS_ENV=production

May need to adjust the config.action_mailer settings in config/environments/production.rb

If updating from earlier version, may need to run:

  ./script/rails generate delayed_job:upgrade
  bundle exec rake db:migrate RAILS_ENV=development
  bundle exec rake db:migrate RAILS_ENV=production

Optionally, to enable notification of changed pages, add this to a crontab:
'ChangeNotifications.send_all_change_notifications'

To make the registration captcha work, need to register with http://www.google.com/recaptcha then set two environment variables: 
    
    export RECAPTCHA_PUBLIC_KEY  = '6Lc6BAAAAAAAAChqRbQZcn_yyyyyyyyyyyyyyyyy'
    export RECAPTCHA_PRIVATE_KEY = '6Lc6BAAAAAAAAKN3DRm6VA_xxxxxxxxxxxxxxxxx'

These environment variables could also be placed in the config/development.env or config/production.env files if needed.

To start (from inside the app directory):
  foreman start --env config/development.env # or --env config/production.env

Then go to http://0.0.0.0:5100

Then register a new email address.

Then you will need to manually make this first account an administrator:
    
  ./script/rails console development # or ./script/rails console production
  u = User.find_by_email 'the email address you used for registration'
  u.activated = true
  u.administrator = true
  u.save
  exit

You can then use that account to log onto the wiki and create your first page.

Because the account is an administrator, you can use it to activate later accounts that are registered.

To make other users administrators, follow the steps above for the first account.

RUNNING ON HEROKU

Need an account with http://www.heroku.com

NB: Get is running locally using the instructions above first.

Depends on: 
  Ruby 1.9.2 
  Git

Setup:
  gem install heroku
  # if you don't already have a ssh key, then:
  # ssh-keygen -t rsa
  # if you don't already have a heroku account, register, then:
  # heroku keys:add
  # Now setup the heroku stack
  heroku create --stack cedar
  heroku addons:add sendgrid:free
  heroku addons:add websolr
  heroku addons:add cron:daily
  heroku addons:add custom_domains
  heroku addons:add pgbackups:basic
  # Now transfer the code up to heroku
  git push heroku master
  # Now setup the database
  heroku run rake db:migrate
  # Now start the app running
  heroku ps:scale web=1 worker=1
  
Other useful commands:
   heroku run rake sunspot:reindex # if you upload a new database, this will get the search in sync
   heroku domains:add 2050-wiki.greenonblack.com # to setup with a new url
   heroku info
   pgbackups:capture # Make a backup of the database
  
RUNNING ON EC2

#!/bin/bash

# This is a bootstrap file to get everything setup on an Ubuntu system
# Such as an appropriate amazon ec2 instance
# I strongly recommend that you DO NOT RUN THIS FILE on a system that
# you are already using for other purposes. Just use it as inspiration
# for what you may need to install.

# For instance, you may have created an Amazon ec2 instance like so:
# ec2-run-instances ami-fb9ca98f --instance-type t1.micro --region eu-west-1 --key deccaws

echo "Update and upgrade the system debs"
sudo apt-get -y update
sudo apt-get -y upgrade

echo "Get rvm setup so that we can install a modern version of ruby"
sudo apt-get -y install git-core build-essential zlib1g-dev libreadline5-dev libssl-dev libxml2-dev libxslt-dev 
( curl http://rvm.beginrescueend.com/releases/rvm-install-latest ) | bash # This is obviously VERY INSECURE
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"' > ~/.profile
source ~/.rvm/scripts/rvm

echo "Now install and select ruby 1.9.2"
rvm install 1.9.2
rvm --default use 1.9.2

echo "Get an appropriate database backend going, for simplicity we use sqlite"
sudo apt-get -y install sqlite3 libsqlite3-dev
# We could have used mysql, but would need to update config/database.yml
# sudo apt-get -y install mysql-client mysql-server

# #############################################################
# STOP HERE. This should be sufficient for light use.         #
# Install apache, etc for production use only                 #
# #############################################################

echo "Install apache"
sudo apt-get -y install apache2 apache2-dev libcurl4-openssl-dev

echo "Install mod_rails/passenger"
gem install --no-rdoc --no-ri passenger
passenger-install-apache2-module -a

echo "Setup the passenger module"
# FIXME: Make this discover the location of the passenger gem automatically
# FIXME: Make this discover the location of the ruby bin automatically
sudo echo "LoadModule passenger_module /home/ubuntu/.rvm/gems/ruby-1.9.2-p136/gems/passenger-3.0.2/ext/apache2/mod_passenger.so" > /etc/apache2/mods-available/passenger.load
sudo echo "PassengerRoot /home/ubuntu/.rvm/gems/ruby-1.9.2-p136/gems/passenger-3.0.2" > /etc/apache2/mods-available/passenger.conf
sudo echo "PassengerRuby /home/ubuntu/.rvm/wrappers/ruby-1.9.2-p136/ruby" >> /etc/apache2/mods-available/passenger.conf
sudo a2enmod passenger

echo "Setup the site"
DIRECTORY="$( cd "$( dirname "$0" )" && pwd )/public"
URL="`curl  http://169.254.169.254/latest/meta-data/public-hostname`"
SITE_CONF="/etc/apache2/sites-available/twenty-fifty"

sudo echo "<VirtualHost *:80>" > $SITE_CONF
sudo echo "   ServerName $URL" >> $SITE_CONF
sudo echo "   DocumentRoot $DIRECTORY" >> $SITE_CONF
sudo echo "   <Directory $DIRECTORY>" >> $SITE_CONF
sudo echo "      AllowOverride all" >> $SITE_CONF
sudo echo "      Options -MultiViews" >> $SITE_CONF
sudo echo "   </Directory>" >> $SITE_CONF
sudo echo "</VirtualHost>" >> $SITE_CONF
sudo a2ensite twenty-fifty
sudo apache2ctl graceful