Skip to content

Commit

Permalink
Go back to older Ubuntu; specify node version for NVM
Browse files Browse the repository at this point in the history
  • Loading branch information
kueda committed Apr 19, 2020
1 parent a9bc3af commit dde1d0b
Show file tree
Hide file tree
Showing 6 changed files with 1,813 additions and 680 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10.20.0
50 changes: 30 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,46 @@ vagrant ssh
git clone https://github.com/kueda/underfoot.git
cd underfoot

# Set up node via NVM. The important part is that you want node 10.x, otherwise
# SQLite will note compile
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
source ~/.profile
nvm use

# Set up a python virtual environment
virtualenv venv -p python3 --no-site-packages
source venv/bin/activate

# Install python deps and some stuff for working with ESRI Arc/Info coverages
./setup
# Install deps and some stuff for working with ESRI Arc/Info coverages
# ./setup
python setup.py

# Make an pack
python packs.py us-ca-oakland

# Create the database and prepare all the data. Takes a good long while.
python prepare-database.py
# # Create the database and prepare all the data. Takes a good long while.
# python prepare-database.py

# Install node deps for generating MBTiles
npm install
# # Install node deps for generating MBTiles
# npm install

# Generate MBtiles
./node_modules/tl/bin/tl.js copy -i underfoot_units.json -z 7 -Z 14 \
'postgis://underfoot:underfoot@localhost:5432/underfoot?table=units' \
mbtiles://./underfoot_units.mbtiles
# # Generate MBtiles
# ./node_modules/tl/bin/tl.js copy -i underfoot_units.json -z 7 -Z 14 \
# 'postgis://underfoot:underfoot@localhost:5432/underfoot?table=units' \
# mbtiles://./underfoot_units.mbtiles

# Generate roads mbtiles from OSM data (currently hard-coded for California)
# Makes underfoot_ways.mbtiles. It takes a long time and takes a lot of disk.
./osm.sh
# # Generate roads mbtiles from OSM data (currently hard-coded for California)
# # Makes underfoot_ways.mbtiles. It takes a long time and takes a lot of disk.
# ./osm.sh

# Generate elevation contours from Mapzen / Amazon elevation tiles
# (https://registry.opendata.aws/terrain-tiles/) and load them into PostGIS
./elevation.sh
# # Generate elevation contours from Mapzen / Amazon elevation tiles
# # (https://registry.opendata.aws/terrain-tiles/) and load them into PostGIS
# ./elevation.sh

# Annoying, but you have to ctrl-c here to get it to finish. Some kind of bug in tl.
./node_modules/tl/bin/tl.js copy -i elevation.json -z 14 -Z 14 \
'postgis://underfoot:underfoot@localhost:5432/underfoot?table=contours12' \
mbtiles://./elevation.mbtiles
# # Annoying, but you have to ctrl-c here to get it to finish. Some kind of bug in tl.
# ./node_modules/tl/bin/tl.js copy -i elevation.json -z 14 -Z 14 \
# 'postgis://underfoot:underfoot@localhost:5432/underfoot?table=contours12' \
# mbtiles://./elevation.mbtiles
```

# Adding Sources
Expand Down
55 changes: 3 additions & 52 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,76 +12,27 @@ Vagrant.configure("2") do |config|
# like at ubuntu@localhost:5433
config.vm.network "forwarded_port", guest: 5432, host: 5433

# # Modifications to postgres security to allow port forwarding to the host.
# # Obviously this is insecure and only meant to be used in a local setting
# postgresql_conf_access_for_host = "listen_addresses='*'"
# pgsql_mods = "grep -q -F \"#{postgresql_conf_access_for_host}\" /etc/postgresql/10/main/postgresql.conf || echo \"#{postgresql_conf_access_for_host}\" >> /etc/postgresql/10/main/postgresql.conf\n"
# %w(vagrant ubuntu underfoot).each do |user|
# pgsql_mods << "sudo -u postgres psql -c \"DROP ROLE IF EXISTS #{user}; CREATE ROLE #{user} INHERIT LOGIN SUPERUSER PASSWORD '#{user}'\"\n"
# pg_hba_access_for_local_ipv4 = "host all #{user} 127.0.0.1/32 trust # Trust all local connections"
# pg_hba_access_for_host = "host all #{user} 10.0.2.2/32 trust # Support connections from the vagrant host"
# [pg_hba_access_for_local_ipv4, pg_hba_access_for_host].each do |pattern|
# pgsql_mods << "grep -q -F '#{pattern}' /etc/postgresql/10/main/pg_hba.conf || echo '#{pattern}' >> /etc/postgresql/10/main/pg_hba.conf\n"
# end
# end

# # Provision the vm with the relevant dependencies, modify postgres settings
# # and create an ubuntu superuser
# config.vm.provision "shell", inline: <<-SHELL
# add-apt-repository ppa:ubuntugis/ppa
# apt-get update
# apt-get install -y git
# apt-get install -y virtualenv
# apt-get install -y npm
# apt-get install -y python3
# apt-get install -y python-gdal
# apt-get install -y gdal-bin
# apt-get install -y libgdal-dev
# apt-get install -y postgis
# apt-get install -y unzip
# apt-get install -y osmosis
# #{pgsql_mods}
# service postgresql restart
# SHELL

# Modifications to postgres security to allow port forwarding to the host.
# Obviously this is insecure and only meant to be used in a local setting
postgresql_conf_access_for_host = "listen_addresses='*'"
pgsql_mods = "grep -q -F \"#{postgresql_conf_access_for_host}\" /etc/postgresql/12/main/postgresql.conf || echo \"#{postgresql_conf_access_for_host}\" >> /etc/postgresql/12/main/postgresql.conf\n"
pgsql_mods = "grep -q -F \"#{postgresql_conf_access_for_host}\" /etc/postgresql/10/main/postgresql.conf || echo \"#{postgresql_conf_access_for_host}\" >> /etc/postgresql/10/main/postgresql.conf\n"
%w(vagrant ubuntu underfoot).each do |user|
pgsql_mods << "sudo -u postgres psql -c \"DROP ROLE IF EXISTS #{user}; CREATE ROLE #{user} INHERIT LOGIN SUPERUSER PASSWORD '#{user}'\"\n"
pg_hba_access_for_local_ipv4 = "host all #{user} 127.0.0.1/32 trust # Trust all local connections"
pg_hba_access_for_host = "host all #{user} 10.0.2.2/32 trust # Support connections from the vagrant host"
[pg_hba_access_for_local_ipv4, pg_hba_access_for_host].each do |pattern|
pgsql_mods << "grep -q -F '#{pattern}' /etc/postgresql/12/main/pg_hba.conf || echo '#{pattern}' >> /etc/postgresql/12/main/pg_hba.conf\n"
pgsql_mods << "grep -q -F '#{pattern}' /etc/postgresql/10/main/pg_hba.conf || echo '#{pattern}' >> /etc/postgresql/10/main/pg_hba.conf\n"
end
end

# Provision the vm with the relevant dependencies, modify postgres settings
# and create an ubuntu superuser
# FYI, setting up the custom Postgres repo is based on https://wiki.postgresql.org/wiki/Apt
config.vm.provision "shell", inline: <<-SHELL
add-apt-repository ppa:ubuntugis/ppa
apt-get update
apt-get install -y git
apt-get install -y virtualenv
apt-get install -y python3
apt-get install -y python3-dev
apt-get install -y python-gdal
apt-get install -y gdal-bin
apt-get install -y libgdal-dev
apt-get install -y unzip
apt-get install -y osmosis
apt-get install curl ca-certificates gnupg
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
apt-get update
apt-get install -y postgresql-12-postgis-3
apt-get install -y git virtualenv python3 python3-dev python-gdal gdal-bin libgdal-dev postgis unzip osmosis
#{pgsql_mods}
service postgresql restart
SHELL

# TODO move node-related setup to an nvm-based post-provisioning step, b/c for
# some reason it just doesn't work anymore

end
5 changes: 3 additions & 2 deletions database.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import psycopg2
from sources import util

DBNAME = "underfoot"
SRID = "4326"
Expand All @@ -7,7 +8,7 @@ def make_database():
try:
con = psycopg2.connect("dbname={}".format(DBNAME))
except psycopg2.OperationalError:
util.call_cmd(["createdb", dbname])
util.call_cmd(["psql", "-d", dbname, "-c", "CREATE EXTENSION postgis;"])
util.call_cmd(["createdb", DBNAME])
util.call_cmd(["psql", "-d", DBNAME, "-c", "CREATE EXTENSION postgis;"])
con = psycopg2.connect("dbname={}".format(DBNAME))
con.close()
Loading

0 comments on commit dde1d0b

Please sign in to comment.