Skip to content

Commit eb911d3

Browse files
authored
Merge pull request #4 from hackoregon/ec2-deploy
Ec2 deploy
2 parents ac1d5ca + 682add0 commit eb911d3

10 files changed

Lines changed: 133 additions & 0 deletions

ec2-deploy/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
geocoder.html

ec2-deploy/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Hack Oregon Geocoder Spring 2017 Edition
2+
1. You'll need a 64-bit Ubuntu 16.04.2 LTS "Xenial Xerus" base box. I tested on a 15 GB drive but it looks like it will run in 10. It will need at least 10. I tested on a 1 GB RAM local VM and a 1 GB RAM EC2 instance.
3+
2. You'll need `git` and `sudo` but the scripts should install everything else required.
4+
3. Log in on a terminal via `ssh` - don't do this on the console in a VM.
5+
4. Enter
6+
7+
```
8+
git clone https://github.com/hackoregon/postgis-geocoder-test
9+
cd postgis-geocoder-test/ec2-deploy
10+
sudo ./root-install-postgis.bash
11+
```
12+
13+
The script will take about half an hour ... it downloades a bunch of shapefiles, inserts them into a database, builds some indexes, creates a `pg_dump` of the database and makes an HTML database document. The last thing it does is test the geocoder. If everything worked you'll see the Hack Oregon headquarters geocoded.
14+
5. The dump file is in `/gisdata/geocoder.pgdump` and the HTML document is in `/gisdata/geocoder.html`. You should be able to recreate this on any PostgreSQL 9.6 / PostGIS 2.3 system by restoring the dump file as the `postgres` PostgreSQL superuser.

ec2-deploy/extensions.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CREATE EXTENSION postgis_tiger_geocoder CASCADE;
2+
GRANT USAGE ON SCHEMA tiger TO PUBLIC;
3+
GRANT USAGE ON SCHEMA tiger_data TO PUBLIC;
4+
GRANT SELECT, REFERENCES, TRIGGER ON ALL TABLES IN SCHEMA tiger TO PUBLIC;
5+
GRANT SELECT, REFERENCES, TRIGGER ON ALL TABLES IN SCHEMA tiger_data TO PUBLIC;
6+
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA tiger TO PUBLIC;
7+
ALTER DEFAULT PRIVILEGES IN SCHEMA tiger_data GRANT SELECT, REFERENCES ON TABLES TO PUBLIC;

ec2-deploy/git-global.bash

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#! /bin/bash -v
2+
git config --global push.default matching
3+
git config --global user.email "znmeb@znmeb.net"
4+
git config --global user.name "M. Edward (Ed) Borasky"

ec2-deploy/make-nation-script.psql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
\t
2+
\a
3+
\o /gisdata/nation.bash
4+
SELECT loader_generate_nation_script('sh');
5+
\o

ec2-deploy/make-states-script.psql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
\t
2+
\a
3+
\o /gisdata/states.bash
4+
SELECT loader_generate_script(ARRAY['OR'], 'sh');
5+
\o

ec2-deploy/postgis.list

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#! /bin/bash
2+
3+
echo "Creating 'geocoder' database."
4+
echo "If there's already a 'geocoder' database you can ignore the error message."
5+
createdb -O postgres geocoder
6+
echo ""
7+
echo "Creating geocoder extension"
8+
echo "If you've already created the extension you can ignore the error messages."
9+
psql -d geocoder -f extensions.sql
10+
11+
echo ""
12+
echo "Creating the nation database population script"
13+
psql -d geocoder -f make-nation-script.psql
14+
chmod +x /gisdata/nation.bash
15+
sed -i -e "s;PGHOST=.*$;PGHOST=/var/run/postgresql;" /gisdata/nation.bash
16+
echo "Running the nation database population script"
17+
/gisdata/nation.bash
18+
19+
echo ""
20+
echo "Creating the states database population script"
21+
psql -d geocoder -f make-states-script.psql
22+
chmod +x /gisdata/states.bash
23+
sed -i -e "s;PGHOST=.*$;PGHOST=/var/run/postgresql;" /gisdata/states.bash
24+
echo "Running the states database population script"
25+
/gisdata/states.bash
26+
27+
echo ""
28+
echo "Installing any missing indexes"
29+
psql -d geocoder -c "SELECT install_missing_indexes();"
30+
31+
echo ""
32+
echo "Creating a dump of the geocoder database"
33+
pg_dump -Fc geocoder > /gisdata/geocoder.pgdump
34+
35+
echo ""
36+
echo "Testing the geocoder - compare lon and lat with Google Maps"
37+
psql -d geocoder -f test-geocoder.sql
38+
39+
echo ""
40+
echo "Documenting geocoder database schema"
41+
postgresql_autodoc -d geocoder -f /gisdata/geocoder -h /var/run/postgresql -t html
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#! /bin/bash
2+
3+
echo "Adding PostgreSQL / PostGIS package repository"
4+
apt-get update && apt-get install -y \
5+
git \
6+
vim-nox \
7+
curl \
8+
wget
9+
cp postgis.list /etc/apt/sources.list.d/
10+
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc \
11+
| apt-key add -
12+
apt-get update
13+
echo "http://apt.postgresql.org/pub/repos/apt repository added!"
14+
echo ""
15+
echo "Installing PostGIS packages"
16+
apt-get install -y \
17+
postgresql-9.6 \
18+
postgresql-autodoc \
19+
postgresql-client-9.6 \
20+
postgresql-contrib-9.6 \
21+
postgresql-doc-9.6 \
22+
postgresql-server-dev-9.6 \
23+
postgis \
24+
postgresql-9.6-postgis-2.3 \
25+
postgresql-9.6-postgis-2.3-scripts \
26+
postgresql-9.6-postgis-scripts \
27+
postgresql-9.6-pgrouting \
28+
postgresql-9.6-pgrouting-doc \
29+
postgresql-9.6-pgrouting-scripts
30+
31+
echo ""
32+
echo "Creating the /gisdata workspace"
33+
mkdir -p /gisdata/temp
34+
chown -R postgres:postgres /gisdata
35+
36+
echo ""
37+
echo "Populating the geocoder database - this will take a while"
38+
su postgres -c ./postgres-create-geocoder-database.bash

ec2-deploy/test-geocoder.sql

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
SELECT
2+
g.rating As r,
3+
ST_X(geomout) As lon,
4+
ST_Y(geomout) As lat,
5+
pprint_addy(addy) As paddress
6+
FROM
7+
geocode(
8+
'317 NW Glisan St, Portland, OR 97209'
9+
) As g;
10+
SELECT
11+
pprint_addy(addy),
12+
st_astext(geomout),
13+
rating
14+
FROM
15+
geocode_intersection(
16+
'Glisan', '3rd', 'OR', 'Portland'
17+
);

0 commit comments

Comments
 (0)