Giter VIP home page Giter VIP logo

norloc's Introduction

Development

Backend

$ sudo apt install binutils libproj-dev gdal-bin postgresql-client-common
$ pip3 install pipenv
$ export PATH="$PATH:/home/user/.local/bin"
$ cd backend/
$ python3 -m venv .venv
$ source .venv/bin/activate
$ pip install wheel
$ pip install -r requirements.txt

$ python manage.py makemigrations locations productions people
$ python manage.py migrate
$ python manage.py createsuperuser

$ python manage.py runserver

Database

$ docker pull kartoza/postgis:13

$ docker run -d -t \
    --name "postgis" \
    -p 25432:5432 \
    -e POSTGRES_USER=postgres \
    -e POSTGRES_PASS=postgres \
    kartoza/postgis:13

$ apt install postgresql-client-13

$ pg_isready -h localhost -p 25432 -U postgres

$ psql -h localhost -p 25432 -U postgres -f initdb.sql 

Backup and restore

$ pg_dump -h localhost -p 25432 -U postgres \
    --format=t \
    --file norloc_db.tar \
    --create \
    norloc

$ tar -xvf norloc_db.tar restore.sql # extract sql file

$ pg_restore -h localhost -p 25432 -U postgres \
    --dbname=norloc \
    norloc_db.tar

Frontend

$ cd frontend/
$ npm install
$ npm run dev

Built using

Resources

Deployment

Database

Setup

$ sudo apt update
$ sudo apt -y install postgresql postgresql-contrib postgis # Install PostgreSQL and PostGIS

$ sudo -u postgres createuser --interactive # Create role
Enter name of role to add: norloc
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) n

$ sudo -u postgres createdb norloc # Create database
$ sudo -u postgres psql
postgres=# \c norloc
norloc=# CREATE EXTENSION postgis; # Enable PostGIS
$ sudo adduser norloc
$ sudo -u norloc psql
norloc=> \conninfo  --: Connection info
norloc=> \du        --: List roles
norloc=> \dt        --: List relations
$ sudo nano /etc/postgresql/9.1/main/pg_hba.conf # Ensure remote connection is disabled (default)

Backend

$ sudo apt -y install libpython3.8 python3.8-venv
$ sudo apt -y install build-essential libpq-dev python-dev # Install dependencies for using PostgresSQL
$ sudo apt -y install nginx supervisor
$ pip install --user pipenv
$ cd apps/
$ git clone ....
$ cd norloc/backend/

$ pipenv install
$ pipenv install gunicorn
$ pipenv shell

$ python manage.py migrate
$ python manage.py collectstatic
$ python manage.py runserver 0.0.0.0:8000   # Test

Supervisor/Gunicorn

$ sudo systemctl enable supervisor
$ sudo systemctl start supervisor

$ mkdir /home/norloc/logs
$ touch /home/norloc/logs/gunicorn-error.log

/home/norloc/bin/norloc_start

#!/bin/bash

NAME="norloc"
DIR=/home/norloc/app/norloc/backend
USER=norloc
GROUP=norloc
WORKERS=3
BIND=unix:/home/norloc/app/norloc.sock
DJANGO_SETTINGS_MODULE=norloc.settings
DJANGO_WSGI_MODULE=norloc.wsgi
LOG_LEVEL=error

cd $DIR

export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DIR:$PYTHONPATH

exec /home/norloc/.local/bin/pipenv run gunicorn ${DJANGO_WSGI_MODULE}:application \
  --name $NAME \
  --workers $WORKERS \
  --user=$USER \
  --group=$GROUP \
  --bind=$BIND \
  --log-level=$LOG_LEVEL \
  --log-file=-
$ chmod u+x /home/norloc/bin/norloc_start

/etc/supervisor/conf.d/norloc.conf

[program:norloc]
command=/home/norloc/app/norloc/backend/bin/gunicorn
user=norloc
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/home/norloc/logs/gunicorn-error.log
$ sudo supervisorctl reread
$ sudo supervisorctl update
$ sudo supervisorctl status norloc
$ sudo supervisorctl restart norloc

nginx

upstream app_server {
    server unix:/home/norloc/app/norloc/run/gunicorn.sock fail_timeout=0;
}
server {
    location /static/ {
        alias /home/norloc/app/norloc/backend/static/;
    }
    location / {
        try_files $uri @proxy_to_app;
    }
    location @proxy_to_app {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://app_server;
    }
}

Updating

$ cd apps/norloc/
$ pipenv shell
$ git pull origin master
$ pipenv install
$ python manage.py migrate
$ python manage.py collectstatic
$ sudo supervisorctl restart norloc

References

norloc's People

Contributors

petterhj avatar

Watchers

 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.