Git Product home page Git Product logo

nearapp-web's Introduction

NearApp-Web

  • This project will combine Django Framework, Django Rest Api, Angular Js and Angular Material technologies.
  • Project initially will use django template engine and combine html/css and angular logic in html and separate the javascript from html.
  • Angular part will be built by using components so that it will be easy to manage components and will be easy to migrate to Angular 2.

Dev Environment

  • There will be provisioning in Vagrantfile will handle installing required packages

  • for future, there will be docker base image and dockerfile to easy spin up this project.

  • Seperate db instance for mysql and redis like AWS RDS.

  • Steps to setup dev Environment

    • create a new folder called vagrants
    • create a sub-folder named near-web-portal under vagrants
    • download Vagrantfile from (https://github.com/aykutgk/dev_environment_files) under near-web-portal
    • create a new folder called data under near-web-portal
    • git clone this repo under near-web-portal
    • go back to main folder where Vagrantfile is
    • run --> vagrant up
    • to get into machine for mac --> vagrant ssh
    • for windows, download puttykey generator, and convert exisitng private_key to ptty by using that tool
    • download putty, put host info and import private_key from ssh/auth on right panel.
  • Steps to set up project Environment

    • create virtual python environment under home folder (run cd to go to home folder)
    • python3.5 -m venv venv_name
    • Activate the venv -> source venv_name/bin/activate
    • go to /vagrant_data
    • pip install --upgrade pip (for some wheel errors update pip version)
    • go into the project where requirements.txt exists
    • run --> pip install -r requirements.txt (this will install all required packages)
    • set up mysql server either in your local or in another vagrant instance
    • to install mysql-server --> sudo apt-get install mysql-server
    • username: root, password: 123456
    • go to project folder and open app/app/settings/dev.py
    • find DATABASE part and edit the host info. for localhost, change host to "localhost"
    • if you create seperate vagrant instance for db, dont forget to open it to public by editing bind_address in mysqld.conf to 0.0.0.0
    • and create new user and grant permissinon
    • Create user: CREATE USER 'mysql_django_user_external'@'192.168.10.1' IDENTIFIED BY '123456'; if you want to reach from eveywhere change that ip to %
    • Grant permissions: GRANT ALL PRIVILEGES ON db.* to 'mysql_django_user_external'@'192.168.10.1' WITH GRANT OPTION;
  • Run Django project

    • python manage.py runserver 0.0.0.0:8080 --settings=app.settings.dev (0.0.0.0 to reach it in your laptop from ip address in vagrantfile)
  • Migrations

    • initial migration --> python manage.py migrate --settings=app.settings.dev
    • after table changes --> python manage.py makemigrations --settings=app.settings.dev

Initial set up on Google Cloud

  • Web app set up

    • Spin up a new ubuntu 16.04 LTS instance (1 vCPU, 2 GB memory, 10GB SSD)
      • sudo apt-get update
    • install required python libraries
      • sudo apt-get install python3-pip
      • sudo apt-get install python3.5-venv
      • apt-get install libmysqlclient-dev
  • RDS and Redis setup

    • Spin up ubuntu 16.04 LTS instance (2 Core, 7GB memory, 50GB SSD)

      • sudo apt-get update
    • Install Mysql-Server 5.7

      • sudo apt-get install mysql-server-5.7
      • put strong root password
      • comment bind address (#bind-address = 127.0.0.1) in /etc/mysql/mysql.conf.d/mysqld.cnf
      • sudo service mysql restart
      • configure firewall to access rds from home
      • create mysql user to be used from http services (django/python) do not use root
      • create mysql user to connect database externally
        • CREATE USER 'external'@'%' IDENTIFIED BY 'pass'
        • GRANT ALL PRIVILEGES ON db.* to 'external'@'%' WITH GRANT OPTION;
    • Install Redis-Server

  • Run Jnkins for auto deployments and cronjobs (periodic tasks)

  • Running Gunicorn

    • used systemctl -> created new gunicorn.service under /etc/systemctl/system
    • permission to start/stop/status for jenkins user
    • trigger deployment from jenkins and sudo systemctl start gunicorn
  • Geo Django Set up

    • In Django settings, add 'django.contrib.gis' to INSTALLED_APPS
    • Change mysql engine to django.contrib.gis.db.backends.mysql
    • in models.py, use "from django.contrib.gis.db import models"
    • Install GEOS
  • Switching to PostgreSQL (PostGIS) from Mysql in order to use GeoDjango Effectively

    • first install python adapter for psycopg2 -> pip install psycopg2

    • Change the engine in database settings -> django.db.backends.postgresql

    • Set up PostgreSql server (https://www.postgresql.org/docs/9.6/static/install-short.html) (https://wiki.postgresql.org/wiki/Compile_and_Install_from_source_code)

      • wget https://ftp.postgresql.org/pub/source/v9.6.1/postgresql-9.6.1.tar.gz
      • tar xvfz postgresql-9.6.1.tar.gz
      • cd postgresql-9.6.1
      • sudo apt-get install build-essential libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt-dev libssl-dev libjson-c-dev
      • ./configure
      • make
      • sudo make install
      • sudo adduser postgres
      • sudo mkdir /usr/local/pgsql/data
      • sudo chown postgres /usr/local/pgsql/data
      • sudo su - postgres
      • /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
      • Not suggested way to start --> /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >logfile 2>&1 & --> this will start the databse
      • Suggested way to start --> /usr/local/pgsql/bin/pg_ctl start -D /usr/local/pgsql/data -l postgreysql.log
      • /usr/local/pgsql/bin/createdb test
      • /usr/local/pgsql/bin/psql test
      • pg_ctl to start/stop/restart and status commands (https://www.postgresql.org/docs/9.1/static/app-pg-ctl.html)
        • /usr/local/pgsql/bin/pg_ctl restart -D /usr/local/pgsql/data -l logfile
        • /usr/local/pgsql/bin/pg_ctl status -D /usr/local/pgsql/data
      • vi /usr/local/pgsql/data/postgresql.conf --> update the listen_addresses to reach from outside network. suggested to update the port number too.
      • or use ssh tunel. first connect to server and then connect to server localy
    • GEOS, PROJ.4, GDAL, GeoIp

      • Pre libs
        • sudo apt-get install binutils libproj-dev gdal-bin
        • sudo apt-get install python-gdal libgeoip1 libgeoip-dev
    • Install GEOS

    • Install Proj4

    • Install GDAL (this installation will take time)

    • Install Posgris

    • Connected to Database

      • /usr/local/pgsql/bin/psql
      • give a password to postgrey user --> ALTER USER postgres PASSWORD '123456';
      • update config files
        • vi /usr/local/pgsql/data/postgresql.conf
          • listen_addresses = '*'
        • vi /usr/local/pgsql/data/pg_hba.conf
          • add following line at the end of the file
          • host db postgres 192.168.10.1/32 password
        • restart postgressql with command below
        • /usr/local/pgsql/bin/pg_ctl restart -D /usr/local/pgsql/data -l postgreysql.log
  • Sample Place data use upload_nearby script

    • first create a superuser
    • python manage.py createsuperuser
    • python upload_nearby_restaurants.py 40.6762531 -73.89776999999998 800
    • 800 meters is radius

nearapp-web's People

Contributors

aykutgk avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.