Skip to content
Ryan Hodges edited this page May 23, 2019 · 27 revisions

Installing COMPASS

Independent Server Setup

install dependencies (deprecated):

  • git
  • python-dev
  • python-pip
  • python-virtualenv
  • postgresql-9.3
  • postgresql-9.3-postgis-2.1
  • postgresql-server-dev-9.3
  • libjpeg-dev

Install dependencies (Ubuntu 18.04 LTS, python 3 2019 overhaul)

sudo apt install git python3 python3-dev python3-virtualenv python3-pip postgresql postgresql-contrib postgis postgresql-server-dev-10 libjpeg-dev gdal-bin python-gdal python3-gdal -y

Create Apps directory:

sudo mkdir /usr/local/apps
sudo chown ubuntu /usr/local/apps

Check out the code into /usr/local/apps/:

cd /usr/local/apps/
git clone https://github.com/Ecotrust/COMPASS.git

Configure PostgreSQL

Replace USERNAME with an appropriate username for your database user below.

You will be prompted to enter a password for the new user as well. Keep track of these for the following steps as well.

sudo -u postgres createuser -s -P USERNAME
sudo -u postgres createdb -O USERNAME compass
sudo -u postgres psql -c "CREATE EXTENSION postgis; CREATE EXTENSION postgis_topology;" compass

Add db user to pg_hba.conf:

  • vim /etc/postgresql/10/main/pg_hba.conf
  • add line to bottom:
    local   compass    USERNAME    127.0.0.1/32  trust
    
  • save and close
  • restart postgres: sudo service postgresql restart

Create Python VirtualEnv

python3 -m pip install --user virtualenv
cd /usr/local/apps/COMPASS/
python3 -m virtualenv env
source /usr/local/apps/COMPASS/env/bin/activate

Install Python Dependencies

pip install -r /usr/local/apps/COMPASS/requirements.txt

Set local Django settings

cp /usr/local/apps/COMPASS/mp/settings_local.template /usr/local/apps/COMPASS/mp/settings_local.py

Edit /usr/local/apps/COMPASS/mp/settings_local.py:

  • SECRET_KEY = [something new]
  • DATABASES
    • 'NAME': 'compass'
    • 'USER': '[compassdbuser]'
    • 'PASSWORD': '[add password]',
    • 'HOST': 'localhost',
    • 'PORT': 5432,
  • MEDIA_ROOT = '/usr/local/apps/COMPASS/mediaroot/'
  • MEDIA_URL = '/media/'
  • SOCKET_URL = ''
  • SOCIAL_AUTH_GOOGLE_PLUS_KEY = ''
  • SOCIAL_AUTH_GOOGLE_PLUS_SECRET = ''
  • ADMIN_MEDIA_PATH = '/usr/local/apps/COMPASS/env/python3/site-packages/django/contrib/admin/static/admin/'

Prep logfile

sudo chown -R {username} /usr/local/apps/COMPASS/mp/logs/

Create dj Alias

sudo vim ~/.bashrc add this to the bottom:

alias dj="/usr/local/apps/COMPASS/env/bin/python3 /usr/local/apps/COMPASS/mp/manage.py"
alias djrun="dj runserver 0:8000 --noreload"

exit out of the ssh session and ssh back in again

Final Django setups steps

dj syncdb
dj migrate
dj install_media
dj loaddata /usr/local/apps/COMPASS/mp/fixtures/layer-data.json
dj loaddata /usr/local/apps/COMPASS/mp/fixtures/project-settings.json

use djrun to test that things are working as expected

Installing on NGINX/uWSGI

For reference go here

From inside your virualenv:

  • sudo apt-get install libpcre3 libpcre3-dev
  • apt-get install uwsgi uwsgi-plugin-python
  • pip install uwsgi
  • test uwsgi install with uwsgi --http :8000 --wsgi-file /usr/local/apps/COMPASS/mp/wsgi.py
  • sudo apt-get install nginx
  • sudo cp /usr/local/apps/COMPASS/deploy/compass.conf /etc/nginx/sites-available/compass
  • sudo rm /etc/nginx/sites-enabled/default
  • sudo ln -s /etc/nginx/sites-available/compass /etc/nginx/sites-enabled/compass
  • sudo service nginx (re)start
  • copy relevant content from deploy/rc.local.template to /etc/rc.local to run uwsgi ini (deploy/compass_uwsgi.ini) on boot
  • sudo chmod 777 /usr/local/apps/COMPASS/mp/logs/main.log <- TODO: make this not necessary
  • sudo reboot
  • In a few minutes, test your URL in a browser to see that everything came up as expected

PUBLIC DRAWING

If you are intending to allow public drawing on your install, you will want to follow these additional steps:

  • get fetch/merge
  • the scenarios/migrations/0003_auto__del... file does not seem to play well. Grab the version on the ODFW production server
  • manage.py syncdb, migrate, and install_media
  • In the admin, create a user with username 'public'
  • chown www-data the following directories:
    • media/extracted/
    • media/planning_unit_sql/
    • mediaroot/csvs/
  • Use the admin hex-import script to import new base data
  • Be sure that you have the correct species lookups (manage.py import_report_lookups)
  • Set a cron job to clean out the mediaroot/csvs/ directory
  • Set settings_local.py with PUBLIC_CSV_DIR = '/home/vagrant/marine-planner/mediaroot/csvs/' or similar
  • Be sure to install the public-drawing branch of Madrona in your environment

VM Setup (deprecated)

Dependencies

  • git

  • vagrant

  • Check out the code

  • Create and update mp/settings_local.py

    • MEDIA_ROOT = '/home/vagrant/marine-planner/media'

    • MEDIA_URL = '/media/'
    • SOCKET_URL = ''
    • SOCIAL_AUTH_GOOGLE_PLUS_KEY = ''
    • SOCIAL_AUTH_GOOGLE_PLUS_SECRET = ''
    • ADMIN_MEDIA_PATH = '/home/vagrant/.virtualenvs/marine-planner/lib/python2.7/site-packages/django/contrib/admin/static/admin/'
  • vagrant up

    • (ignore) Exceptions: Exception: Your MEDIA_ROOT setting has to be a directory other than your madrona or project media folder!
    • Likely this will choke on not being able to find ElementTree
      • Copy ElementTree libraries from a live source
      • run vagrant provision
  • vagrant ssh

    • dj syncdb
      • create superuser now
    • dj migrate
    • dj loaddata data_manager/fixtures/ofr_data_manager.json [ dj is alias for python manage.py ]
    • dj loaddata mp-settings/fixtures/ofr_mp_settings.json
    • dj loaddata ../mp/fixtures/project_settings.json
    • dj loaddata ../mp/fixtures/layer_data_proxy.json
  • dj site localhost:8000

  • dj createsuperuser

  • djrun [ same as python manage.py runserver 0.0.0.0:8000 ]

  • Point a browser at http://localhost:8000

Clone this wiki locally