Skip to content

Latest commit

 

History

History
210 lines (157 loc) · 5.19 KB

dev_environ_setup_linux.md

File metadata and controls

210 lines (157 loc) · 5.19 KB

Development Environment Setup Instructions (Linux Ubuntu)

Setup Server

Step 1. Install PostgreSQL and PostGIS, and Dev libraries

$ sudo apt-get update
$ sudo lsb_release -a   (copy ubuntu version number)
$ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt (enter ubuntu version number)-pgdg main" >> /etc/apt/sources.list'
$ wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
$ sudo apt-get update
$ sudo apt-get install postgresql-9.5-postgis-2.2 pgadmin3 postgresql-contrib-9.5
$ sudo apt-get install libpq-dev

Step 2. Connect to database

$ sudo -u postgres psql postgres

Step 3. Set Postgres user password to "postgres", and create PostGIS required extensions:

# ALTER USER postgres WITH PASSWORD 'postgres';
# CREATE EXTENSION postgis;
# CREATE EXTENSION postgis_topology;
# CREATE EXTENSION fuzzystrmatch;
# \q

Modifiy the base template so all newly created test databases will have hstore extension:

$ psql -d template1 -c 'CREATE EXTENSION hstore;'

Step 4. Install Redis

$ wget http://download.redis.io/redis-stable.tar.gz
$ tar xvzf redis-stable.tar.gz
$ cd redis-stable
$ cd deps
$ # Dependencies have to be built before
$ make hiredis lua jemalloc linenoise geohash-int
$ cd ..
$ sudo make install
$ make test

Step 5. Install git and clone eTools repository

$ sudo apt install git
$ git clone https://github.com/unicef/etools.git

Step 6. Install latest pip, Python dev libraries, VirtualEnv, and VirtualEnvWrapper

$ sudo apt-get install python-pip python-dev build-essential
$ sudo pip install virtualenv
$ sudo pip install virtualenvwrapper

Step 7. Create Virtual Environment

  • Add . /usr/local/bin/virtualenvwrapper.sh to the end of ~/.bashrc

Restart the terminal

$ mkdir ~/.virtualenvs
$ export WORKON_HOME=~/.virtualenvs
$ mkvirtualenv env1

Step 8. Install GDAL dependencies

$ sudo apt-get install libgdal-dev
$ export CPLUS_INCLUDE_PATH=/usr/include/gdal
$ export C_INCLUDE_PATH=/usr/include/gdal

Step 9. Install Cryptography dependencies

$ sudo apt-get install libffi-dev
$ sudo apt-get install libssl-dev

Step 10. Load Python packages

$ pip install -r path/to/etools/EquiTrack/requirements/local.txt

Step 11. Set environment variables:

$ export REDIS_URL=redis://localhost:6379/0
$ export DATABASE_URL=postgis://postgres:(your-password-here)@localhost:5432/postgres

Step 12. Connect to database and create required hstore extension

$ sudo -u postgres psql postgres
# CREATE EXTENSION hstore;
# \q

Step 13. Activate virtual env, migrate database schemas and create database superuser

$ workon env1
$ python path/to/etools/EquiTrack/manage.py migrate_schemas --fake-initial --noinput
$ python path/to/etools/EquiTrack/manage.py createsuperuser --username:etoolsusr

Load Default Data

Import the test data:

$ bzcat db_dumps/pg_backup1_27-07-16.bz2 | sudo -u postgres nice pg_restore --verbose -F t -d postgres

Assign the test country (UAT) to the user:

$ workon env1
$ python manage.py shell

In the shell:

>>> from users.models import UserProfile, Country, Office, Section
>>> from django.contrib.auth.models import User
>>> user = User.objects.get(id=1)
>>> userp = UserProfile.objects.get(user=user)
>>> country=Country.objects.get(name='UAT')
>>> userp.country = country
>>> userp.country_override = country
>>> userp.save()

Run Server

$ workon env1
$ export DATABASE_URL=postgis://postgres:(your-password-here)@localhost:5432/postgres
$ python path/to/etools/EquiTrack/manage.py runserver 8080

Setup Debugger (PyCharm)

Step 1:

  • Once the project is loaded in PyCharm go to menu -> PyCharm - > Preferences -> Project
  • Make sure your project is chosen
  • Select the python interpreter present inside of the virtualenvironment

Step 2:

  • Go to menu -> PyCharm - > Preferences -> Languages & Frameworks -> Django
  • Select your project and:
    • enable Django Support
    • Set Django Project root
    • choose base.py as the settings file
    • add all of the previously mentioned environment vars

Step 3:

  • Go to menu -> Run -> Edit Configurations
  • Add Django Server and name it.
  • Set the Host to localhost
  • In the Configuration make sure to add the environment variables again +
    • DEBUG=True
  • Choose the python interpreter (The interpreter inside of the virtual environment)
  • Choose a working Directory

Step 4:

  • Quit Pycharm and restart it

Step 5:

  • Run the server
  • Go back to Edit Configurations
  • Change the environment variable DJANGO_SETTINGS_MODULE to EquiTrack.settings.local
  • Rerun the server

Resources

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-14-04

https://trac.osgeo.org/postgis/wiki/UsersWikiPostGIS22UbuntuPGSQL95Apt

http://redis.io/topics/quickstart

http://roundhere.net/journal/virtualenv-ubuntu-12-10/