Skip to content

Development Installation

David Pollard edited this page Apr 3, 2024 · 28 revisions

Development Installation:

  1. Create a DEVELOPMENT DIRECTORY

    1. this doc will assume Unix formatted addresses:
      1. if running Windows, you will use \ instead of /
    2. Put this somewhere where your user has full privileges, like one of the following examples:
      1. Linux: /home/YOUR_USER_NAME/projects
      2. Max: /Users/YOUR_USER_NAME/projects
      3. Windows would looks something like C:\Users\YOUR_USER_NAME\projects
  2. Install Git

  3. Clone repository into your DEVELOPMENT DIRECTORY

    cd /YOUR/DEVELOPMENT/DIRECTORY/
    git clone https://github.com/Ecotrust/TEKDB.git
    
  4. Install Vagrant

  5. Deploy base box with Vagrant

    cd /YOUR/DEVELOPMENT/DIRECTORY/TEKDB/
    vagrant up
    
    1. Wait while your new VM installs all of the required dependencies
    2. if you see an error like:
          default: cannot touch '/home/ubuntu/.bash_aliases'
          default: : Permission denied
          default: /vagrant/scripts/vagrant_provision_ubuntu.sh: line 43: /home/ubuntu/.bash_aliases: Permission denied
      The SSH command responded with a non-zero exit status. Vagrant assumes that this means the command failed. The output for this command should be in the log above. Please read the output to determine what went wrong.
      
      1. this likely means your vagrant VM is using 'vagrant' for the default user, but all of the code assumes 'ubuntu' as the default user. Fix this by:
        1. vagrant halt
        2. vagrant destroy
        3. Comment out the line in Vagrantfile that reads: config.ssh.username = "ubuntu"
          • vagrant assumes a user of 'vagrant' - the box assigns all passwords and public keys to this user, so we need to log in with this user, create the 'ubuntu' user that we need to finish up, and re-provision from there.
        4. vagrant up
        5. vagrant ssh
        6. sudo cp /home/vagrant/.ssh/authorized_keys /home/ubuntu/.ssh/
        7. exit
        8. Then edit Vagrantfile to include: config.ssh.username = "ubuntu"
        9. vagrant halt
        10. vagrant up --provision
  6. Log in to your new VM and run updates

    vagrant ssh
    sudo apt-get update
    sudo apt-get upgrade
    
  7. Update Local Settings

    1. File (same file, just accessed from either the host or the vm):
      1. On Host server: /YOUR/DEVELOPMENT/DIRECTORY/TEKDB/TEKDB/TEKDB/local_settings.py
      2. On Vagrant VM: /usr/local/apps/TEKDB/TEKDB/local_settings.py
    2. Things to change:
      1. DEBUG: add a line that reads DEBUG=True - this is only to be used for development environments, not live servers.
      2. SECRET_KEY: change to a long string of gibberish - you never need to type this in, so the longer and more complex the better
      3. DATABASE_GEOGRAPHY: basic geo settings so the maps know where to focus by default in the admin
        1. For example:
        DATABASE_GEOGRAPHY = {
            'default_lon': -124.2,
            'default_lat': 41.9,
            'default_zoom': 10,
            'map_template': 'gis/admin/ol2osm.html',
        }
        
        1. NOTES:
          1. LAT/LON: the lon and lat presented here are Coordinates (EPSG:4326) for the Northern CA coast. At the time of this writing, the tool only supports coordinates in Web Mercator (EPSG:3857), so the longitude would actually be -13825880.7546 and the latitude is 5146011.678566459.
          2. ZOOM: The higher the number, the more closely zoomed in the map will be by default.
          3. TEMPLATE: The location of the html template for displaying the map in the admin tool for geometry fields.
  8. Virtual Environment Setup

    sudo apt install python3-venv
    python3 -m venv env
    
  9. Activate your python virtual environment

    source /usr/local/apps/TEKDB/env/bin/activate
    
  10. Install requirements

    pip3 install -r /usr/local/app/TEKDB/TEKDB/requirements.txt
    
  11. Install dependencies

    sudo apt-get install git python3 python3-pip python3-virtualenv virtualenv gcc make uwsgi uwsgi-plugin-python3 gdal-bin python3-gdal python3-dev build-essential -y
    sudo apt install postgresql-14 postgresql-contrib postgresql-server-dev-14 postgis postgresql-14-postgis-3 -y
    
  12. Create Database and User. You will be prompted to enter a password of your choice.

    sudo -u postgres createuser -s -P USERNAME
    sudo -u postgres createdb -O USERNAME tekdb
    
  13. Enable External Access to Postgres Enable authentication from remote access

    sudo vim /etc/postgresql/14/main/pg_hba.conf
    

    Find the section of uncommented lines near the bottom. Change for the user postgres to:

    local    all           postgres                 trust
    

    Log out and log back into your VM

    ctrl+D
    vagrant ssh
    
  14. Run migration

    python /usr/local/apps/TEKDB/manage.py migrate
    
  15. Run static file collection

    python /usr/local/apps/TEKDB/manage.py collectstatic
    
  16. Load in the dummy data

    python /usr/local/apps/TEKDB/manage.py loaddata /usr/local/apps/TEKDB/TEKDB/fixtures/all_dummy_data.json
    
  17. Test your installation with Django’s Dev Server

    python /usr/local/apps/TEKDB/manage.py runserver 0.0.0.0:8000
    
    1. Open http://localhost:8111

Clone this wiki locally