Skip to content

Commit

Permalink
automatic migration; extended configuration via environment variables…
Browse files Browse the repository at this point in the history
…; fixed a bug in Tasks.vue
  • Loading branch information
TheMrSheldon committed Sep 13, 2024
1 parent ac2b27a commit f49dd0d
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 36 deletions.
2 changes: 1 addition & 1 deletion application/Dockerfile.prod
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ RUN <<EOF
export PATH="/home/tira/.local/bin:$PATH"

# Install dependencies
pip3 install -q --no-cache-dir --user ../python-client .[test,deploy]
pip3 install -q --no-cache-dir --user ../python-client .[test,deploy,postgreqsql]

chmod +x ./src/tira_app/endpoints/aha # FIXME; aha is not copied to the Production Container

Expand Down
12 changes: 6 additions & 6 deletions application/config/tira-application-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ grpc_host: local
host_grpc_port: 50051
application_grpc_port: 50052
database:
engine: django.db.backends.sqlite3 # django.db.backends.mysql or django.db.backends.sqlite3
name: tira # when backend is sqlite, this will be the name of the database below TIRA_ROOT/state
user: tira # ignored when using sqlite3
password: TODO-ENTER-PASSWORD # ignored when using sqlite3
host: tira-mariadb # ignored when using sqlite3
port: 3306 # ignored when using sqlite3
engine: !ENV ${TIRA_DB_ENGINE:django.db.backends.sqlite3} # django.db.backends.mysql or django.db.backends.sqlite3
name: !ENV ${TIRA_DB_NAME:tira} # when backend is sqlite, this will be the name of the database below TIRA_ROOT/state
user: !ENV ${TIRA_DB_USER:tira} # ignored when using sqlite3
password: !ENV ${TIRA_DB_PASSWORD} # ignored when using sqlite3
host: !ENV ${TIRA_DB_HOST:tira-mariadb} # ignored when using sqlite3
port: !ENV ${TIRA_DB_PORT:3306} # ignored when using sqlite3
github_token: !ENV ${TIRA_GITHUB_TOKEN}
discourse_api_url: !ENV ${DISCOURSE_API_URL:https://www.tira.io}
6 changes: 6 additions & 0 deletions application/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,9 @@ HF_HOME = "./tira-root/huggingface"
TIRA_ROOT = "./tira-root"
TIRA_CONFIG = "../config/tira-application-config.yml"
TIRA_DEBUG = true
TIRA_DB_ENGINE = "django.db.backends.sqlite3"
TIRA_DB_NAME = "test-database/sqlite3"
TIRA_DB_USER = "tira"
TIRA_DB_PASSWORD = "replace-with-db-password"
TIRA_DB_HOST = "tira-mariadb"
TIRA_DB_PORT = 3306
2 changes: 2 additions & 0 deletions application/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ dev =
mypy
deploy =
uwsgi
postgreqsql =
psycopg2-binary

[options.packages.find]
where = src
Expand Down
25 changes: 13 additions & 12 deletions application/src/django_admin/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@
config = parse_config(cfgpath, default_value=None, loader=yaml.FullLoader)
custom_settings.update(config)

if "database" not in custom_settings:
custom_settings["database"] = {}
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = str2bool(custom_settings["debug"])

if DEBUG:
logging.basicConfig(level=logging.DEBUG, force=True)

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
Expand All @@ -40,8 +43,6 @@
SECRET_KEY = custom_settings["django_secret"]


# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = str2bool(custom_settings["debug"])
ALLOWED_HOSTS = custom_settings["allowed_hosts"]

TIRA_ROOT = Path(custom_settings["tira_root"])
Expand All @@ -55,17 +56,17 @@
APPLICATION_GRPC_PORT = custom_settings.get("application_grpc_port", "50052")
GRPC_HOST = custom_settings.get("grpc_host", "local") # can be local or remote
TIRA_DB_NAME = (
Path(TIRA_ROOT / "state") / f"{custom_settings['database'].get('name', 'tira')}.sqlite3"
if custom_settings["database"].get("engine", "django.db.backends.sqlite3") == "django.db.backends.sqlite3"
else custom_settings["database"].get("name", "tira")
Path(TIRA_ROOT / "state") / f"{custom_settings['database']['name']}.sqlite3"
if custom_settings["database"]["engine"] == "django.db.backends.sqlite3"
else custom_settings["database"]["name"]
)
TIRA_DB = {
"ENGINE": custom_settings["database"].get("engine", "django.db.backends.sqlite3"),
"ENGINE": custom_settings["database"]["engine"],
"NAME": TIRA_DB_NAME,
"USER": custom_settings["database"].get("user", "tira"),
"PASSWORD": custom_settings["database"].get("password", "replace-with-db-password"),
"HOST": custom_settings["database"].get("host", "tira-mariadb"),
"PORT": int(custom_settings["database"].get("port", 3306)),
"USER": custom_settings["database"]["user"],
"PASSWORD": custom_settings["database"]["password"],
"HOST": custom_settings["database"]["host"],
"PORT": int(custom_settings["database"]["port"]),
"TEST": {
"NAME": "test_tira",
"ENGINE": "django.db.backends.sqlite3",
Expand Down
4 changes: 4 additions & 0 deletions application/src/django_admin/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@

import os

from django.core.management import call_command
from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_admin.settings")

application = get_wsgi_application()

# https://stackoverflow.com/a/58182766
call_command("migrate")
23 changes: 13 additions & 10 deletions application/test/settings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,19 @@
config = parse_config(cfgpath, default_value=None, loader=yaml.FullLoader)
custom_settings.update(config)

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = str2bool(custom_settings["debug"])

if DEBUG:
logging.basicConfig(level=logging.DEBUG, force=True)

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = custom_settings["django_secret"]


# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = str2bool(custom_settings["debug"])
ALLOWED_HOSTS = custom_settings["allowed_hosts"]

TIRA_ROOT = Path(custom_settings["tira_root"])
Expand All @@ -51,14 +55,14 @@
HOST_GRPC_PORT = custom_settings.get("host_grpc_port", "50051")
APPLICATION_GRPC_PORT = custom_settings.get("application_grpc_port", "50052")
GRPC_HOST = custom_settings.get("grpc_host", "local") # can be local or remote

TIRA_DB_NAME = custom_settings["database"]["name"]
TIRA_DB = {
"ENGINE": "django.db.backends.sqlite3",
"NAME": "test-database/sqlite3",
"USER": "tira",
"PASSWORD": "replace-with-db-password",
"HOST": "tira-mariadb",
"PORT": 3306,
"ENGINE": custom_settings["database"]["engine"],
"NAME": TIRA_DB_NAME,
"USER": custom_settings["database"]["user"],
"PASSWORD": custom_settings["database"]["password"],
"HOST": custom_settings["database"]["host"],
"PORT": int(custom_settings["database"]["port"]),
"TEST": {
"NAME": "test_tira",
"ENGINE": "django.db.backends.sqlite3",
Expand All @@ -72,7 +76,6 @@
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django_extensions",
"django_filters",
"rest_framework",
"rest_framework_json_api",
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/Tasks.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<template>
<tira-breadcrumb />
<loading :loading="task_list.length === 0" />
<loading :loading="task_list === undefined" />

<v-container v-if="task_list.length > 0">
<v-container v-if="task_list !== undefined">
<h3 class="text-h3 py-5">Choose a Task</h3>
<div class="py-5"></div>
<div class="d-flex">
Expand Down Expand Up @@ -101,7 +101,7 @@ export default {
{ title: 'Subs', key: 'software_count' },
{ text: 'Description', value: 'data-table-expand' },
],
task_list: [] as Task[],
task_list: undefined as (Task[] | undefined),
}
},
methods: {
Expand Down
4 changes: 0 additions & 4 deletions python-client/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,3 @@ run-tests:
docker run -u root --rm -v /var/run/docker.sock:/var/run/docker.sock -v ${PWD}:/app -w /app --entrypoint pytest webis/tira:python-client-dev-0.0.5
docker run -u root --rm -v /var/run/docker.sock:/var/run/docker.sock -v ${PWD}:/app -w /app --entrypoint pytest webis/tira:python-client-dev-0.0.5-python3.7
docker run -u root --rm -v /var/run/docker.sock:/run/user/0/podman/podman.sock -v ${PWD}:/app -w /app --entrypoint pytest webis/tira:python-client-dev-0.0.5-python3.7

docs:
docker run --rm -ti -v ${PWD}:/app -w /app webis/tira:python-client-dev-0.0.3 bash -c \
'sphinx-apidoc -o docs tira/ && cd docs && make html'

0 comments on commit f49dd0d

Please sign in to comment.