Skip to content
ScilifelabDataCentrePublic

About

A cloud-based system for the delivery of data from SciLifeLab Facilities to their users (e.g. research group).

Topics

Resources

Contributing

Security policy

Stars

10 stars

Watchers

4 watching

Forks

Latest commit

 

History

7,303 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Data Delivery System Web / API

Release Licence: MIT Code style: black Code style: prettier
Linting CodeQL Tests

Links
Documentation Technical Overview Architecture Decision Record Troubleshooting CLI

About

The Data Delivery System (DDS) is a cloud-based system for all SciLifeLab platforms where data generated throughout each project can be delivered to the research groups in a fast, secure and simple way. The Web / API is the backend, handling the requests and the logic behind the scenes.

The Data Delivery System is developed and maintained by the SciLifeLab Data Centre. National Genomics Infrastructure (NGI) Stockholm has been a part of the development team during 2021 and early 2022.

This project is supported by EIT Digital, activity number 19390. This deliverable consists of design document and implementation report of application and validation of VEIL.AI technology in SciLifeLab context in Sweden.


Table of Contents

Development Setup

When developing this software, we recommend that you run the web server locally using Docker. You can download Docker here: https://docs.docker.com/get-docker/

Then, fork this repository and clone to your local system.

Running locally

The development environment requires that dds_cli is checked out next to this repo, in ../dds_cli (otherwise adapt the volume path in docker-compose.yml). Without it, the cli container fails to start.

In the root folder of the repo, start the development environment:

docker compose up

This builds and starts all containers needed for development:

  • backend: the web app and API, at localhost:5000. Use localhost rather than 127.0.0.1: links in emails point to localhost:5000, and the login session doesn't carry over between the two hosts
  • db: the MariaDB database
  • redis: the job queue. To also use it for API rate limiting, uncomment RATELIMIT_STORAGE_URI in docker-compose.yml
  • weedmini: SeaweedFS (weed mini) S3 storage, at localhost:9000
  • mailcatcher: catches emails sent by the app; read them at localhost:1080
  • cli: for running the CLI against the local setup (see below)
  • node_builder: recompiles the CSS when SCSS files change

Add -d to run in detached mode, and stop the containers with docker compose down.

The backend fills the database with development data the first time it starts (DDS_DB_TYPE, e.g. dev-small). Later starts against the same database skip this, for example after a backend restart or after changing the backend's settings in docker-compose.yml. To start over with a fresh database:

docker compose down -v
docker compose up

-v also removes the containers' volumes, which is where the database data lives. There is no need to remove images: the cached images are reused, so this takes seconds rather than a full rebuild.

If you are updating from an older setup (for example from before the switch from MinIO to SeaweedFS), remove the old containers before starting:

docker compose down --remove-orphans

Otherwise old containers that are no longer in docker-compose.yml can keep running and block ports, and the database keeps data that points to the old storage.

Second S3 storage: s3-switch

docker compose --profile s3-switch up

Also starts weedmini2, a second SeaweedFS S3 storage at localhost:9002. It is only needed for testing a switch between two S3 storages.

Stop it with docker compose --profile s3-switch down, since a plain docker compose down may leave weedmini2 running.

CLI development against local environment

The cli container runs your local checkout of dds_cli in ../dds_cli. With the containers running, shell into the dds_cli container:

docker exec -it dds_cli /bin/sh

Then you can freely use the dds cli component against the local development setup in the active CLI.

Python debugger inside docker

It's possible to use the interactive debugging tool pdb inside Docker with this method:

  1. Edit the docker-compose.yml and for the backend service, add:

    tty: true
    stdin_open: true

    just under

    ports:
      - 127.0.0.1:5000:5000
  2. Put import pdb; pdb.set_trace() in the python code where you would like to activate the debugger.

  3. Run with docker-compose as normal.

  4. Find out the id of the container running the backend.

    docker container ls
  5. Attach to the running backend container:

    docker container attach <container_id/name>

Config settings

When run from the cloned repo, all settings are set to default values. These values are publicly visible on GitHub and should not be used in production!

❗️ At the time of writing, upload within projects created in the development database will most likely not work. To use the upload functionality with the CLI, first create a project.

The following test usernames ship in the development setup:

  • superadmin
  • unituser_1
  • unituser_2
  • researchuser_1
  • researchuser_2

All have the password: password

Database changes

If you modify the database models (e.g. tables or indexes), you must create a migration for the changes. We use Alembic (via flask-migrate) which compares our database models with the running database to generate a suggested migration.

For instructions on how to do this, see the README in the migrations directory.

Run tests

Tests run on github actions on every pull request and push against master and dev. To run the tests locally, use this command:

docker compose -f docker-compose.yml -f tests/docker-compose-test.yml up --build --exit-code-from backend backend

This will create a test database in the mariadb container called DeliverySystemTest which will be populated before a test and emptied after a test has finished.

It's possible to supply arguments to pytest via the environment variable $DDS_PYTEST_ARGS. For example to only run the test_x inside the file tests/test_y.py you would set this variable as follows: export DDS_PYTEST_ARGS=tests/test_y.py::test_x.

To run interactively, use the following command:

docker compose -f docker-compose.yml -f tests/docker-compose-test-interactive.yml up --build --exit-code-from backend backend

Then in a new terminal, shell into the container and run pytest:

docker exec -it dds_backend /bin/sh
pytest

If you want to run tests quickly, without rebuilding the database each time, set the SAVE_DB environment variable:

SAVE_DB=1 pytest

Note that this stops the database from being deleted, so it will speed up the next run. Equally, if you want to tear down you need to run pytest twice without it, as it only affects the tear down.


Production Instance

The production version of the backend image is published at the GitHub Container Registry (GHCR, ghcr.io/scilifelabdatacentre/dds-backend). It can also be built by running:

docker build --target production -f Dockerfiles/backend.Dockerfile .

Use docker-compose.yml as a reference for the required environment.

Configuration

The environment variable DDS_APP_CONFIG defines the location of the config file, e.g. /code/dds_web/dds_app.cfg. The config values are listed in dds_web/config.py. Add them to the file in the format:

MAX_CONTENT_LENGTH = 0x1000000
MAX_DOWNLOAD_LIMIT = 1000000000

❗ It is recommended that you redefine all values in config.py in your config file to avoid using default values by mistake.

Initialise the database

Before you can use the system, you must run flask db upgrade to initialise the database schema and prepare for future database migrations. You can also add a superuser by running flask init-db production. In order to customize the user, make sure to set the SUPERADMIN* config options.

Upgrades

Whenever you upgrade to a newer version, start by running flask db upgrade to make sure that the database schema is up-to-date.

About

A cloud-based system for the delivery of data from SciLifeLab Facilities to their users (e.g. research group).

Topics

Resources

Contributing

Security policy

Stars

10 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages