mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-06-21 05:20:36 +00:00
Next big config update. Check the .env.tpl and db.env.tpl
This commit is contained in:
@ -14,7 +14,6 @@ RUN apt-get update \
|
||||
&& apt-get install --no-install-recommends --yes \
|
||||
build-essential \
|
||||
libpq-dev \
|
||||
wait-for-it \
|
||||
&& rm -r /var/lib/apt/lists/*
|
||||
|
||||
|
||||
@ -27,8 +26,7 @@ WORKDIR /home/nopaqued
|
||||
|
||||
COPY --chown=nopaqued:nopaqued [".", "."]
|
||||
RUN python -m venv venv \
|
||||
&& venv/bin/pip install --requirement requirements.txt \
|
||||
&& mkdir logs
|
||||
&& venv/bin/pip install --requirement requirements.txt
|
||||
|
||||
|
||||
ENTRYPOINT ["./boot.sh"]
|
||||
|
30
daemon/app/__init__.py
Normal file
30
daemon/app/__init__.py
Normal file
@ -0,0 +1,30 @@
|
||||
from config import config
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import scoped_session, sessionmaker
|
||||
from time import sleep
|
||||
import docker
|
||||
import os
|
||||
|
||||
|
||||
configuration = config[os.environ.get('NOPAQUE_CONFIG', 'development')]
|
||||
docker_client = docker.from_env()
|
||||
engine = create_engine(configuration.SQLALCHEMY_DATABASE_URI)
|
||||
Session = scoped_session(sessionmaker(bind=engine))
|
||||
|
||||
|
||||
def run():
|
||||
from .tasks.check_corpora import check_corpora
|
||||
check_corpora_thread = check_corpora()
|
||||
from .tasks.check_jobs import check_jobs
|
||||
check_jobs_thread = check_jobs()
|
||||
from .tasks.notify import notify
|
||||
notify_thread = notify()
|
||||
|
||||
while True:
|
||||
if not check_corpora_thread.is_alive():
|
||||
check_corpora_thread = check_corpora()
|
||||
if not check_jobs_thread.is_alive():
|
||||
check_jobs_thread = check_jobs()
|
||||
if not notify_thread.is_alive():
|
||||
notify_thread = notify()
|
||||
sleep(3)
|
@ -1,6 +1,7 @@
|
||||
from . import config, docker_client, Session
|
||||
from .decorators import background
|
||||
from .models import Corpus
|
||||
from .. import configuration as config
|
||||
from .. import docker_client, Session
|
||||
from ..decorators import background
|
||||
from ..models import Corpus
|
||||
import docker
|
||||
import logging
|
||||
import os
|
@ -1,7 +1,8 @@
|
||||
from datetime import datetime
|
||||
from . import config, docker_client, Session
|
||||
from .decorators import background
|
||||
from .models import Job, JobResult, NotificationData, NotificationEmailData
|
||||
from .. import configuration as config
|
||||
from .. import docker_client, Session
|
||||
from ..decorators import background
|
||||
from ..models import Job, JobResult, NotificationData, NotificationEmailData
|
||||
import docker
|
||||
import logging
|
||||
import json
|
0
daemon/app/tasks/libnotify/__init__.py
Normal file
0
daemon/app/tasks/libnotify/__init__.py
Normal file
@ -1,13 +1,18 @@
|
||||
from notify.notification import Notification
|
||||
from notify.service import NotificationService
|
||||
from sqlalchemy import asc
|
||||
from . import config, Session
|
||||
from .decorators import background
|
||||
from .models import NotificationEmailData
|
||||
from .libnotify.notification import Notification
|
||||
from .libnotify.service import NotificationService
|
||||
from .. import configuration as config
|
||||
from .. import Session
|
||||
from ..decorators import background
|
||||
from ..models import NotificationEmailData
|
||||
import logging
|
||||
import os
|
||||
import smtplib
|
||||
|
||||
|
||||
ROOT_DIR = os.path.abspath(os.path.dirname(__file__))
|
||||
|
||||
|
||||
@background
|
||||
def notify():
|
||||
session = Session()
|
||||
@ -72,8 +77,10 @@ def __create_mail_notifications(notification_service, session):
|
||||
'status': data.notify_status,
|
||||
'time': data.creation_date,
|
||||
'url': url}
|
||||
txt_tmplt = 'notify/templates/notification_messages/notification.txt'
|
||||
html_tmplt = 'notify/templates/notification_messages/notification.html'
|
||||
txt_tmplt = os.path.join(ROOT_DIR,
|
||||
'libnotify/templates/notification.txt')
|
||||
html_tmplt = os.path.join(ROOT_DIR,
|
||||
'libnotify/templates/notification.html')
|
||||
notification.set_notification_content(subject_template,
|
||||
subject_template_values_dict,
|
||||
txt_tmplt,
|
@ -1,8 +1,3 @@
|
||||
#!/bin/bash
|
||||
echo "Waiting for db..."
|
||||
wait-for-it "${NOPAQUE_DB_HOST}:${NOPAQUE_DB_PORT:-5432}" --strict --timeout=0
|
||||
echo "Waiting for nopaque..."
|
||||
wait-for-it nopaque:5000 --strict --timeout=0
|
||||
|
||||
source venv/bin/activate
|
||||
python nopaqued.py
|
||||
|
102
daemon/config.py
102
daemon/config.py
@ -2,60 +2,70 @@ import logging
|
||||
import os
|
||||
|
||||
|
||||
root_dir = os.path.abspath(os.path.dirname(__file__))
|
||||
|
||||
|
||||
DEFAULT_DATA_DIR = os.path.join('/mnt/nopaque')
|
||||
DEFAULT_DB_PORT = '5432'
|
||||
DEFAULT_DOMAIN = 'localhost'
|
||||
DEFAULT_LOG_DATE_FORMAT = '%Y-%m-%d %H:%M:%S'
|
||||
DEFAULT_LOG_FILE = os.path.join(root_dir, 'nopaqued.log')
|
||||
DEFAULT_LOG_FORMAT = ('[%(asctime)s] %(levelname)s in %(pathname)s '
|
||||
'(function: %(funcName)s, line: %(lineno)d): '
|
||||
'%(message)s')
|
||||
DEFAULT_LOG_LEVEL = 'ERROR'
|
||||
DEFAULT_MAIL_USE_SSL = 'False'
|
||||
DEFAULT_MAIL_USE_TLS = 'False'
|
||||
DEFAULT_PROTOCOL = 'http'
|
||||
ROOT_DIR = os.path.abspath(os.path.dirname(__file__))
|
||||
|
||||
|
||||
class Config:
|
||||
''' ### Database ### '''
|
||||
DB_HOST = os.environ.get('NOPAQUE_DB_HOST')
|
||||
DB_NAME = os.environ.get('NOPAQUE_DB_NAME')
|
||||
DB_PASSWORD = os.environ.get('NOPAQUE_DB_PASSWORD')
|
||||
DB_PORT = os.environ.get('NOPAQUE_DB_PORT', DEFAULT_DB_PORT)
|
||||
DB_USERNAME = os.environ.get('NOPAQUE_DB_USERNAME')
|
||||
SQLALCHEMY_DATABASE_URI = 'postgresql://{}:{}@{}:{}/{}'.format(
|
||||
DB_USERNAME, DB_PASSWORD, DB_HOST, DB_PORT, DB_NAME)
|
||||
|
||||
''' ### SMTP ### '''
|
||||
''' # Email # '''
|
||||
SMTP_DEFAULT_SENDER = os.environ.get('NOPAQUE_SMTP_DEFAULT_SENDER')
|
||||
SMTP_PASSWORD = os.environ.get('NOPAQUE_SMTP_PASSWORD')
|
||||
SMTP_PORT = os.environ.get('NOPAQUE_SMTP_PORT')
|
||||
SMTP_PORT = int(os.environ.get('NOPAQUE_SMTP_PORT'))
|
||||
SMTP_SERVER = os.environ.get('NOPAQUE_SMTP_SERVER')
|
||||
SMTP_USERNAME = os.environ.get('NOPAQUE_SMTP_USERNAME')
|
||||
SMTP_USE_SSL = os.environ.get('NOPAQUE_SMTP_USE_SSL',
|
||||
DEFAULT_MAIL_USE_SSL).lower() == 'true'
|
||||
SMTP_USE_TLS = os.environ.get('NOPAQUE_SMTP_USE_TLS',
|
||||
DEFAULT_MAIL_USE_TLS).lower() == 'true'
|
||||
SMTP_USE_SSL = os.environ.get(
|
||||
'NOPAQUE_SMTP_USE_SSL', 'false').lower() == 'true'
|
||||
SMTP_USE_TLS = os.environ.get(
|
||||
'NOPAQUE_SMTP_USE_TLS', 'false').lower() == 'true'
|
||||
|
||||
''' ### General ### '''
|
||||
DATA_DIR = os.environ.get('NOPAQUE_DATA_DIR', DEFAULT_DATA_DIR)
|
||||
DOMAIN = os.environ.get('NOPAQUE_DOMAIN', DEFAULT_DOMAIN)
|
||||
PROTOCOL = os.environ.get('NOPAQUE_PROTOCOL', DEFAULT_PROTOCOL)
|
||||
''' # General # '''
|
||||
DATA_DIR = os.environ.get('NOPAQUE_DATA_DIR', '/mnt/nopaque')
|
||||
DOMAIN = os.environ.get('NOPAQUE_DOMAIN', 'localhost')
|
||||
PROTOCOL = os.environ.get('NOPAQUE_PROTOCOL', 'http')
|
||||
SECRET_KEY = os.environ.get('NOPAQUE_SECRET_KEY', 'hard to guess string')
|
||||
|
||||
''' ### Logging ### '''
|
||||
''' # Logging # '''
|
||||
LOG_DATE_FORMAT = os.environ.get('NOPAQUE_LOG_DATE_FORMAT',
|
||||
DEFAULT_LOG_DATE_FORMAT)
|
||||
LOG_FILE = os.environ.get('NOPAQUE_DAEMON_LOG_FILE', DEFAULT_LOG_FILE)
|
||||
LOG_FORMAT = os.environ.get('NOPAQUE_LOG_FORMAT', DEFAULT_LOG_FORMAT)
|
||||
LOG_LEVEL = os.environ.get('NOPAQUE_LOG_LEVEL', DEFAULT_LOG_LEVEL)
|
||||
'%Y-%m-%d %H:%M:%S')
|
||||
LOG_FILE = os.environ.get('NOPAQUED_LOG_FILE',
|
||||
os.path.join(ROOT_DIR, 'nopaqued.log'))
|
||||
LOG_FORMAT = os.environ.get(
|
||||
'NOPAQUE_LOG_FORMAT',
|
||||
'[%(asctime)s] %(levelname)s in '
|
||||
'%(pathname)s (function: %(funcName)s, line: %(lineno)d): %(message)s'
|
||||
)
|
||||
LOG_LEVEL = os.environ.get('NOPAQUE_LOG_LEVEL', 'WARNING')
|
||||
|
||||
def init_app(self):
|
||||
# Configure logging according to the corresponding (LOG_*) config
|
||||
# entries
|
||||
logging.basicConfig(datefmt=self.LOG_DATE_FORMAT,
|
||||
filename=self.LOG_FILE,
|
||||
format=self.LOG_FORMAT,
|
||||
level=self.LOG_LEVEL)
|
||||
@classmethod
|
||||
def init(cls):
|
||||
# Set up logging according to the corresponding (LOG_*) variables
|
||||
logging.basicConfig(datefmt=cls.LOG_DATE_FORMAT,
|
||||
filename=cls.LOG_FILE,
|
||||
format=cls.LOG_FORMAT,
|
||||
level=cls.LOG_LEVEL)
|
||||
|
||||
|
||||
class DevelopmentConfig(Config):
|
||||
''' # Database # '''
|
||||
SQLALCHEMY_DATABASE_URI = os.environ.get(
|
||||
'NOPAQUE_DEV_DATABASE_URL',
|
||||
'sqlite:///' + os.path.join(ROOT_DIR, 'data-dev.sqlite')
|
||||
)
|
||||
|
||||
|
||||
class ProductionConfig(Config):
|
||||
''' # Database # '''
|
||||
SQLALCHEMY_DATABASE_URI = os.environ.get(
|
||||
'NOPAQUE_DATABASE_URL',
|
||||
'sqlite:///' + os.path.join(ROOT_DIR, 'data.sqlite')
|
||||
)
|
||||
|
||||
|
||||
class TestingConfig(Config):
|
||||
''' # Database # '''
|
||||
SQLALCHEMY_DATABASE_URI = os.environ.get(
|
||||
'NOPAQUE_TEST_DATABASE_URL', 'sqlite://')
|
||||
|
||||
|
||||
config = {'development': DevelopmentConfig,
|
||||
'production': ProductionConfig,
|
||||
'testing': TestingConfig}
|
||||
|
@ -1,23 +1,13 @@
|
||||
from tasks.check_corpora import check_corpora
|
||||
from tasks.check_jobs import check_jobs
|
||||
from tasks.notify import notify
|
||||
from time import sleep
|
||||
from dotenv import load_dotenv
|
||||
from app import run
|
||||
import os
|
||||
|
||||
|
||||
def nopaqued():
|
||||
check_corpora_thread = check_corpora()
|
||||
check_jobs_thread = check_jobs()
|
||||
notify_thread = notify()
|
||||
|
||||
while True:
|
||||
if not check_corpora_thread.is_alive():
|
||||
check_corpora_thread = check_corpora()
|
||||
if not check_jobs_thread.is_alive():
|
||||
check_jobs_thread = check_jobs()
|
||||
if not notify_thread.is_alive():
|
||||
notify_thread = notify()
|
||||
sleep(3)
|
||||
# Load environment variables
|
||||
DOTENV_FILE = os.path.join(os.path.dirname(__file__), '.env')
|
||||
if os.path.exists(DOTENV_FILE):
|
||||
load_dotenv(DOTENV_FILE)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
nopaqued()
|
||||
run()
|
||||
|
@ -1,3 +1,4 @@
|
||||
docker
|
||||
psycopg2
|
||||
python-dotenv
|
||||
SQLAlchemy
|
||||
|
@ -1,11 +0,0 @@
|
||||
from config import Config
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import scoped_session, sessionmaker
|
||||
import docker
|
||||
|
||||
|
||||
config = Config()
|
||||
config.init_app()
|
||||
docker_client = docker.from_env()
|
||||
engine = create_engine(config.SQLALCHEMY_DATABASE_URI)
|
||||
Session = scoped_session(sessionmaker(bind=engine))
|
Reference in New Issue
Block a user