Add files for deployment. Make testing use memory-DB.

This commit is contained in:
Thomas L 2018-03-24 15:02:11 +01:00
parent 061fb62bdc
commit 751f9154cc
4 changed files with 39 additions and 9 deletions

10
db.py
View file

@ -2,7 +2,7 @@ from bottle import redirect, request
from functools import wraps from functools import wraps
from inspect import Signature from inspect import Signature
import jwt import jwt
from os import path, urandom from os import urandom
from pylibscrypt import scrypt_mcf, scrypt_mcf_check from pylibscrypt import scrypt_mcf, scrypt_mcf_check
import sqlite3 import sqlite3
import prepare import prepare
@ -10,11 +10,9 @@ from user import User
class DB(object): class DB(object):
def __init__(self): def __init__(self, dbfile):
self.config = prepare.get_config() self.config = prepare.get_config()
self.logger = prepare.get_logger(self.config) self.logger = prepare.get_logger(self.config)
dbfile = path.join(path.dirname(path.abspath(__file__)),
self.config['database']['db_path'])
self.conn = sqlite3.connect(dbfile) self.conn = sqlite3.connect(dbfile)
self.cur = self.conn.cursor() self.cur = self.conn.cursor()
self.create() self.create()
@ -149,8 +147,8 @@ class DBPlugin(object):
name = 'DBPlugin' name = 'DBPlugin'
api = 2 api = 2
def __init__(self, loginpage): def __init__(self, dbfile, loginpage):
self.db = DB() self.db = DB(dbfile)
self.loginpage = loginpage self.loginpage = loginpage
def close(self): def close(self):

View file

@ -0,0 +1,16 @@
[Unit]
Description=Ticketfrei Web Application
After=syslog.target network.target
[Service]
ExecStart=/usr/bin/uwsgi --ini /srv/ticketfrei/deployment/uwsgi.ini
# Requires systemd version 211 or newer
RuntimeDirectory=uwsgi
Restart=always
KillSignal=SIGQUIT
Type=notify
StandardError=syslog
NotifyAccess=all
[Install]
WantedBy=multi-user.target

11
deployment/uwsgi.ini Normal file
View file

@ -0,0 +1,11 @@
[uwsgi]
plugins = python3
master = true
uid = www-data
gid = www-data
processes = 1
# logto = /var/log/ticketfrei.log
socket = /var/run/ticketfrei/ticketfrei.sock
chmod-socket = 660
wsgi-file = /srv/ticketfrei/frontend.py
virtualenv = /srv/ticketfrei/venv

View file

@ -143,6 +143,11 @@ def login_mastodon(user):
return dict(error='Login to Mastodon failed.') return dict(error='Login to Mastodon failed.')
if __name__ == '__main__':
# testing only
bottle.install(DBPlugin(':memory:', '/'))
bottle.run(host='localhost', port=8080)
else:
config = prepare.get_config() config = prepare.get_config()
bottle.install(DBPlugin('/')) bottle.install(DBPlugin(config['database']['db_path'], '/'))
bottle.run(host=config['web']['host'], port=8080) application = bottle.default_app()