Remove breaks, use multiline code blocks, reflow paragraphs

This commit is contained in:
Tom Russell 2019-04-09 09:23:50 +01:00
parent bad21c9eb0
commit c040105557

View File

@ -1,22 +1,16 @@
## Setting up a local development environment ## Setting up a local development environment
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. This document is intended to guide you through setting up a local development environment for
<br> Colouring London. This guide assumes you already have Ubuntu 18.04 server installed, typically
<br> installed in a virtual environment such a Virtual Box and are able to SSH into your Ubuntu
installation for convenience.
First upgrade the installed packages to the latest versions, to remove any security warnings. First upgrade the installed packages to the latest versions, to remove any security warnings.
`sudo apt-get update` ```
sudo apt-get update
sudo apt-get upgrade
`sudo apt-get upgrade` ```
<br>
#### Installing the tools and components #### Installing the tools and components
@ -24,14 +18,10 @@ Now we install some essential tools.
`sudo apt-get install -y build-essential git vim-nox wget curl` `sudo apt-get install -y build-essential git vim-nox wget curl`
<br>
Now install python and related tools. Now install python and related tools.
`sudo apt-get install -y python3 python3-pip python3-dev python3-venv` `sudo apt-get install -y python3 python3-pip python3-dev python3-venv`
<br>
Next install postgres and postgis to enable support for geographical objects. Next install postgres and postgis to enable support for geographical objects.
`sudo apt-get install -y postgresql postgresql-contrib libpq-dev postgis postgresql-10-postgis-2.4` `sudo apt-get install -y postgresql postgresql-contrib libpq-dev postgis postgresql-10-postgis-2.4`
@ -40,46 +30,37 @@ and additional geo-spatial tools
`sudo apt-get install -y gdal-bin libspatialindex-dev libgeos-dev libproj-dev` `sudo apt-get install -y gdal-bin libspatialindex-dev libgeos-dev libproj-dev`
<br>
Now clone the colouring london codebase. Now clone the colouring london codebase.
`git clone https://github.com/tomalrussell/colouring-london.git` `git clone https://github.com/tomalrussell/colouring-london.git`
<br>
Now install Node. It is helpful to define some local variables. Now install Node. It is helpful to define some local variables.
`NODE_VERSION=v8.11.3` ```
NODE_VERSION=v8.11.3
`DISTRO=linux-x64` DISTRO=linux-x64
wget -nc https://nodejs.org/dist/$NODE_VERSION/node-$NODE_VERSION-$DISTRO.tar.xz
`wget -nc https://nodejs.org/dist/$NODE_VERSION/node-$NODE_VERSION-$DISTRO.tar.xz` sudo mkdir /usr/local/lib/node
sudo tar xf node-$NODE_VERSION-$DISTRO.tar.xz -C /usr/local/lib/node
`sudo mkdir /usr/local/lib/node` sudo mv /usr/local/lib/node/node-$NODE_VERSION-$DISTRO /usr/local/lib/node/node-$NODE_VERSION
rm node-$NODE_VERSION-$DISTRO.tar.xz
`sudo tar xf node-$NODE_VERSION-$DISTRO.tar.xz -C /usr/local/lib/node` ```
`sudo mv /usr/local/lib/node/node-$NODE_VERSION-$DISTRO /usr/local/lib/node/node-$NODE_VERSION`
`rm node-$NODE_VERSION-$DISTRO.tar.xz`
<br>
Now add the Node installation to the path and export this to your bash profile. Now add the Node installation to the path and export this to your bash profile.
`cat >> ~/.profile <<EOF ```
cat >> ~/.profile <<EOF
export NODEJS_HOME=/usr/local/lib/node/node-$NODE_VERSION/bin export NODEJS_HOME=/usr/local/lib/node/node-$NODE_VERSION/bin
export PATH=\$NODEJS_HOME:\$PATH export PATH=\$NODEJS_HOME:\$PATH
EOF` EOF
```
You can check the updated variables as follows You can check the updated variables as follows
`echo $PATH` ```
echo $PATH
`echo $NODEJS_HOME` echo $NODEJS_HOME
```
<br>
#### Configuring Postgres #### Configuring Postgres
@ -87,65 +68,48 @@ Now we configure postgres. First ensure postgres is running.
`service postgresql start` `service postgresql start`
<br>
Ensure the `en_US` locale exists. Ensure the `en_US` locale exists.
`sudo locale-gen en_US.UTF-8` `sudo locale-gen en_US.UTF-8`
<br>
Configure the database to listen on network connection. Configure the database to listen on network connection.
`sudo sed -i "s/#\?listen_address.*/listen_addresses '*'/" /etc/postgresql/10/main/postgresql.conf` `sudo sed -i "s/#\?listen_address.*/listen_addresses '*'/" /etc/postgresql/10/main/postgresql.conf`
<br>
Allow authenticated connections from any IP (so includes the host). Allow authenticated connections from any IP (so includes the host).
`echo "host all all all md5" | sudo tee --append /etc/postgresql/10/main/pg_hba.conf > /dev/null` `echo "host all all all md5" | sudo tee --append /etc/postgresql/10/main/pg_hba.conf > /dev/null`
<br>
Restart postgres to pick up config changes. Restart postgres to pick up config changes.
`service postgresql restart` `service postgresql restart`
<br> 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.
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>';"` `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>';"`
<br> Create a colouring london database if none exists. The name (`<colouringlondondb>`) is arbitrary.
Create a colouring london database if none exists. The name (`<colorlondondb>`) is arbitrary. `sudo -u postgres psql -c "SELECT 1 FROM pg_database WHERE datname = '<colouringlondondb>';" | grep -q 1 || sudo -u postgres createdb -E UTF8 -T template0 --locale=en_US.utf8 -O <username> <colouringlondondb>`
`sudo -u postgres psql -c "SELECT 1 FROM pg_database WHERE datname = '<colorlondondb>';" | grep -q 1 || sudo -u postgres createdb -E UTF8 -T template0 --locale=en_US.utf8 -O <username> <colorlondondb>`
<br>
Create the necessary postgres extensions. Create the necessary postgres extensions.
`psql -d <colorlondondb> -c "create extension postgis;"` `psql -d <colouringlondondb> -c "create extension postgis;"`
`psql -d <colorlondondb> -c "create extension pgcrypto;"` `psql -d <colouringlondondb> -c "create extension pgcrypto;"`
`psql -d <colorlondondb> -c "create extension pg_trgm;"` `psql -d <colouringlondondb> -c "create extension pg_trgm;"`
<br>
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>
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 <colouringlondondb> < $migration; done;`
#### Setting up Python #### 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. 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` `pyvenv colouringlondon`
@ -155,69 +119,53 @@ Activate the virtual environment so we can install python packages into it.
Install python pip package manager and related tools. Install python pip package manager and related tools.
`pip install --upgrade pip` ```
`pip install --upgrade setuptools wheel` 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 install the required python packages. This relies on the `requirements.txt` file located
in the `etl` folder of your local repository.
`pip install -r ./colouring-london/etl/requirements.txt` `pip install -r ./colouring-london/etl/requirements.txt`
<br>
#### Setting up Node #### Setting up Node
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 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.
`sudo su root` ```
sudo su root
export NODEJS_HOME=/usr/local/lib/node/node-v8.11.3/bin/`
export PATH=$NODEJS_HOME:$PATH`
npm install -g npm@next`
exit
```
`export NODEJS_HOME=/usr/local/lib/node/node-v8.11.3/bin/` 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.
`export PATH=$NODEJS_HOME:$PATH`
`npm install -g npm@next`
`exit`
<br>
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` `cd ./colouring-london/app && npm install`
<br>
#### Running the application #### Running the application
Now we are ready to run the application. The `APP_COOKIE_SECRET` is arbitrary. Now we are ready to run the application. The `APP_COOKIE_SECRET` is arbitrary.
`PGPASSWORD=<pgpassword> PGDATABASE=<colorlondondb> PGUSER=<username> PGHOST=localhost PGPORT=5432 APP_COOKIE_SECRET=123456 npm start` `PGPASSWORD=<pgpassword> PGDATABASE=<colouringlondondb> PGUSER=<username> PGHOST=localhost PGPORT=5432 APP_COOKIE_SECRET=123456 npm start`
<br>
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.
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 Name | Protocol | Host Port | Guest Port
----------| ---------- | --------- | --------- -------- | --------- | ---------- | -----------
app | TCP | 8080 | 3000 app | TCP | 8080 | 3000
app_dev | TCP | 3001 | 3001 app_dev | TCP | 3001 | 3001
ssh | TCP | 4022 | 22 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.
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.
<br>
Finally to quit the application type `Ctrl-C`. Finally to quit the application type `Ctrl-C`.