diff --git a/application/.dockerignore b/application/.dockerignore index 6392292d9..bac451f72 100644 --- a/application/.dockerignore +++ b/application/.dockerignore @@ -7,6 +7,7 @@ Makefile README.md test/tira-root +.data-dumps # Gitignore contentn diff --git a/application/Dockerfile.prod b/application/Dockerfile.prod index 2051ab26f..b8ff0f861 100644 --- a/application/Dockerfile.prod +++ b/application/Dockerfile.prod @@ -12,7 +12,7 @@ FROM debian:stable-slim AS build ENV TZ=Europe/Berlin RUN < /etc/timezone -apt-get update && apt-get install -y locales +apt-get -qq update && apt-get -qq install -y locales echo "en_US.UTF-8 UTF-8" | tee -a /etc/locale.gen && locale-gen EOF @@ -38,21 +38,21 @@ ENV PIP_BREAK_SYSTEM_PACKAGES=1 ENV GRPC_PYTHON_BUILD_EXT_COMPILER_JOBS=16 RUN < /etc/timezone -apt-get update && apt-get install -y locales +apt-get -qq update && apt-get -qq install -y locales echo "en_US.UTF-8 UTF-8" | tee -a /etc/locale.gen && locale-gen # Tools -apt-get install -y python3 +apt-get -qq install -y python3 python3-dev # mkdir -p /tira/application/src chown -R tira:tira /tira @@ -98,7 +99,7 @@ USER tira ENV PATH=/home/tira/.local/bin:$PATH # CONFIGURE THE FOLLOWING ENVIRONMENT VARIABLES IN YOUR DOCKER-COMPOSE FILE ENV HF_HOME=/home/tira/data/publicly-shared-datasets/huggingface/ -ENV TIRA_CONFIG=/tira/config/tira-application-config.docker.yml +ENV TIRA_CONFIG=/tira/config/tira-application-config.yml ENV TIRA_DEBUG=false EXPOSE 80 diff --git a/application/config/tira-application-config.yml b/application/config/tira-application-config.yml index c8f0f1175..c53ec410a 100644 --- a/application/config/tira-application-config.yml +++ b/application/config/tira-application-config.yml @@ -1,5 +1,5 @@ # ---task/celebrity-profiling/user/hodge20a -debug: ${TIRA_DEBUG:false} +debug: !ENV ${TIRA_DEBUG:false} allowed_hosts: - "127.0.0.1" django_secret: "not-so-secret" diff --git a/application/pyproject.toml b/application/pyproject.toml index fd76035bd..e32272d7a 100644 --- a/application/pyproject.toml +++ b/application/pyproject.toml @@ -1,8 +1,8 @@ [tool.black] line-length = 120 exclude = '''/( - src/tira/migrations - | src/tira/proto + src/tira_app/migrations + | src/tira_app/proto )''' [tool.isort] @@ -11,8 +11,8 @@ multi_line_output = 3 line_length = 120 include_trailing_comma = true skip = [ - "src/tira/migrations", - "src/tira/proto", + "src/tira_app/migrations", + "src/tira_app/proto", ] [tool.mypy] @@ -21,8 +21,8 @@ explicit_package_bases = true ignore_missing_imports = true install_types = true exclude = [ - "^src/tira/proto/.*\\.py$", - "^src/tira/migrations/.*\\.py$", + "^src/tira_app/proto/.*\\.py$", + "^src/tira_app/migrations/.*\\.py$", ] [tool.pytest.ini_options] @@ -32,4 +32,6 @@ python_files = "test_*.py" [tool.pytest_env] HF_HOME = "./tira-root/huggingface" -TIRA_ROOT = "./tira-root" \ No newline at end of file +TIRA_ROOT = "./tira-root" +TIRA_CONFIG = "../config/tira-application-config.yml" +TIRA_DEBUG = true diff --git a/application/src/django_admin/settings.py b/application/src/django_admin/settings.py index 0c3b978b4..510005f3f 100644 --- a/application/src/django_admin/settings.py +++ b/application/src/django_admin/settings.py @@ -19,13 +19,15 @@ import yaml from pyaml_env import parse_config +from tira_app.util import str2bool + # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent custom_settings = {} cfgpath = os.environ.get("TIRA_CONFIG", str(BASE_DIR / "config" / "tira-application-config.yml")) logging.info(f"Load settings from {cfgpath}.") -config = parse_config(cfgpath, default_value=None) +config = parse_config(cfgpath, default_value=None, loader=yaml.FullLoader) custom_settings.update(config) if "database" not in custom_settings: @@ -39,7 +41,7 @@ # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = custom_settings["debug"] +DEBUG = str2bool(custom_settings["debug"]) ALLOWED_HOSTS = custom_settings["allowed_hosts"] TIRA_ROOT = Path(custom_settings["tira_root"]) @@ -95,6 +97,7 @@ REST_FRAMEWORK = { "DEFAULT_AUTHENTICATION_CLASSES": ("tira_app.authentication.TrustedHeaderAuthentication",), "DEFAULT_FILTER_BACKENDS": ("rest_framework_json_api.django_filters.DjangoFilterBackend",), + "DEFAULT_RENDERER_CLASSES": ("rest_framework.renderers.JSONRenderer",), } ROOT_URLCONF = "django_admin.urls" diff --git a/application/src/tira_app/endpoints/misc.py b/application/src/tira_app/endpoints/misc.py index 2b5435c6a..2298cd2ab 100644 --- a/application/src/tira_app/endpoints/misc.py +++ b/application/src/tira_app/endpoints/misc.py @@ -7,9 +7,7 @@ from rest_framework.decorators import api_view from rest_framework.request import Request from rest_framework.response import Response - -# TODO: this does not work so I hardcoded for now -# from tira import __version__ as tira_version +from tira import __version__ as tira_version tira_version = "0.0.136" rest_api_version = "v1.0.0-draft" diff --git a/application/src/tira_app/static/tira/css/tira-style.css b/application/src/tira_app/static/tira/css/tira-style.css deleted file mode 100644 index 7adacc84e..000000000 --- a/application/src/tira_app/static/tira/css/tira-style.css +++ /dev/null @@ -1,147 +0,0 @@ -.index-main-cover { - background: #323232 url("../img/background2.jpg") no-repeat top right; - background-size: 100%; - height: 250px; - width: 100%; - min-height: 200px; - font-size: 1.05rem; -} - -.index-main-cover h1 { - font-size: 2.65rem -} - -.cover-background-fade { - position: absolute; - top: 0; - bottom: 0; - left: 0; - right: 0; - background: linear-gradient(to bottom, rgba(0, 0, 0, 0.2) 0%, rgba(0, 0, 0, 0.2) 40%, rgba(0, 0, 0, 0.85) 85%) -} - -.dataset-detail-icon { - height: 15px; - width: 15px; - min-width: 20px; - min-height: 20px; -} - -.dropdown-scroll { - /*height: auto;*/ - max-height: calc(100vh - 52ex); - overflow-x: auto; - overflow-y: visible; -} - -.scrollable-table { - overflow-x: visible; - overflow-y: hidden; -} - -a.uk-button-primary { - color: #fff; -} - -.tira-content label { - display: inline; -} - -.uk-checkbox, .uk-radio{ - width: 16px !important; -} - -.uk-accordion table, .uk-card table { - border-collapse: inherit; -} - -.table-background-yellow { - background-color: #fff6ed; -} - -.table-background-yellow .uk-button { - border-color: darkorange; -} - -.table-background-red { - background-color: #ffe3e3; -} - -.table-background-red .uk-button{ - border-color: #a41515; -} - -.table-background-green { - background-color: #e5ffe3; -} - -.table-background-green .uk-button{ - border-color: #006b1b; -} - -.tira-button-selected, .tira-button-selected:hover { - border-color: #006b1b; - color: #006b1b; -} - -@keyframes flash-green-keyframes { - from {background-color: #006b1b;} - to {background-color: white;} -} - -@keyframes flash-red-keyframes { - from {background-color: darkred;} - to {background-color: white;} -} - -.flash-red { - animation-name: flash-red-keyframes; - animation-duration: 3s; -} - -.flash-green { - animation-name: flash-green-keyframes; - animation-duration: 3s; -} - -@media (max-width: 800px) { - .index-main-cover { - height: 200px - } -} - -@media (max-width: 400px) { - .index-main-cover { - height: 175px - } -} - -@media (max-width: 300px) { - .index-main-cover { - height: 150px - } -} - -@media (min-width: 960px) { - .index-main-cover { - height: 300px; - min-height: 200px; - } -} -/* strange disraptor hover fixes? */ -.disraptor-content .sortable:hover { - background-color: revert; -} -.disraptor-content .webis-data-table .sortable { - cursor: revert; -} - -.submit-button { - width: 100%; - border-radius: 5px; - margin-top: 5px; -} - -.hide-element { - display: none; -} diff --git a/application/src/tira_app/static/tira/img/background1.jpg b/application/src/tira_app/static/tira/img/background1.jpg deleted file mode 100644 index f40dfc3e0..000000000 Binary files a/application/src/tira_app/static/tira/img/background1.jpg and /dev/null differ diff --git a/application/src/tira_app/static/tira/img/background2.jpg b/application/src/tira_app/static/tira/img/background2.jpg deleted file mode 100644 index c90e49dd4..000000000 Binary files a/application/src/tira_app/static/tira/img/background2.jpg and /dev/null differ diff --git a/application/src/tira_app/static/tira/img/google-icon.png b/application/src/tira_app/static/tira/img/google-icon.png deleted file mode 100644 index 7c4c9f85f..000000000 Binary files a/application/src/tira_app/static/tira/img/google-icon.png and /dev/null differ diff --git a/application/src/tira_app/static/tira/img/ia-icon.png b/application/src/tira_app/static/tira/img/ia-icon.png deleted file mode 100644 index 4a5b2c67b..000000000 Binary files a/application/src/tira_app/static/tira/img/ia-icon.png and /dev/null differ diff --git a/application/src/tira_app/static/tira/img/image-licence.txt b/application/src/tira_app/static/tira/img/image-licence.txt deleted file mode 100644 index b27b52844..000000000 --- a/application/src/tira_app/static/tira/img/image-licence.txt +++ /dev/null @@ -1,2 +0,0 @@ -v1 - https://www.istockphoto.com/de/foto/blauen-und-wei%C3%9Fen-kirchen-von-oia-santorin-griechenland-gm164015369-23359009 -v2 - https://www.shutterstock.com/image-photo/sunset-oia-santorini-greece-1005762703 \ No newline at end of file diff --git a/application/src/tira_app/static/tira/img/logo-tira-32x32.png b/application/src/tira_app/static/tira/img/logo-tira-32x32.png deleted file mode 100644 index e69de29bb..000000000 diff --git a/application/src/tira_app/static/tira/img/logo-tira-40x40-transparent.png b/application/src/tira_app/static/tira/img/logo-tira-40x40-transparent.png deleted file mode 100644 index ae5bc7167..000000000 Binary files a/application/src/tira_app/static/tira/img/logo-tira-40x40-transparent.png and /dev/null differ diff --git a/application/src/tira_app/static/tira/img/logo-tira-40x40.png b/application/src/tira_app/static/tira/img/logo-tira-40x40.png deleted file mode 100644 index 3ead968de..000000000 Binary files a/application/src/tira_app/static/tira/img/logo-tira-40x40.png and /dev/null differ diff --git a/application/src/tira_app/static/tira/img/zenodo-icon.png b/application/src/tira_app/static/tira/img/zenodo-icon.png deleted file mode 100644 index 5578cb0a2..000000000 Binary files a/application/src/tira_app/static/tira/img/zenodo-icon.png and /dev/null differ diff --git a/application/src/tira_app/static/tira/js/review.js b/application/src/tira_app/static/tira/js/review.js deleted file mode 100644 index af2f29b67..000000000 --- a/application/src/tira_app/static/tira/js/review.js +++ /dev/null @@ -1,107 +0,0 @@ -let vm_id = null; -let dataset_id = null; -let run_id = null; - -// change view when blind state changes -function setBlindButton(blinded){ - if ( blinded === false ) { - $('#blind-button').show() - $('#blind-text').show() - $('#unblind-button').hide() - $('#unblind-text').hide() - } else { - $('#blind-button').hide() - $('#blind-text').hide() - $('#unblind-button').show() - $('#unblind-text').show() - } -} - -// change view when published state changes -function setPublishButton(published){ - if ( published === true ) { - $('#publish-button').hide(); - $('#publish-text').hide(); - $('#unpublish-button').show(); - $('#unpublish-text').show(); - } else { - $('#publish-button').show(); - $('#publish-text').show(); - $('#unpublish-button').hide(); - $('#unpublish-text').hide(); - } -} - -// when publish state changes: notify server and update view if successful -function publish(bool) { - $.ajax({ - type:"GET", - url: "/publish/" + vm_id + "/" + dataset_id + "/" + run_id + "/" + bool, - data: {}, - success: function( data ) - { - if(data.status === "0"){ - setPublishButton(data.published) - } - } - }) -} - -// when blind state changes: notify server and update view if successful -function blind(bool) { - $.ajax({ - type:"GET", - url: "/blind/" + vm_id + "/" + dataset_id + "/" + run_id + "/" + bool, - data:{}, - success: function( data ) - { - if(data.status === "0"){ - setBlindButton(data.blinded) - } - } - }) -} - -/* Init state and events for this page -* - initial state of blind, publish, and review -* - events for publishing and blinding -* - events to uncheck checkboxes -*/ -function addReviewEvents(p, b, vid, did, rid) { - vm_id = vid; - dataset_id =did; - run_id = rid; - p = p !== "False"; // Convert booleans to JS style - b = b !== "False"; - setPublishButton(p) - setBlindButton(b) - - $('#blind-button').click(function () { - blind(true) - }) - $('#unblind-button').click(function () { - blind(false) - }) - $('#publish-button').click(function () { - publish(true) - }) - $('#unpublish-button').click(function () { - publish(false) - }) - $('#no-error-checkbox').change(function () { - if(this.checked) { - $('#software-error-checkbox').prop('checked', false); - $('#output-error-checkbox').prop('checked', false); - } - }) - $('#software-error-checkbox').change(function () { - if(this.checked) { - $('#no-error-checkbox').prop('checked', false); - } - }) - $('#output-error-checkbox').change(function () { - if(this.checked) { - $('#no-error-checkbox').prop('checked', false); - } - }) -} \ No newline at end of file diff --git a/application/src/tira_app/templates/tira/base.html b/application/src/tira_app/templates/tira/base.html deleted file mode 100644 index 5b6f0c536..000000000 --- a/application/src/tira_app/templates/tira/base.html +++ /dev/null @@ -1,44 +0,0 @@ - -{% load static %} - - - {% block title %}{% endblock %} - - - - - - - - - - - - - - - - - - -
-{% block navbar %}{% endblock %} -{% block content %}{% endblock %} -
-
- - - - - diff --git a/application/src/tira_app/templates/tira/navbar.html b/application/src/tira_app/templates/tira/navbar.html deleted file mode 100644 index 86ea0f9b4..000000000 --- a/application/src/tira_app/templates/tira/navbar.html +++ /dev/null @@ -1,62 +0,0 @@ -{% load static %} -{% if include_navigation %} -
-
- - - - -
-
- - -{% endif %} \ No newline at end of file diff --git a/application/src/tira_app/tests/tests.py b/application/src/tira_app/tests/tests.py deleted file mode 100644 index bd3ace575..000000000 --- a/application/src/tira_app/tests/tests.py +++ /dev/null @@ -1,10 +0,0 @@ -from django.test import TestCase - - -class TestSetup(TestCase): - def setUp(self) -> None: - self.setup = True - - def test_setup_success(self): - """test if tests work""" - self.assertTrue(self.setup) diff --git a/application/src/tira_app/util.py b/application/src/tira_app/util.py index c6e707cf2..455956842 100644 --- a/application/src/tira_app/util.py +++ b/application/src/tira_app/util.py @@ -5,7 +5,6 @@ from django.conf import settings -from . import tira_model from .proto import TiraClientWebMessages_pb2 as modelpb logger = logging.getLogger("tira") @@ -114,6 +113,11 @@ def link_to_discourse_team(vm_id): def register_run(dataset_id, vm_id, run_id, software_id): + # import tira_model has to be done here since it has a side-effect with django and throws + # django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. + # if it is imported before django is launched otherwise. + from . import tira_model + path_for_run = Path(settings.TIRA_ROOT) / "data" / "runs" / dataset_id / vm_id / run_id with open(path_for_run / "run.prototext", "w") as f: @@ -191,3 +195,12 @@ def docker_image_details(image): ret = ret[0] image_id = ret["Id"] if ":" not in ret["Id"] else ret["Id"].split(":")[1] return {"image_id": image_id, "size": ret["Size"], "virtual_size": ret["VirtualSize"]} + + +def str2bool(text: str) -> bool: + """ + Extracts the boolean meaning of the given text. A string of the form "yes", "y", "true", "t", and "1" is + considered to express the boolean value True. The string may be in upper case as well (e.g., TRUE or True) and may + be surrounded by whitespaces. Any value that is not considered true, will return false. + """ + return text.strip().lower() in ("yes", "y", "true", "t", "1") diff --git a/application/test/settings_test.py b/application/test/settings_test.py index 0c0bbc597..472c5466b 100644 --- a/application/test/settings_test.py +++ b/application/test/settings_test.py @@ -19,13 +19,15 @@ import yaml from pyaml_env import parse_config +from tira_app.util import str2bool + # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent custom_settings = {} cfgpath = os.environ.get("TIRA_CONFIG", str(BASE_DIR / "config" / "tira-application-config.yml")) logging.info(f"Load settings from {cfgpath}.") -config = parse_config(cfgpath, default_value=None) +config = parse_config(cfgpath, default_value=None, loader=yaml.FullLoader) custom_settings.update(config) # Quick-start development settings - unsuitable for production @@ -36,10 +38,10 @@ # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = custom_settings["debug"] +DEBUG = str2bool(custom_settings["debug"]) ALLOWED_HOSTS = custom_settings["allowed_hosts"] -TIRA_ROOT = Path(custom_settings.get("tira_root", BASE_DIR / "test" / "tira-root")) +TIRA_ROOT = Path(custom_settings["tira_root"]) if not TIRA_ROOT.is_dir(): logging.warning(f"{TIRA_ROOT} does not exists and will be created now.") @@ -89,6 +91,7 @@ REST_FRAMEWORK = { "DEFAULT_AUTHENTICATION_CLASSES": ("tira_app.authentication.TrustedHeaderAuthentication",), "DEFAULT_FILTER_BACKENDS": ("rest_framework_json_api.django_filters.DjangoFilterBackend",), + "DEFAULT_RENDERER_CLASSES": ("rest_framework.renderers.JSONRenderer",), } ROOT_URLCONF = "django_admin.urls"