From 4e5444638af0a5165277407f290a153257a3a66c Mon Sep 17 00:00:00 2001 From: glass-ships Date: Wed, 14 Aug 2024 15:17:01 -0400 Subject: [PATCH 1/6] Reorganize and modernize repository --- .github/workflows/unittest.yml | 6 +- Dockerfile | 2 +- Makefile | 13 ++- README.md | 2 +- .../docker-compose.envlocal.yml | 6 +- .../nginx/docker-entrypoint.sh | 0 {config => deploy-config}/nginx/envlocal.conf | 0 docker-entrypoint.sh | 2 +- docs/developer/config_for_local_use.rst | 2 +- docs/developer/troubleshoot/unresponsive.rst | 4 +- src/{live_data_server => }/.coveragerc | 0 src/{live_data_server => }/__init__.py | 0 .../plots => apps}/__init__.py | 0 .../management => apps/plots}/__init__.py | 0 src/{live_data_server => apps}/plots/admin.py | 2 +- src/{live_data_server => apps}/plots/apps.py | 2 +- .../plots/management}/__init__.py | 0 .../plots/management/commands}/__init__.py | 0 .../management/commands/ensure_adminuser.py | 0 .../management/commands/purge_expired_data.py | 2 +- .../plots/migrations/0001_initial.py | 0 .../0002_datarun_expiration_date.py | 0 src/apps/plots/migrations/__init__.py | 0 .../plots/models.py | 0 src/{live_data_server => apps}/plots/tests.py | 0 src/{live_data_server => apps}/plots/urls.py | 1 - .../plots/view_util.py | 2 +- src/{live_data_server => apps}/plots/views.py | 2 +- .../live_data_server => config}/__init__.py | 0 .../live_data_server => config}/settings.py | 6 +- .../live_data_server => config}/urls.py | 2 +- .../live_data_server => config}/wsgi.py | 2 +- src/{live_data_server => }/manage.py | 2 +- test_client/test_client.py | 92 ------------------- tests/test_expiration.py | 4 +- tests/test_post_get.py | 2 +- 36 files changed, 34 insertions(+), 124 deletions(-) rename {config => deploy-config}/docker-compose.envlocal.yml (94%) rename {config => deploy-config}/nginx/docker-entrypoint.sh (100%) rename {config => deploy-config}/nginx/envlocal.conf (100%) rename src/{live_data_server => }/.coveragerc (100%) rename src/{live_data_server => }/__init__.py (100%) rename src/{live_data_server/plots => apps}/__init__.py (100%) rename src/{live_data_server/plots/management => apps/plots}/__init__.py (100%) rename src/{live_data_server => apps}/plots/admin.py (89%) rename src/{live_data_server => apps}/plots/apps.py (73%) rename src/{live_data_server/plots/management/commands => apps/plots/management}/__init__.py (100%) rename src/{live_data_server/plots/migrations => apps/plots/management/commands}/__init__.py (100%) rename src/{live_data_server => apps}/plots/management/commands/ensure_adminuser.py (100%) rename src/{live_data_server => apps}/plots/management/commands/purge_expired_data.py (90%) rename src/{live_data_server => apps}/plots/migrations/0001_initial.py (100%) rename src/{live_data_server => apps}/plots/migrations/0002_datarun_expiration_date.py (100%) create mode 100644 src/apps/plots/migrations/__init__.py rename src/{live_data_server => apps}/plots/models.py (100%) rename src/{live_data_server => apps}/plots/tests.py (100%) rename src/{live_data_server => apps}/plots/urls.py (87%) rename src/{live_data_server => apps}/plots/view_util.py (98%) rename src/{live_data_server => apps}/plots/views.py (98%) rename src/{live_data_server/live_data_server => config}/__init__.py (100%) rename src/{live_data_server/live_data_server => config}/settings.py (97%) rename src/{live_data_server/live_data_server => config}/urls.py (92%) rename src/{live_data_server/live_data_server => config}/wsgi.py (81%) rename src/{live_data_server => }/manage.py (68%) delete mode 100644 test_client/test_client.py diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index af84efb..6139562 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -41,7 +41,7 @@ jobs: - name: Start docker containers run: | - cp ./config/docker-compose.envlocal.yml docker-compose.yml + cp ./deploy-config/docker-compose.envlocal.yml docker-compose.yml docker compose up --build -d - name: Sleep, wait for containers to start up @@ -52,10 +52,10 @@ jobs: - name: Stop the coverage process # Stopping the coverage process allows the code coverage to be written to disk - run: docker exec live_data_server-livedata-1 /bin/bash -c "pkill coverage" + run: docker exec live_data_server-django-1 /bin/bash -c "pkill coverage" - name: Copy code coverage out of docker container - run: docker cp live_data_server-livedata-1:/var/www/livedata/app /tmp/ + run: docker cp live_data_server-django-1:/var/www/livedata/app /tmp/ - name: Combine and show code coverage shell: bash -l {0} diff --git a/Dockerfile b/Dockerfile index 5a46c28..91897e4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ WORKDIR /var/www/livedata COPY docker-entrypoint.sh /usr/bin/ -COPY src/live_data_server app +COPY src app RUN mkdir ./static RUN chmod +x /usr/bin/docker-entrypoint.sh diff --git a/Makefile b/Makefile index 26d3eb7..f8e21ff 100644 --- a/Makefile +++ b/Makefile @@ -33,15 +33,18 @@ docker/compose/validate: ## validate the version of the docker-compose command. @./scripts/docker-compose_validate.sh $(DOCKER_COMPOSE) docker/compose/local: docker/compose/validate ## compose and start the service locally - \cp ./config/docker-compose.envlocal.yml docker-compose.yml + \cp ./deploy-config/docker-compose.envlocal.yml docker-compose.yml $(DOCKER_COMPOSE) up --build .PHONY: clean -clean: ## remove all local compiled Python files - rm -f `find . -type f -name '*.py[co]' ` \ - `find . -type f -name '_version.py'` +clean: ## remove local files from python installation etc. + rm -f `find . -type f -name '*.py[co]' -o -name '_version.py'` \ rm -rf `find . -name __pycache__ -o -name "*.egg-info"` \ - .ruff_cache .pytest_cache + .ruff_cache \ + .pytest_cache \ + .coverage htmlcov \ + build dist \ + # docker-compose.yml .PHONY: check .PHONY: first_install diff --git a/README.md b/README.md index 32d1b85..855c67f 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ Developer documentation at make docker/compose/local ``` - This command will copy `config/docker-compose.envlocal.yml` into `docker-compose.yml` before composing all the services. + This command will copy `deploy-config/docker-compose.envlocal.yml` into `docker-compose.yml` before composing all the services. Type `make help` to learn about other macros available as make targets. For instance, `make docker/pruneall` will stop all containers, then remove all containers, images, networks, and volumes. diff --git a/config/docker-compose.envlocal.yml b/deploy-config/docker-compose.envlocal.yml similarity index 94% rename from config/docker-compose.envlocal.yml rename to deploy-config/docker-compose.envlocal.yml index ef6848b..6b76db9 100644 --- a/config/docker-compose.envlocal.yml +++ b/deploy-config/docker-compose.envlocal.yml @@ -7,12 +7,12 @@ services: - "443:443" volumes: - web-static:/var/www/livedata/static - - ./config/nginx/envlocal.conf:/etc/nginx/conf.d/nginx.conf + - ./deploy-config/nginx/envlocal.conf:/etc/nginx/conf.d/nginx.conf depends_on: - livedata: + django: condition: service_healthy - livedata: + django: build: context: . dockerfile: Dockerfile diff --git a/config/nginx/docker-entrypoint.sh b/deploy-config/nginx/docker-entrypoint.sh similarity index 100% rename from config/nginx/docker-entrypoint.sh rename to deploy-config/nginx/docker-entrypoint.sh diff --git a/config/nginx/envlocal.conf b/deploy-config/nginx/envlocal.conf similarity index 100% rename from config/nginx/envlocal.conf rename to deploy-config/nginx/envlocal.conf diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index b56730a..cd6f173 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -24,4 +24,4 @@ python manage.py createcachetable webcache python manage.py ensure_adminuser --username=${DJANGO_SUPERUSER_USERNAME} --email='workflow@example.com' --password=${DJANGO_SUPERUSER_PASSWORD} # run application -${COVERAGE_RUN} gunicorn live_data_server.wsgi:application -w 2 -b :8000 --reload +${COVERAGE_RUN} gunicorn config.wsgi:application -w 2 -b :8000 --reload diff --git a/docs/developer/config_for_local_use.rst b/docs/developer/config_for_local_use.rst index e7c7793..0c5f504 100644 --- a/docs/developer/config_for_local_use.rst +++ b/docs/developer/config_for_local_use.rst @@ -54,7 +54,7 @@ After the secrets are set, you can start the server with: make docker/compose/local -This command will copy ``config/docker-compose.envlocal.yml`` into ``./docker-compose.yml`` before composing all the services. +This command will copy ``deploy-config/docker-compose.envlocal.yml`` into ``./docker-compose.yml`` before composing all the services. | Run ``make help`` to learn about other macros available as make targets. | For instance, ``make docker/pruneall`` will stop all containers, then remove all containers, images, networks, and volumes. diff --git a/docs/developer/troubleshoot/unresponsive.rst b/docs/developer/troubleshoot/unresponsive.rst index e953edd..b20bba1 100644 --- a/docs/developer/troubleshoot/unresponsive.rst +++ b/docs/developer/troubleshoot/unresponsive.rst @@ -24,9 +24,9 @@ The logs indicate a problem with the certificate files. An additional test is to substitute the `nginx.conf file for the testing environment `_ with the -`local environment one `_, +`local environment one `_, which does not contain SSL certificates. Don't forget to change -`the server name `_ +`the server name `_ from `"localhost"` to `"testfixture02-test.ornl.gov"`. Redeploy after this. If the http://testfixture02-test.ornl.gov/admin (notice the `http` instead of `https`) app is served now, then it's a problem of the secure connection. diff --git a/src/live_data_server/.coveragerc b/src/.coveragerc similarity index 100% rename from src/live_data_server/.coveragerc rename to src/.coveragerc diff --git a/src/live_data_server/__init__.py b/src/__init__.py similarity index 100% rename from src/live_data_server/__init__.py rename to src/__init__.py diff --git a/src/live_data_server/plots/__init__.py b/src/apps/__init__.py similarity index 100% rename from src/live_data_server/plots/__init__.py rename to src/apps/__init__.py diff --git a/src/live_data_server/plots/management/__init__.py b/src/apps/plots/__init__.py similarity index 100% rename from src/live_data_server/plots/management/__init__.py rename to src/apps/plots/__init__.py diff --git a/src/live_data_server/plots/admin.py b/src/apps/plots/admin.py similarity index 89% rename from src/live_data_server/plots/admin.py rename to src/apps/plots/admin.py index be4eebf..cb6d290 100644 --- a/src/live_data_server/plots/admin.py +++ b/src/apps/plots/admin.py @@ -1,5 +1,5 @@ +from apps.plots.models import DataRun, Instrument, PlotData from django.contrib import admin -from plots.models import DataRun, Instrument, PlotData class PlotDataAdmin(admin.ModelAdmin): diff --git a/src/live_data_server/plots/apps.py b/src/apps/plots/apps.py similarity index 73% rename from src/live_data_server/plots/apps.py rename to src/apps/plots/apps.py index 10d83c7..9f62667 100644 --- a/src/live_data_server/plots/apps.py +++ b/src/apps/plots/apps.py @@ -2,4 +2,4 @@ class PlotsConfig(AppConfig): - name = "plots" + name = "apps.plots" diff --git a/src/live_data_server/plots/management/commands/__init__.py b/src/apps/plots/management/__init__.py similarity index 100% rename from src/live_data_server/plots/management/commands/__init__.py rename to src/apps/plots/management/__init__.py diff --git a/src/live_data_server/plots/migrations/__init__.py b/src/apps/plots/management/commands/__init__.py similarity index 100% rename from src/live_data_server/plots/migrations/__init__.py rename to src/apps/plots/management/commands/__init__.py diff --git a/src/live_data_server/plots/management/commands/ensure_adminuser.py b/src/apps/plots/management/commands/ensure_adminuser.py similarity index 100% rename from src/live_data_server/plots/management/commands/ensure_adminuser.py rename to src/apps/plots/management/commands/ensure_adminuser.py diff --git a/src/live_data_server/plots/management/commands/purge_expired_data.py b/src/apps/plots/management/commands/purge_expired_data.py similarity index 90% rename from src/live_data_server/plots/management/commands/purge_expired_data.py rename to src/apps/plots/management/commands/purge_expired_data.py index db17068..982f9d9 100644 --- a/src/live_data_server/plots/management/commands/purge_expired_data.py +++ b/src/apps/plots/management/commands/purge_expired_data.py @@ -1,6 +1,6 @@ +from apps.plots.models import DataRun from django.core.management.base import BaseCommand from django.utils import timezone -from plots.models import DataRun class Command(BaseCommand): diff --git a/src/live_data_server/plots/migrations/0001_initial.py b/src/apps/plots/migrations/0001_initial.py similarity index 100% rename from src/live_data_server/plots/migrations/0001_initial.py rename to src/apps/plots/migrations/0001_initial.py diff --git a/src/live_data_server/plots/migrations/0002_datarun_expiration_date.py b/src/apps/plots/migrations/0002_datarun_expiration_date.py similarity index 100% rename from src/live_data_server/plots/migrations/0002_datarun_expiration_date.py rename to src/apps/plots/migrations/0002_datarun_expiration_date.py diff --git a/src/apps/plots/migrations/__init__.py b/src/apps/plots/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/live_data_server/plots/models.py b/src/apps/plots/models.py similarity index 100% rename from src/live_data_server/plots/models.py rename to src/apps/plots/models.py diff --git a/src/live_data_server/plots/tests.py b/src/apps/plots/tests.py similarity index 100% rename from src/live_data_server/plots/tests.py rename to src/apps/plots/tests.py diff --git a/src/live_data_server/plots/urls.py b/src/apps/plots/urls.py similarity index 87% rename from src/live_data_server/plots/urls.py rename to src/apps/plots/urls.py index 94ab868..a0cba07 100644 --- a/src/live_data_server/plots/urls.py +++ b/src/apps/plots/urls.py @@ -16,5 +16,4 @@ ), re_path(r"^(?P[\w]+)/upload_user_data/$", views.upload_user_data, name="upload_user_data"), re_path(r"^(?P[\w]+)/list/$", views.get_data_list, name="get_data_list"), - # re_path(r"^(?P[\w]+)/list_extra/$", views.get_data_list, name="get_data_list"), ] diff --git a/src/live_data_server/plots/view_util.py b/src/apps/plots/view_util.py similarity index 98% rename from src/live_data_server/plots/view_util.py rename to src/apps/plots/view_util.py index 0428f01..4872756 100644 --- a/src/live_data_server/plots/view_util.py +++ b/src/apps/plots/view_util.py @@ -8,10 +8,10 @@ from datetime import datetime from typing import Optional +from apps.plots.models import DataRun, Instrument, PlotData from django.conf import settings from django.http import HttpResponse from django.utils import timezone -from plots.models import DataRun, Instrument, PlotData def generate_key(instrument, run_id): diff --git a/src/live_data_server/plots/views.py b/src/apps/plots/views.py similarity index 98% rename from src/live_data_server/plots/views.py rename to src/apps/plots/views.py index ac1399b..146294f 100644 --- a/src/live_data_server/plots/views.py +++ b/src/apps/plots/views.py @@ -6,6 +6,7 @@ import logging from datetime import timedelta +from apps.plots.models import DataRun, Instrument, PlotData from django.conf import settings from django.contrib.auth import authenticate, login from django.http import HttpResponse, HttpResponseNotFound, JsonResponse @@ -13,7 +14,6 @@ from django.utils import dateformat, timezone from django.views.decorators.cache import cache_page from django.views.decorators.csrf import csrf_exempt -from plots.models import DataRun, Instrument, PlotData from . import view_util diff --git a/src/live_data_server/live_data_server/__init__.py b/src/config/__init__.py similarity index 100% rename from src/live_data_server/live_data_server/__init__.py rename to src/config/__init__.py diff --git a/src/live_data_server/live_data_server/settings.py b/src/config/settings.py similarity index 97% rename from src/live_data_server/live_data_server/settings.py rename to src/config/settings.py index b314a85..663565c 100644 --- a/src/live_data_server/live_data_server/settings.py +++ b/src/config/settings.py @@ -40,7 +40,7 @@ # Application definition INSTALLED_APPS = [ - "plots.apps.PlotsConfig", + "apps.plots", "django.contrib.admin", "django.contrib.auth", "django.contrib.contenttypes", @@ -61,7 +61,7 @@ "django.middleware.clickjacking.XFrameOptionsMiddleware", ] -ROOT_URLCONF = "live_data_server.urls" +ROOT_URLCONF = "config.urls" CORS_ALLOW_ALL_ORIGINS = True @@ -81,7 +81,7 @@ }, ] -WSGI_APPLICATION = "live_data_server.wsgi.application" +WSGI_APPLICATION = "config.wsgi.application" # Database diff --git a/src/live_data_server/live_data_server/urls.py b/src/config/urls.py similarity index 92% rename from src/live_data_server/live_data_server/urls.py rename to src/config/urls.py index 8f6c461..c6ad9b9 100644 --- a/src/live_data_server/live_data_server/urls.py +++ b/src/config/urls.py @@ -23,5 +23,5 @@ urlpatterns = [ re_path(r"^admin/", admin.site.urls), re_path(r"^$", RedirectView.as_view(url="/plots/")), - re_path(r"^plots/", include("plots.urls", namespace="plots")), + re_path(r"^plots/", include("apps.plots.urls", namespace="plots")), ] diff --git a/src/live_data_server/live_data_server/wsgi.py b/src/config/wsgi.py similarity index 81% rename from src/live_data_server/live_data_server/wsgi.py rename to src/config/wsgi.py index 5d95e84..3f6d59b 100644 --- a/src/live_data_server/live_data_server/wsgi.py +++ b/src/config/wsgi.py @@ -11,6 +11,6 @@ from django.core.wsgi import get_wsgi_application -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "live_data_server.settings") +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings") application = get_wsgi_application() diff --git a/src/live_data_server/manage.py b/src/manage.py similarity index 68% rename from src/live_data_server/manage.py rename to src/manage.py index b3ae653..5ec273e 100755 --- a/src/live_data_server/manage.py +++ b/src/manage.py @@ -3,7 +3,7 @@ import sys if __name__ == "__main__": - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "live_data_server.settings") + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings") from django.core.management import execute_from_command_line diff --git a/test_client/test_client.py b/test_client/test_client.py deleted file mode 100644 index de566cc..0000000 --- a/test_client/test_client.py +++ /dev/null @@ -1,92 +0,0 @@ -""" -Test client that uploads data -""" - -import argparse -import datetime -import json -import os -import string - -import numpy as np -import plotly.graph_objs as go -import requests -from plotly.offline import plot - -API_USER = os.environ.get("DJANGO_SUPERUSER_USERNAME") -API_PWD = os.environ.get("DJANGO_SUPERUSER_PASSWORD") -UPLOAD_URL = "http://127.0.0.1/plots/$instrument/$run_number/upload_plot_data/" -USER_UPLOAD_URL = "http://127.0.0.1/plots/$user/upload_user_data/" - - -def get_plot_as_json(): - """ - Generates normal distributed 2D points - Number of points depends on the real time seconds. - """ - now = datetime.datetime.now() - n_points = 100 * now.second - mean = [0, 0] - cov = [[1, 0], [0, 1]] - x, y = np.random.multivariate_normal(mean, cov, n_points).T - data = dict( - x=x.tolist(), y=y.tolist(), mode="markers", name="points", marker=dict(color="rgb(0,0,0)", size=4, opacity=0.4) - ) - return data - - -def get_plot_as_div(): - """ - Return a plot as a div - """ - trace = go.Scatter(get_plot_as_json()) - data = [trace] - - layout = go.Layout( - showlegend=False, - autosize=False, - width=800, - height=700, - xaxis=dict( - range=[-4, 4], - ), - yaxis=dict( - range=[-4, 4], - ), - margin=dict(t=50), - hovermode="closest", - bargap=0, - ) - - fig = go.Figure(data=data, layout=layout) - plot_div = plot(fig, output_type="div", include_plotlyjs=False) - return plot_div - - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description="Test plot data producer") - parser.add_argument("--json", help="Produce json data", action="store_true", dest="as_json") - parser.add_argument("--html", help="Produce html data", action="store_false", dest="as_json") - parser.add_argument("-r", metavar="runid", type=int, help="Run number (int)", dest="runid", required=True) - parser.add_argument("-d", metavar="description", help="Data description", dest="description", required=False) - parser.add_argument("-i", metavar="instrument", help="Instrument", dest="instrument", required=True) - namespace = parser.parse_args() - - monitor_user = {"username": API_USER, "password": API_PWD} - url_template = string.Template(UPLOAD_URL) - url = url_template.substitute(instrument=namespace.instrument, run_number=namespace.runid) - - if namespace.as_json: - print("Producing json data") - files = {"file": json.dumps(get_plot_as_json())} - else: - print("Producing html data") - files = {"file": get_plot_as_div()} - - if namespace.description is not None: - url_template = string.Template(USER_UPLOAD_URL) - url = url_template.substitute(user=namespace.instrument) - monitor_user["data_id"] = namespace.description - - request = requests.post(url, data=monitor_user, files=files, verify=False) - print(request.status_code) diff --git a/tests/test_expiration.py b/tests/test_expiration.py index abc3185..5b08583 100644 --- a/tests/test_expiration.py +++ b/tests/test_expiration.py @@ -6,7 +6,7 @@ import psycopg import requests -TEST_URL = "http://127.0.0.1" +TEST_URL = "http://127.0.0.1:8000" HTTP_OK = requests.status_codes.codes["OK"] HTTP_UNAUTHORIZED = requests.status_codes.codes["unauthorized"] HTTP_NOT_FOUND = requests.status_codes.codes["NOT_FOUND"] @@ -117,7 +117,7 @@ def test_expiration_user(self, data_server): def test_deleting_expired(self): """Test the purge_expired_data command""" - command = "docker exec -i live_data_server-livedata-1 bash -ic" + command = "docker exec -i live_data_server-django-1 bash -ic" subcommand = "conda activate livedata && cd app && coverage run manage.py purge_expired_data" # subcommand = "conda activate livedata && cd app && python manage.py purge_expired_data" output = subprocess.check_output([*command.split(" "), subcommand]) diff --git a/tests/test_post_get.py b/tests/test_post_get.py index bf6dc2b..ff3c8c7 100644 --- a/tests/test_post_get.py +++ b/tests/test_post_get.py @@ -5,7 +5,7 @@ import psycopg import requests -TEST_URL = "http://127.0.0.1" +TEST_URL = "http://127.0.0.1:8000" HTTP_OK = requests.status_codes.codes["OK"] HTTP_UNAUTHORIZED = requests.status_codes.codes["unauthorized"] HTTP_NOT_FOUND = requests.status_codes.codes["NOT_FOUND"] From 9f654d9240d777c0012c18eaadf3006bb338a1ba Mon Sep 17 00:00:00 2001 From: glass-ships Date: Thu, 15 Aug 2024 11:49:37 -0400 Subject: [PATCH 2/6] try python manage.py instead of coverage run --- tests/test_expiration.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_expiration.py b/tests/test_expiration.py index 5b08583..8ca6a0a 100644 --- a/tests/test_expiration.py +++ b/tests/test_expiration.py @@ -118,8 +118,8 @@ def test_expiration_user(self, data_server): def test_deleting_expired(self): """Test the purge_expired_data command""" command = "docker exec -i live_data_server-django-1 bash -ic" - subcommand = "conda activate livedata && cd app && coverage run manage.py purge_expired_data" - # subcommand = "conda activate livedata && cd app && python manage.py purge_expired_data" + # subcommand = "conda activate livedata && cd app && coverage run manage.py purge_expired_data" + subcommand = "conda activate livedata && cd app && python manage.py purge_expired_data" output = subprocess.check_output([*command.split(" "), subcommand]) print(output) From 7ab43a7799d421c40e3d3e1248033941596b63fb Mon Sep 17 00:00:00 2001 From: glass-ships Date: Mon, 19 Aug 2024 10:08:30 -0400 Subject: [PATCH 3/6] adjust .coveragerc --- src/.coveragerc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/.coveragerc b/src/.coveragerc index c900f8e..65e2612 100644 --- a/src/.coveragerc +++ b/src/.coveragerc @@ -1,4 +1,4 @@ [run] -source=live_data_server,plots +source=apps,config parallel=True relative_files=True From 6d210b474ca408c11e5352b352f4e7d0103d0805 Mon Sep 17 00:00:00 2001 From: glass-ships Date: Mon, 19 Aug 2024 11:46:02 -0400 Subject: [PATCH 4/6] update documentation --- docs/developer/updating_data_models.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/developer/updating_data_models.rst b/docs/developer/updating_data_models.rst index 045dedc..52ec366 100644 --- a/docs/developer/updating_data_models.rst +++ b/docs/developer/updating_data_models.rst @@ -5,25 +5,25 @@ Updating Data Models | There may be times when you need to update the data models used by Django. | This can be done by following these steps: -#. Make the necessary changes to the models in ``src/live_data_server/plots/models.py``. +#. Make the necessary changes to the models in ``src/apps/plots/models.py``. #. Generate the Django migration file(s): .. code-block:: bash - cd src/live_data_server + cd src python manage.py makemigrations -The migration(s) will be created in the ``src/live_data_server/plots/migrations/`` directory. +The migration(s) will be created in the ``src/apps/plots/migrations/`` directory. First check the migration(s) to ensure they are correct. If they are, apply the migration(s): -From within the live_data_server Docker container: +From within the Django app Docker container: .. code-block:: bash python manage.py migrate # or if you are not in the container - docker exec -i live_data_server-livedata-1 bash -ic ' + docker exec -i live_data_server-django-1 bash -ic ' conda activate livedata cd app python manage.py migrate From 04b669b90d8175a667125ff8cc13418abe2199ff Mon Sep 17 00:00:00 2001 From: glass-ships Date: Mon, 19 Aug 2024 12:36:47 -0400 Subject: [PATCH 5/6] run expiration test with coverage --- tests/test_expiration.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_expiration.py b/tests/test_expiration.py index 8ca6a0a..03c7c88 100644 --- a/tests/test_expiration.py +++ b/tests/test_expiration.py @@ -118,8 +118,7 @@ def test_expiration_user(self, data_server): def test_deleting_expired(self): """Test the purge_expired_data command""" command = "docker exec -i live_data_server-django-1 bash -ic" - # subcommand = "conda activate livedata && cd app && coverage run manage.py purge_expired_data" - subcommand = "conda activate livedata && cd app && python manage.py purge_expired_data" + subcommand = "conda activate livedata && cd app && coverage run manage.py purge_expired_data" output = subprocess.check_output([*command.split(" "), subcommand]) print(output) From beb077bee2b743889a928eed6451f3213d6899b8 Mon Sep 17 00:00:00 2001 From: glass-ships Date: Mon, 19 Aug 2024 13:46:47 -0400 Subject: [PATCH 6/6] add upstream server in nginx config --- deploy-config/nginx/envlocal.conf | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/deploy-config/nginx/envlocal.conf b/deploy-config/nginx/envlocal.conf index 36514fb..bb44ab8 100644 --- a/deploy-config/nginx/envlocal.conf +++ b/deploy-config/nginx/envlocal.conf @@ -1,3 +1,7 @@ +upstream livedata { + server django:8000; +} + server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; @@ -6,7 +10,7 @@ server { client_max_body_size 0; location / { - proxy_pass http://livedata:8000; + proxy_pass http://livedata; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;