Skip to content

Installing Dev Compass

Ryan Hodges edited this page Aug 27, 2019 · 2 revisions

This guide walks you through installing a dev instance of Compass alongside a previously installed production instance.

Why Dev

Having a Dev instance allows an admin to try out adding layers and themes without exposing them to the public site - being sure layer, metadata, and legend are all in place and displaying as expected prior to the reveal.

Step 1: Install Compass

It is expected that you have an Ubuntu 18.04 LTS server with a running instance of Compass already installed. If you have not done this, please follow this guide first: Install Compass

Step 2: Clone the Repo

Since you already have COMPASS sitting at /usr/local/apps/ and all of the helper scripts assume 'dev-compass', we can't just clone 'COMPASS' into apps without having a naming conflict. To avoid this, we'll clone into a temp directory, then rename and move the repo's root folder back into apps:

  • mkdir /usr/local/apps/dev
  • cd /usr/local/apps/dev/
  • git clone https://github.com/Ecotrust/COMPASS.git
  • mv /usr/local/apps/dev/COMPASS/ /usr/local/apps/dev-compass
  • cd /usr/local/apps/
  • rm -r /usr/local/apps/dev/

Step 3: Create the Dev Database

The following steps will refer to USERNAME as a shorthand for the compass database user you created in the production Compass install. This does not have to be the same user, but if not, you will need to refer to those instructions to create a new DB user.

  • create a new DB named 'compass_dev' (by default the production database is named 'compass')
    • sudo -u postgres createdb -O USERNAME compass_dev
  • IF you are creating a database from scratch: * sudo -u postgres psql -c "CREATE EXTENSION postgis; CREATE EXTENSION postgis_topology;" compass_dev * From scratch you will need to perform some additional tasks after migration, including creating the 'public' user. See the 'Public Drawing' section of the production installation instructions for more info.
    • else, if you have another DB (perhaps your prod DB) you want to load in:
      • DUMP the template DB (we'll use the local 'compass' db in this case)
      • sudo -u postgres pg_dump compass > /tmp/compass_dump.sql
      • sudo -u postgres psql compass_dev < /tmp/compass_dump.sql Add db user to pg_hba.conf:
  • vim /etc/postgresql/10/main/pg_hba.conf
  • add line to bottom:
    local   compass_dev    USERNAME                  trust
    
  • save and close
  • restart postgres: sudo service postgresql restart

Step 4: Virtual Environment

cd /usr/local/apps/dev-compass/
python3 -m virtualenv env
source /usr/local/apps/dev-compass/env/bin/activate

Step 5: Install Python Dependencies

pip install -r /usr/local/apps/dev-compass/requirements.txt

Step 6: Install PyGDAL

Currently PyGDAL is a bit of a pain to install...

pip uninstall numpy
gdal-config --version
  • Capture the output of that last command (such as 2.2.3)
  • Increment the last digit by 1 and plug it in to pip install "pygdal<X.Y.Z" (such as pip install "pygdal<2.2.4")

Step 7: Local Settings

cp /usr/local/apps/dev-compass/mp/settings_local.template /usr/local/apps/dev-compass/mp/settings_local.py

For USERNAME use the same database username used in step 3 Edit /usr/local/apps/dev-compass/mp/settings_local.py:

  • SECRET_KEY = [something new]
  • DATABASES
    • 'NAME': 'compass_dev'
    • 'USER': '[USERNAME]'
    • 'PASSWORD': '[add password]',
    • 'HOST': 'localhost',
    • 'PORT': 5432,
  • MEDIA_ROOT = '/usr/local/apps/dev-compass/mediaroot/'
  • MEDIA_URL = '/media/'
  • SOCKET_URL = ''
  • SOCIAL_AUTH_GOOGLE_PLUS_KEY = ''
  • SOCIAL_AUTH_GOOGLE_PLUS_SECRET = ''
  • ADMIN_MEDIA_PATH = '/usr/local/apps/dev-compass/env/python3/site-packages/django/contrib/admin/static/admin/' If enabling public drawing, please also add:
  • PUBLIC_CSV_DIR = '/usr/local/apps/dev-compass/mediaroot/csvs/'

Step 8: Prep logfile/Logdir

Here, USERNAME refers to your OS user (i.e. 'ubuntu')

sudo chown -R USERNAME /usr/local/apps/dev-compass/mp/logs/

Step 9: Create djdev Alias

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

alias djdev="/usr/local/apps/dev-compass/env/bin/python3 /usr/local/apps/dev-compass/mp/manage.py"
alias djdevrun="djdev runserver 0:8000 --noreload"

exit out of the ssh session and ssh back in again

Step 10: Enable layer fixture import/export

mkdir /usr/local/apps/dev-compass/mediaroot/data_manager_uploads
sudo chgrp www-data /usr/local/apps/dev-compass/mediaroot/data_manager_uploads

Step 11: Final Django setup steps

If you created a new database:

djdev migrate
djdev loaddata /usr/local/apps/dev-compass/mp/fixtures/layer-data.json
djdev loaddata /usr/local/apps/dev-compass/mp/fixtures/project-settings.json

If you used psql to load in a DB from a dump file:

djdev migrate --fake-initial

In both cases, run the following:

djdev collectstatic
djdev enable_sharing all

use djdevrun to test that things are working as expected

Step 12: Installing on NGINX/uWSGI

From inside your virualenv:

  • pip install uwsgi
  • test uwsgi install with uwsgi --http :8000 --wsgi-file /usr/local/apps/COMPASS/mp/wsgi.py
  • sudo cp /usr/local/apps/dev-compass/deploy/compass.conf /etc/nginx/sites-available/compass_dev
    • sudo vim /etc/nginx/sites-available/compass_dev
      • remove the 'arcgix_services' section
        • The duplication breaks NGINX - does removing it break any assumptions?
      • update server_name to use your specific compass-dev url
      • update the logfile locations to use '_dev' in the names
      • udpate /static and /media to point at 'dev-compass' instead of 'COMPASS'
      • under '/' update 'uwsgi_pass unix:///tmp/compass-*dev-*socket;'
  • sudo ln -s /etc/nginx/sites-available/compass_dev /etc/nginx/sites-enabled/compass_dev
  • test the configuration with sudo nginx -t
  • sudo cp /usr/local/apps/dev-compass/deploy/compass_dev.service /etc/systemd/system/compass_dev.service
  • sudo systemctl enable compass_dev.service
  • sudo cp /usr/local/apps/dev-compass/deploy/compass_dev.ini /etc/uwsgi/apps-enabled/compass_dev.ini
  • sudo service nginx restart
  • sudo service compass_dev start
  • sudo service compass_dev restart
  • sudo chmod 666 /usr/local/apps/dev-compass/mp/logs/main.log <- TODO: make this not necessary
  • sudo chmod 666 /usr/local/apps/dev-compass/mp/logs/main_debug.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

Step 13: PUBLIC DRAWING

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

  • If you created a new database from scratch (not imported from a dump) be sure to:

    • Create a django user with username 'public'
    • Use the admin hex-import script to import new base data
    • Check that you have the correct species lookups (manage.py import_report_lookups)
  • chown www-data the following directories:

    • media/extracted/
    • media/planning_unit_sql/
    • mediaroot/csvs/
  • Be sure to install the public-drawing branch of Madrona in your environment

    • py3 branch contains public-drawing by default

Old PUBLIC DRAWING NOTES (Deprecated)

  • 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

Step 14: Add Fonts

cp -r /usr/local/apps/COMPASS/media/compass/fonts/ /usr/local/apps/dev-compass/media/compass/
cp /usr/local/apps/COMPASS/media/compass/css/compass_fonts.css /usr/local/apps/dev-compass/media/compass/css/
djdev collectstatic