This document is intended to guide you through setting up a local development environment for Colouring London. This guide assumes you already have Ubuntu 18.04 server installed, typically installed in a virtual environment such a Virtual Box and are able to SSH into your Ubuntu installation for convenience.
<br>
<br>
First upgrade the installed packages to the latest versions, to remove any security warnings.
Create a superuser role for this user (`<username>`) if it does not already exist. The password `<pgpassword>` is arbitrary and probably should not be your Ubuntu login password.
`sudo -u postgres psql -c "SELECT 1 FROM pg_user WHERE usename = '<username>';" | grep -q 1 || sudo -u postgres psql -c "CREATE ROLE <username> SUPERUSER LOGIN PASSWORD '<pgpassword>';"`
Now run all 'up' migrations to create tables, data types, indexes etc. The `.sql` scripts to do this are located in the `migrations` folder of your local repository.
`ls ./colouring-london/migrations/*.up.sql 2>/dev/null | while read -r migration; do psql -d <colorlondondb> < $migration; done;`
<br>
#### Setting up Python
Now set up a virtual environment for python. In the following example we have named the virtual environment *colouringlondon* but it can have any name.
`pyvenv colouringlondon`
Activate the virtual environment so we can install python packages into it.
`source colouringlondon/bin/activate`
Install python pip package manager and related tools.
`pip install --upgrade pip`
`pip install --upgrade setuptools wheel`
Now install the required python packages. This relies on the `requirements.txt` file located in the `etl` folder of your local repository.
Now upgrade the npm package manager to the most recent release with global privileges. This needs to be performed as root user, so it is necessary to export the node variables to the root user profile. Don't forget to exit from root at the end.
Now install the required Node packages. This needs to done from the `app` directory of your local repository, so that it can read from the `package.json` file.
`cd ./colouring-london/app && npm install`
<br>
#### Running the application
Now we are ready to run the application. The `APP_COOKIE_SECRET` is arbitrary.
If you a running Ubuntu in a virtual environment you will need to configure networking to forward ports from the guest to the host. For Virtual Box the following was configured under NAT port forwarding.
Name | Protocol | Host Port | Guest Port
----------| ---------- | --------- | ---------
app | TCP | 8080 | 3000
app_dev | TCP | 3001 | 3001
ssh | TCP | 4022 | 22
The site can then be viewed on http://localhost:8080. The `app_dev` mapping is used in development by Razzle which rebuilds and serves client side assets on the fly.