AgileVentures/LocalSupport

View on GitHub
docs/installation/c9.md

Summary

Maintainability
Test Coverage
## Installation commands

(Note: these instructions are for the original c9 - AWS C9 may require alternative commands)

Cloud9 can be found [here](https://c9.io/). To create a Cloud9 workspace to run LocalSupport:

1. Fork the `http://github.com/AgileVentures/LocalSupport` repo (fork button at top right of github web interface)
2. Create a workspace in Cloud9. Fill in the fields:
    - **Workspace name:** LocalSupport (or anything else that fits you)
    - **Clone from Git or Mercurial URL:** the url of your forked repository, e.g. `https://github.com/your-git-id/LocalSupport.git`
    - **Choose a template:** Select the *Rails / Ruby* icon
    - Click the *Create workspace* button

   If you get a message: `ruby-2.x.y is not installed.`, see next section to install that version of ruby.

3. Update package cache: `sudo apt-get update`


4. Change branch for development: `git checkout develop`


5. Install Qt webkit ([source](https://github.com/thoughtbot/capybara-webkit/wiki/Installing-Qt-and-compiling-capybara-webkit)):

    `sudo apt-get install qt5-default libqt5webkit5-dev gstreamer1.0-plugins-base gstreamer1.0-tools gstreamer1.0-x`

    (*Note:* for some reason, I could not get it to pass on the first try.)

6. Install [GNU IDN Library](http://www.gnu.org/software/libidn/#downloading) version 1.33
  You will need a few basic tools, such as ‘sh’, ‘make’ and ‘cc’.
  ```bash
  wget -q ftp://ftp.gnu.org/gnu/libidn/libidn-1.33.tar.gz
  tar xfz libidn-1.33.tar.gz
  cd libidn-1.33/
  ./configure
  ...
  make
  ...
  make install
  ...
  ```

  The `make install` command may need to be ran with sudo. for ex:
  ```bash
  sudo make install
  ```

7. Configure the pre-installed postgreSQL. Check which version is installed with `ls /etc/postgresql/`. If the version is not 9.3, the `sed` commands must be edited to reflect the current version.

```Shell
# Change conf files to map your user to postgres user
sudo sed -i 's/local[ ]*all[ ]*postgres[ ]*peer/local all postgres peer map=basic/' /etc/postgresql/9.3/main/pg_hba.conf
sudo sed -i "$ a\basic $USER postgres" /etc/postgresql/9.3/main/pg_ident.conf
# Start the service
sudo service postgresql start
# Make the default database template encoded in unicode
psql -U postgres -c "update pg_database set encoding = 6, datcollate = 'C', datctype = 'C' where datname = 'template1';"
sudo /etc/init.d/postgresql restart
```

8. Install X virtual frame buffer

    `sudo apt-get install xvfb`

9. Run `bundle install` to get the gems (run `gem install bundler` if bundler is not installed)

 (*Note:* If your connection breaks during the process retry until all gems are installed.)

10. *(optional)* Run `selenium install` to download jars that this gem needs

11. Get the javascript dependencies:

```Shell
sudo apt-get install npm
npm install -g bower
bower install
```

12. *(optional)* Update the heroku tools : `wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh`

13. Run the following to get the database set up and import seed data

```Shell
bundle exec rake db:create
bundle exec rake db:migrate
bundle exec rake db:setup
```

*Note:*  You might encounter error with the creating the relevant schema. This is due to some configuration error with PostgreSql. Solution of interest can be found [(1) here](PostgreSQL-problems-in-Debian.md) and [(2) here](issues.md#peer-authentication-fails-for-user-postgres). You should first drop the cluster as mentioned in (1) and then configure the user access privileges in pg_hba.conf and username mapping in pg_ident.conf. One way to successfully configure the line `pg_hba.conf` from

```
  # TYPE  DATABASE       USER            ADDRESS                 METHOD
  local   all             all                                     peer
```
to

```
  # TYPE  DATABASE       USER            ADDRESS                 METHOD
  local   all             all                                     trust
```
and add a mapping in `pg_ident.conf`
```
# MAPNAME       SYSTEM-USERNAME                                         PG-USERNAME
basic           ubuntu(or the username of your C9 instance)             postgres
```

14. Run locally with `rails s -b $IP -p $PORT` (in either a terminal or a *run configuration* window)

15. Run the test (note the explicit call to `xvfb` when executing cucumber -- Cloud9 does not run an X-server)

```ruby
bundle exec rake db:migrate RAILS_ENV=test
bundle exec rake spec
xvfb-run -a bundle exec cucumber
```

## Installing another version of ruby in Cloud9

If the ruby version specified in the LocalSupport gemfile does not match one of the preinstalled version on Cloud9, the following message is outputted:

```
ruby-2.x.y is not installed.
To install do: 'rvm install ruby-2.x.y'
```

Execute the suggested command to install the proper version (the compilation of ruby may take some time). After completion, execute:

`gem install bundler`

You should also make that ruby version your default version, with the command:

`rvm --default use 2.x.y`