Skip to content

Filming locations for norwegian film- and TV-productions

Notifications You must be signed in to change notification settings

petterhj/norloc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Filming locations for norwegian film- and TV-productions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published