Skip to content

Commit 7a4d038

Browse files
authored
Merge pull request #29 from neutrons/restructure
Reorganize and modernize repository
2 parents 25a1c73 + beb077b commit 7a4d038

37 files changed

+45
-132
lines changed

.github/workflows/unittest.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141

4242
- name: Start docker containers
4343
run: |
44-
cp ./config/docker-compose.envlocal.yml docker-compose.yml
44+
cp ./deploy-config/docker-compose.envlocal.yml docker-compose.yml
4545
docker compose up --build -d
4646
4747
- name: Sleep, wait for containers to start up
@@ -52,10 +52,10 @@ jobs:
5252

5353
- name: Stop the coverage process
5454
# Stopping the coverage process allows the code coverage to be written to disk
55-
run: docker exec live_data_server-livedata-1 /bin/bash -c "pkill coverage"
55+
run: docker exec live_data_server-django-1 /bin/bash -c "pkill coverage"
5656

5757
- name: Copy code coverage out of docker container
58-
run: docker cp live_data_server-livedata-1:/var/www/livedata/app /tmp/
58+
run: docker cp live_data_server-django-1:/var/www/livedata/app /tmp/
5959

6060
- name: Combine and show code coverage
6161
shell: bash -l {0}

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ WORKDIR /var/www/livedata
77

88
COPY docker-entrypoint.sh /usr/bin/
99

10-
COPY src/live_data_server app
10+
COPY src app
1111
RUN mkdir ./static
1212

1313
RUN chmod +x /usr/bin/docker-entrypoint.sh

Makefile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,18 @@ docker/compose/validate: ## validate the version of the docker-compose command.
3333
@./scripts/docker-compose_validate.sh $(DOCKER_COMPOSE)
3434

3535
docker/compose/local: docker/compose/validate ## compose and start the service locally
36-
\cp ./config/docker-compose.envlocal.yml docker-compose.yml
36+
\cp ./deploy-config/docker-compose.envlocal.yml docker-compose.yml
3737
$(DOCKER_COMPOSE) up --build
3838

3939
.PHONY: clean
40-
clean: ## remove all local compiled Python files
41-
rm -f `find . -type f -name '*.py[co]' ` \
42-
`find . -type f -name '_version.py'`
40+
clean: ## remove local files from python installation etc.
41+
rm -f `find . -type f -name '*.py[co]' -o -name '_version.py'` \
4342
rm -rf `find . -name __pycache__ -o -name "*.egg-info"` \
44-
.ruff_cache .pytest_cache
43+
.ruff_cache \
44+
.pytest_cache \
45+
.coverage htmlcov \
46+
build dist \
47+
# docker-compose.yml
4548

4649
.PHONY: check
4750
.PHONY: first_install

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Developer documentation at <https://livedata-ornl.readthedocs.io/en/latest/>
5959
make docker/compose/local
6060
```
6161

62-
This command will copy `config/docker-compose.envlocal.yml` into `docker-compose.yml` before composing all the services.
62+
This command will copy `deploy-config/docker-compose.envlocal.yml` into `docker-compose.yml` before composing all the services.
6363

6464
Type `make help` to learn about other macros available as make targets.
6565
For instance, `make docker/pruneall` will stop all containers, then remove all containers, images, networks, and volumes.

config/docker-compose.envlocal.yml renamed to deploy-config/docker-compose.envlocal.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ services:
77
- "443:443"
88
volumes:
99
- web-static:/var/www/livedata/static
10-
- ./config/nginx/envlocal.conf:/etc/nginx/conf.d/nginx.conf
10+
- ./deploy-config/nginx/envlocal.conf:/etc/nginx/conf.d/nginx.conf
1111
depends_on:
12-
livedata:
12+
django:
1313
condition: service_healthy
1414

15-
livedata:
15+
django:
1616
build:
1717
context: .
1818
dockerfile: Dockerfile

config/nginx/envlocal.conf renamed to deploy-config/nginx/envlocal.conf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
upstream livedata {
2+
server django:8000;
3+
}
4+
15
server {
26
listen 80 default_server;
37
listen [::]:80 default_server ipv6only=on;
@@ -6,7 +10,7 @@ server {
610
client_max_body_size 0;
711

812
location / {
9-
proxy_pass http://livedata:8000;
13+
proxy_pass http://livedata;
1014
proxy_set_header Host $http_host;
1115
proxy_set_header X-Real-IP $remote_addr;
1216
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

docker-entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ python manage.py createcachetable webcache
2424
python manage.py ensure_adminuser --username=${DJANGO_SUPERUSER_USERNAME} --email='[email protected]' --password=${DJANGO_SUPERUSER_PASSWORD}
2525

2626
# run application
27-
${COVERAGE_RUN} gunicorn live_data_server.wsgi:application -w 2 -b :8000 --reload
27+
${COVERAGE_RUN} gunicorn config.wsgi:application -w 2 -b :8000 --reload

docs/developer/config_for_local_use.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ After the secrets are set, you can start the server with:
5454
5555
make docker/compose/local
5656
57-
This command will copy ``config/docker-compose.envlocal.yml`` into ``./docker-compose.yml`` before composing all the services.
57+
This command will copy ``deploy-config/docker-compose.envlocal.yml`` into ``./docker-compose.yml`` before composing all the services.
5858

5959
| Run ``make help`` to learn about other macros available as make targets.
6060
| For instance, ``make docker/pruneall`` will stop all containers, then remove all containers, images, networks, and volumes.

docs/developer/troubleshoot/unresponsive.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ The logs indicate a problem with the certificate files.
2424
An additional test is to substitute the
2525
`nginx.conf file for the testing environment <https://code.ornl.gov/sns-hfir-scse/deployments/livedata-deploy/-/blob/main/test/nginx.conf?ref_type=heads>`_
2626
with the
27-
`local environment one <https://github.com/neutrons/live_data_server/blob/b903a26232dcbccf9f974d522c6113094a0689f0/config/nginx/envlocal.conf>`_,
27+
`local environment one <https://github.com/neutrons/live_data_server/blob/next/deploy-config/nginx/envlocal.conf>`_,
2828
which does not contain SSL certificates. Don't forget to change
29-
`the server name <https://github.com/neutrons/live_data_server/blob/b903a26232dcbccf9f974d522c6113094a0689f0/config/nginx/envlocal.conf#L4>`_
29+
`the server name <https://github.com/neutrons/live_data_server/blob/next/deploy-config/nginx/envlocal.conf#L4>`_
3030
from `"localhost"` to `"testfixture02-test.ornl.gov"`.
3131
Redeploy after this. If the http://testfixture02-test.ornl.gov/admin (notice the `http` instead of `https`) app is
3232
served now, then it's a problem of the secure connection.

docs/developer/updating_data_models.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@ Updating Data Models
55
| There may be times when you need to update the data models used by Django.
66
| This can be done by following these steps:
77
8-
#. Make the necessary changes to the models in ``src/live_data_server/plots/models.py``.
8+
#. Make the necessary changes to the models in ``src/apps/plots/models.py``.
99
#. Generate the Django migration file(s):
1010

1111
.. code-block:: bash
1212
13-
cd src/live_data_server
13+
cd src
1414
python manage.py makemigrations
1515
16-
The migration(s) will be created in the ``src/live_data_server/plots/migrations/`` directory.
16+
The migration(s) will be created in the ``src/apps/plots/migrations/`` directory.
1717
First check the migration(s) to ensure they are correct. If they are, apply the migration(s):
1818

19-
From within the live_data_server Docker container:
19+
From within the Django app Docker container:
2020

2121
.. code-block:: bash
2222
2323
python manage.py migrate
2424
2525
# or if you are not in the container
26-
docker exec -i live_data_server-livedata-1 bash -ic '
26+
docker exec -i live_data_server-django-1 bash -ic '
2727
conda activate livedata
2828
cd app
2929
python manage.py migrate
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[run]
2-
source=live_data_server,plots
2+
source=apps,config
33
parallel=True
44
relative_files=True
File renamed without changes.
File renamed without changes.

src/live_data_server/plots/admin.py renamed to src/apps/plots/admin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
from apps.plots.models import DataRun, Instrument, PlotData
12
from django.contrib import admin
2-
from plots.models import DataRun, Instrument, PlotData
33

44

55
class PlotDataAdmin(admin.ModelAdmin):

src/live_data_server/plots/apps.py renamed to src/apps/plots/apps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33

44
class PlotsConfig(AppConfig):
5-
name = "plots"
5+
name = "apps.plots"

src/live_data_server/plots/management/commands/purge_expired_data.py renamed to src/apps/plots/management/commands/purge_expired_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
from apps.plots.models import DataRun
12
from django.core.management.base import BaseCommand
23
from django.utils import timezone
3-
from plots.models import DataRun
44

55

66
class Command(BaseCommand):

src/apps/plots/migrations/__init__.py

Whitespace-only changes.
File renamed without changes.
File renamed without changes.

src/live_data_server/plots/urls.py renamed to src/apps/plots/urls.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,4 @@
1616
),
1717
re_path(r"^(?P<user>[\w]+)/upload_user_data/$", views.upload_user_data, name="upload_user_data"),
1818
re_path(r"^(?P<instrument>[\w]+)/list/$", views.get_data_list, name="get_data_list"),
19-
# re_path(r"^(?P<instrument>[\w]+)/list_extra/$", views.get_data_list, name="get_data_list"),
2019
]

src/live_data_server/plots/view_util.py renamed to src/apps/plots/view_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
from datetime import datetime
99
from typing import Optional
1010

11+
from apps.plots.models import DataRun, Instrument, PlotData
1112
from django.conf import settings
1213
from django.http import HttpResponse
1314
from django.utils import timezone
14-
from plots.models import DataRun, Instrument, PlotData
1515

1616

1717
def generate_key(instrument, run_id):

src/live_data_server/plots/views.py renamed to src/apps/plots/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
import logging
77
from datetime import timedelta
88

9+
from apps.plots.models import DataRun, Instrument, PlotData
910
from django.conf import settings
1011
from django.contrib.auth import authenticate, login
1112
from django.http import HttpResponse, HttpResponseNotFound, JsonResponse
1213
from django.shortcuts import get_object_or_404
1314
from django.utils import dateformat, timezone
1415
from django.views.decorators.cache import cache_page
1516
from django.views.decorators.csrf import csrf_exempt
16-
from plots.models import DataRun, Instrument, PlotData
1717

1818
from . import view_util
1919

src/live_data_server/live_data_server/settings.py renamed to src/config/settings.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
# Application definition
4141

4242
INSTALLED_APPS = [
43-
"plots.apps.PlotsConfig",
43+
"apps.plots",
4444
"django.contrib.admin",
4545
"django.contrib.auth",
4646
"django.contrib.contenttypes",
@@ -61,7 +61,7 @@
6161
"django.middleware.clickjacking.XFrameOptionsMiddleware",
6262
]
6363

64-
ROOT_URLCONF = "live_data_server.urls"
64+
ROOT_URLCONF = "config.urls"
6565

6666
CORS_ALLOW_ALL_ORIGINS = True
6767

@@ -81,7 +81,7 @@
8181
},
8282
]
8383

84-
WSGI_APPLICATION = "live_data_server.wsgi.application"
84+
WSGI_APPLICATION = "config.wsgi.application"
8585

8686

8787
# Database

src/live_data_server/live_data_server/urls.py renamed to src/config/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@
2323
urlpatterns = [
2424
re_path(r"^admin/", admin.site.urls),
2525
re_path(r"^$", RedirectView.as_view(url="/plots/")),
26-
re_path(r"^plots/", include("plots.urls", namespace="plots")),
26+
re_path(r"^plots/", include("apps.plots.urls", namespace="plots")),
2727
]

src/live_data_server/live_data_server/wsgi.py renamed to src/config/wsgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111

1212
from django.core.wsgi import get_wsgi_application
1313

14-
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "live_data_server.settings")
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
1515

1616
application = get_wsgi_application()

src/live_data_server/manage.py renamed to src/manage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44

55
if __name__ == "__main__":
6-
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "live_data_server.settings")
6+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
77

88
from django.core.management import execute_from_command_line
99

test_client/test_client.py

Lines changed: 0 additions & 92 deletions
This file was deleted.

tests/test_expiration.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import psycopg
77
import requests
88

9-
TEST_URL = "http://127.0.0.1"
9+
TEST_URL = "http://127.0.0.1:8000"
1010
HTTP_OK = requests.status_codes.codes["OK"]
1111
HTTP_UNAUTHORIZED = requests.status_codes.codes["unauthorized"]
1212
HTTP_NOT_FOUND = requests.status_codes.codes["NOT_FOUND"]
@@ -117,9 +117,8 @@ def test_expiration_user(self, data_server):
117117

118118
def test_deleting_expired(self):
119119
"""Test the purge_expired_data command"""
120-
command = "docker exec -i live_data_server-livedata-1 bash -ic"
120+
command = "docker exec -i live_data_server-django-1 bash -ic"
121121
subcommand = "conda activate livedata && cd app && coverage run manage.py purge_expired_data"
122-
# subcommand = "conda activate livedata && cd app && python manage.py purge_expired_data"
123122
output = subprocess.check_output([*command.split(" "), subcommand])
124123
print(output)
125124

tests/test_post_get.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import psycopg
66
import requests
77

8-
TEST_URL = "http://127.0.0.1"
8+
TEST_URL = "http://127.0.0.1:8000"
99
HTTP_OK = requests.status_codes.codes["OK"]
1010
HTTP_UNAUTHORIZED = requests.status_codes.codes["unauthorized"]
1111
HTTP_NOT_FOUND = requests.status_codes.codes["NOT_FOUND"]

0 commit comments

Comments
 (0)