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

Feature/add nix #26

Merged
merged 13 commits into from
Sep 10, 2024
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ MANIFEST
pip-log.txt
pip-delete-this-directory.txt

# Local dev secrets
k8s/envs/local/secrets.env

# Unit test / coverage reports
htmlcov/
.tox/
Expand Down Expand Up @@ -161,8 +164,11 @@ cython_debug/

# vscode
.vscode
.devenv
.pre-commit-config.yaml

# temp files
tmp/
tmp/**/*
dump.rdb
local-kubeconfig
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This application is the backend server for the PhotonRanch Datalab. It is a djan


## Local Development
### Bare Metal
Start by creating a virtualenv for this project and entering it:
```
python -m venv /path/to/my/virtualenv
Expand Down Expand Up @@ -38,6 +39,23 @@ Now start your server
./manage.py runserver
```

### Nix development
For this mode of development, you must install:
- nix with flakes support

Then to develop, run these commands:
- `nix develop --impure` to start your nix development environment - **called anytime you use a new terminal**
- `ctlptl apply -f local-registry.yaml -f local-cluster.yaml` to start up the registry and cluster - **should only need to be called one time within the nix environment**
- `skaffold dev -m deps` to start the dependencies - **run this in a different tab to keep running during development or use 'run' instead of 'dev'**
- Copy `./k8s/envs/local/secrets.env.changeme` to a version without `.changeme` and fill in values for connecting to the appropriate services.
- `skaffold dev -m app --port-forward` to start the servers and worker. This will auto-redeploy as you make changes to the code.

### Connecting a frontend
You can also run a local [datalab-ui](https://github.com/LCOGT/datalab-ui) to connect to your datalab. Assuming you've cloned that repo:
- Change the `./public/config/config.json` "datalabApiBaseUrl" to be `http://127.0.0.1:8080/api/` or wherever your backend is deployed to
- `npm install` to install the libraries
- `npm run serve` to run the server at `http://127.0.0.1:8081` assuming your backend was already running (otherwise it will try to be :8080)

## API Structure
The application has a REST API with the following endpoints you can use. You must pass your user's API token in the request header to access any of the endpoints - the headers looks like `{'Authorization': 'Token 123456789abcdefg'}` if you are using python's requests library.

Expand Down Expand Up @@ -105,9 +123,4 @@ Available Operations are introspected from the `data_operations` directory and m
`DELETE /api/datasessions/datasession_id/operations/operation_id/`

## ROADMAP
* Come up with operation `wizard_description` format and add endpoint to get them for all available operations so the frontend can auto-create UI wizards for new operations.
* Figure out user accounts between PTR and datalab - datalab needs user accounts for permissions to gate access to only your own sessions.
* Implement operations to actually do something when they are added to a session
* Figure out caching and storage of intermediate results
* Figure out asynchronous task queue or temporal for executing operations
* Add in operation results/status to the serialized operations output (maybe to the model too as needed)
* TBD
4 changes: 2 additions & 2 deletions datalab/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ def get_list_from_env(variable, default=None):
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = '/static/'
STATIC_URL = os.getenv('STATIC_URL', '/static/')
STATIC_ROOT = os.getenv('STATIC_ROOT', '/static/')

# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
Expand Down
5 changes: 5 additions & 0 deletions datalab/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.conf import settings
from django.urls import path, re_path, include
from rest_framework_nested import routers
import ocs_authentication.auth_profile.urls as authprofile_urls
Expand All @@ -39,3 +41,6 @@
path('api/available_operations/', OperationOptionsApiView.as_view(), name='available_operations'),
re_path(r'^authprofile/', include(authprofile_urls)),
]

if settings.DEBUG:
urlpatterns += staticfiles_urlpatterns()
Loading
Loading