Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add expiration field to DataRun model #25

Merged
merged 31 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a7f317c
Add expiration field to DataRun model
glass-ships Aug 5, 2024
7da502d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 5, 2024
0fbd74b
lint
glass-ships Aug 6, 2024
9d23c49
Merge branch 'expiration-field' of github.com:neutrons/live_data_serv…
glass-ships Aug 6, 2024
9bc990e
makefile checks for correct docker compose command
glass-ships Aug 6, 2024
e2e8ede
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 6, 2024
1fdc19e
typo in path to environment.yml in github action
glass-ships Aug 6, 2024
8479c69
Merge branch 'expiration-field' of github.com:neutrons/live_data_serv…
glass-ships Aug 6, 2024
3503724
try commenting use only tar bz2
glass-ships Aug 6, 2024
14d5e91
try uncommenting use only tar bz2
glass-ships Aug 6, 2024
b8a1711
try setting cache_number to 1
glass-ships Aug 6, 2024
283b6b8
remove caching step for now
glass-ships Aug 6, 2024
5bb56bf
add seemingly unnecessary check for docker compose command
glass-ships Aug 6, 2024
ff71348
fix wrong docker image in coverage steps
glass-ships Aug 6, 2024
92fc810
fix wrong docker image in coverage steps (again)
glass-ships Aug 6, 2024
ce53338
docker-compose -> docker compose everywhere
glass-ships Aug 6, 2024
450faa5
remove try except, unsure what to catch apart from bare exception
glass-ships Aug 7, 2024
6c942db
rename expired run data id just because
glass-ships Aug 7, 2024
5739c54
trying management command, need to figure out tests
glass-ships Aug 8, 2024
3654b14
fix tests
glass-ships Aug 8, 2024
ec17de2
add new migration for model changes
glass-ships Aug 8, 2024
100df66
remove unnecessary util command
glass-ships Aug 8, 2024
fc49df6
eh remove unneeded USE_L10N and USE_TZ
glass-ships Aug 8, 2024
f296c39
update documentation
glass-ships Aug 9, 2024
92dcc28
add codecov.yml
glass-ships Aug 9, 2024
83a6b32
modify codecov.yml
glass-ships Aug 9, 2024
8412fa1
revert add dependabot and update precommit
glass-ships Aug 9, 2024
cfd0790
Merge branch 'next' into expiration-field
glass-ships Aug 9, 2024
174eca2
Try running purge with coverage
glass-ships Aug 12, 2024
ede7ff9
revert to django 4.2
glass-ships Aug 13, 2024
5e67172
address comments, revert django ver, etc
glass-ships Aug 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
name: unit-test
name: Run unit tests

on:
workflow_dispatch:
pull_request:
push:
branches: [next, qa, main]
tags: ['v*']
tags: ["v*"]

jobs:
linux:
runs-on: ubuntu-latest
defaults:
run:
shell: bash -l {0}

env:
DATABASE_NAME: livedatadb
DATABASE_USER: livedatauser
Expand All @@ -23,29 +24,39 @@ jobs:
DJANGO_SUPERUSER_USERNAME: livedatauser
DJANGO_SUPERUSER_PASSWORD: livedatapass
COVERAGE_RUN: coverage run -m

steps:
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v3
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Conda environment
uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
channels: conda-forge,defaults
mamba-version: "*"
environment-file: environment.yml
cache-environment-key: ${{ runner.os }}-env-${{ hashFiles('**/environment.yml') }}
cache-downloads-key: ${{ runner.os }}-downloads-${{ hashFiles('**/environment.yml') }}

- name: Start docker containers
run: |
cp ./config/docker-compose.envlocal.yml docker-compose.yml
docker-compose up --build -d
docker compose up --build -d

- name: Sleep, wait for containers to start up
run: sleep 30

- name: Run unit tests
run: python -m pytest tests/

- 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-livedata-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-livedata-1:/var/www/livedata/app /tmp/

- name: Combine and show code coverage
shell: bash -l {0}
run: |
Expand All @@ -54,9 +65,11 @@ jobs:
coverage xml
cp coverage.xml $OLDPWD
coverage report

- name: Bring down docker containers completely now
# This will completely remove the containers
run: docker-compose down
run: docker compose down

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
with:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/.envrc
/docker-compose.yml
_version.py

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
21 changes: 15 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ app_dir := live_data_server
DJANGO_COMPATIBLE:=$(shell python -c "import django;t=0 if django.VERSION[0]<4 else 1; print(t)")
DJANGO_VERSION:=$(shell python -c "import django;print(django.__version__)")

# command to run docker compose. change this to be what you have installed
# this can be overriden on the command line
# DOCKER_COMPOSE="docker compose" make docker/pruneall
DOCKER_COMPOSE ?= docker-compose
ifneq ($(shell docker compose version 2>/dev/null),)
DOCKER_COMPOSE=docker compose
else ifneq ($(shell docker-compose --version 2>/dev/null),)
DOCKER_COMPOSE=docker-compose
endif


help:
# this nifty perl one-liner collects all comments headed by the double "#" symbols next to each target and recycles them as comments
Expand All @@ -30,10 +32,17 @@ docker/pruneall: docker/compose/validate ## stop all containers, then remove al
docker/compose/validate: ## validate the version of the docker-compose command. Exits quietly if valid.
@./scripts/docker-compose_validate.sh $(DOCKER_COMPOSE)

local/docker/up: docker/compose/validate ## compose and start the service locally
docker/compose/local: docker/compose/validate ## compose and start the service locally
\cp ./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'`
rm -rf `find . -name __pycache__ -o -name "*.egg-info"` \
.ruff_cache .pytest_cache

.PHONY: check
.PHONY: first_install
.PHONY: help
Expand All @@ -42,4 +51,4 @@ local/docker/up: docker/compose/validate ## compose and start the service locall
.PHONY: webapp/core
.PHONY: docker/compose/validate
.PHONY: docker/pruneall
.PHONY: local/docker/up
.PHONY: docker/compose/local
114 changes: 73 additions & 41 deletions README.md
glass-ships marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,70 +1,102 @@
## live_data_server
Data server for data plots
# live_data_server

<!-- Badges -->

[![Documentation Status](https://readthedocs.org/projects/livedata-ornl/badge/?version=latest)](https://livedata-ornl.readthedocs.io/en/latest/?badge=latest)
[![codecov](https://codecov.io/gh/neutrons/live_data_server/graph/badge.svg?token=niQ0AWldBd)](https://codecov.io/gh/neutrons/live_data_server)

Developer documentation at https://livedata-ornl.readthedocs.io/en/latest/
Data server for data plots.

## Contributing
## Development

Create a conda environment `livedata`, containing all the dependencies
```python
conda env create -f environment.yml
conda activate livedata
```
Developer documentation at <https://livedata-ornl.readthedocs.io/en/latest/>

### Containerization
### Dependencies

To deploy this application locally for development you will need to assign values to the following secrets
as environment variables defined in the shell's environment:
```bash
DATABASE_NAME
DATABASE_USER
DATABASE_PASS
DATABASE_HOST
DATABASE_PORT
LIVE_PLOT_SECRET_KEY
```
It is recommended to save these variables into an `.envrc` file which can be managed by
[envdir](https://direnv.net/).
- [Conda](https://conda.io/projects/conda/en/latest/user-guide/install/index.html) / [Mamba/Miniforge](https://github.com/conda-forge/miniforge)
- [Docker](https://docs.docker.com/engine/install/) and [Docker Compose](https://docs.docker.com/compose/install/)
- [direnv](https://direnv.net/) (optional)

After the secrets are set, type in the terminal shell:
```bash
make local/docker/up
```
This command will copy `config/docker-compose.envlocal.yml` into `docker-compose.yml` before composing
all the services.
### Setup for Local Development

1. Clone the repository and `cd` into the project directory.

1. Create a conda environment `livedata`, containing all the dependencies

```python
conda env create -f environment.yml
conda activate livedata
```

1. To deploy this application locally, you will need to set a number of environment variables,
for example (bash):

```bash
export DATABASE_NAME=livedatadb
export DATABASE_USER=livedatauser
export DATABASE_PASS=livedatapass
export DATABASE_HOST=db
export DATABASE_PORT=5432
export LIVE_PLOT_SECRET_KEY="secretKey"

# These need to be set for `pytest`,
# but are not used in the docker compose
export DJANGO_SUPERUSER_USERNAME=$DATABASE_USER
export DJANGO_SUPERUSER_PASSWORD=$DATABASE_PASS
```

**Notes**:

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.
- The `DATABASE_PORT` _must_ be set to `5432`, as Postgres is configured to listen on that port by default.
If you need to change the port, you will need to modify the `docker-compose.yml` file accordingly.

## Test & Verification
- It is recommended to save these variables into an `.envrc` file which can be managed by [direnv](https://direnv.net/).
direnv will automatically load the variables when you `cd` into the project directory.

After starting the services with `make local/docker/up`, run the test that will post and get data:
1. After the secrets are set, type in the terminal shell:

```bash
make docker/compose/local
```

This command will copy `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.

### Testing

After the setup, with the server running, you can test your setup by running `pytest`:

```bash
DJANGO_SUPERUSER_USERNAME=***** DJANGO_SUPERUSER_PASSWORD=***** pytest tests/test_post_get.py
pytest tests/test_post_get.py
# or simply
pytest
```

Environment variables `DJANGO_SUPERUSER_USERNAME` and `DJANGO_SUPERUSER_PASSWORD` are defined in
file `docker-compose.envlocal.yml`. You need to either pass these variables with the correct values or have
them exported to the shell where `pytest` is to be run.
**NOTE:**
The environment variables `DJANGO_SUPERUSER_USERNAME` and `DJANGO_SUPERUSER_PASSWORD` are defined in the `docker-compose.envlocal.yml` file, but `pytest` does not read this file.
You must either have them exported to the shell where `pytest` is to be run, as described above, or modify the `pytest` command to include them, e.g.:

```bash
DJANGO_SUPERUSER_USERNAME=***** DJANGO_SUPERUSER_PASSWORD=***** pytest
```

## Deployment to the Test Environment
- Repository managing the provision for deployment:
+ hardware and networking for deployment: https://code.ornl.gov/sns-hfir-scse/infrastructure/neutrons-test-environment/-/blob/main/terraform/servers.tf#L85-97
+ configuration independent of source code changes: https://code.ornl.gov/sns-hfir-scse/infrastructure/neutrons-test-environment/-/blob/main/ansible/testfixture02-test.yaml
- Repository managing deployment of the source to the provisioned hardware: https://code.ornl.gov/sns-hfir-scse/deployments/livedata-deploy

- Repository managing the provision for deployment:
- hardware and networking for deployment: <https://code.ornl.gov/sns-hfir-scse/infrastructure/neutrons-test-environment/-/blob/main/terraform/servers.tf#L85-97>
- configuration independent of source code changes: <https://code.ornl.gov/sns-hfir-scse/infrastructure/neutrons-test-environment/-/blob/main/ansible/testfixture02-test.yaml>
- Repository managing deployment of the source to the provisioned hardware: <https://code.ornl.gov/sns-hfir-scse/deployments/livedata-deploy>

## Building the Documentation

Additional documentation is available in the `docs` directory. To build the documentation in your local machine,
run the following command from within directory `docs/`:

```bash
make html
```

The documentation will be built in the `docs/_build/html` directory. To view the documentation,
open the `docs/_build/html/index.html` file in a web browser.
10 changes: 10 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
coverage:
status:
project:
default:
target: 80%
threshold: 3%
patch:
default:
target: 80%
threshold: 10%
4 changes: 2 additions & 2 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
@$(SPHINXBUILD) -M help $(SOURCEDIR) $(BUILDDIR) $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
$(SPHINXBUILD) -M $@ $(SOURCEDIR) $(BUILDDIR) $(SPHINXOPTS) $(O)
10 changes: 5 additions & 5 deletions docs/conf.py
backmari marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
import os
import sys
from importlib import metadata

sys.path.insert(0, os.path.abspath("../live_data_server"))
# sys.path.insert(0, os.path.abspath("../live_data_server"))
# from live_data_server import __version__ as release

from live_data_server import __version__ as release
release = metadata.version("live_data_server")

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
Expand Down Expand Up @@ -67,7 +67,7 @@
autosummary_generate = True

# Napoleon settings
napoleon_google_docstring = False
napoleon_google_docstring = True
napoleon_numpy_docstring = True

# Add any paths that contain custom static files (such as style sheets) here,
Expand Down
Loading
Loading