Skip to content

Latest commit

 

History

History
194 lines (135 loc) · 6.03 KB

PORT.md

File metadata and controls

194 lines (135 loc) · 6.03 KB

Port

Port is a research tool that enables individuals to donate their digital trace data for academic research in a secure, transparent, and privacy-preserving way.

Digital Data Donation Infrastructure (D3I)

The D3i project is funded by the PDI-SSH and is a collaboration between six Dutch universities and Eyra.

The consortium is composed of researchers from:

  • University of Amsterdam
  • Radboud University Nijmegen
  • VU Amsterdam
  • Utrecht University
  • Tilburg University
  • Erasmus University Rotterdam

D3i Pilot

The first phase of the project ended in December 2022 and resulted in an MVP solution to run one Port app on top of a Next bundle (see: README.md). This Next + Port combi can be released as a Docker image and deployed on Azure Web App Service.

Development instructions

Setup

  1. Pre-requisite

  2. Create a PostgreSQL database and replace the configurated values in core/config/dev.exs with your own:

    # Configure your database
    config :core, Core.Repo,
    username: "postgres",
    password: "postgres",
    database: "next_dev",
  3. Link Port app in core/assets/package.json

    See https://github.com/eyra/port-poc/blob/master/README.md on how to create your own Port app.

    Go to package.json and replace github:eyra/port with a reference to your Port app.

  4. Install tools:

    $ asdf plugin-add erlang
    $ asdf plugin-add elixir
    $ asdf plugin-add nodejs
    
    $ asdf install

    See .tool-versions for the exact versions that will be installed

  5. Install dependencies:

    $ cd core
    $ make install
  6. Build Next (from core folder):

    $ BUNDLE=next make build
  7. Run database migrations (from core folder)

    $ mix ecto.migrate
  8. Run Next locally (from core folder):

    $ BUNDLE=next make run
  9. Go to browser

    The Port app is running at: http://localhost:4000/data-donation/port. To start a donation session complete the url with:

    • App id (aka flow id). Currently we have only one Port app running with id 1.
    • Participant id. Can be any alpha numeric string).

    Example: http://localhost:4000/data-donation/port/1/tester1

Relevant Code

Source file Description
port.js Javascript hook responsible for starting the Port app and implementing the Port app System callback interface
port_page.ex Elixir/Phoenix web page running on endpoint /data-donation/port/:appid/:participantid
port_model.ex Port app configuration (id and storage configuration)
port_model_data.ex Contains configuration for Port app with id 1
delivery.ex Asynchronous delivery of donated data backed by Oban
azure_storage_backend.ex Integration with Azure Blob Storage.

Note: if you created an alternative processing worker file, don't forget to import this file port.js:

import Worker from "port/dist/framework/processing/my_new_worker.js";

Testing

Add local dependency

When testing your work it is useful to link your cloned Port app instance to your cloned Mono instance.

  1. Register Port app locally

    In the Port app:

    $ npm link
  2. Link Port app locally

    In Mono:

    $ cd core/assets
    $ npm link port
  3. Unlink

    In Mono:

    $ cd core/assets
    $ npm unlink --no-save port

Port rate limiters

To prevent users from exhausting system resources, Next uses rate limiters. The local configuration of rate limiters for Azure Blob Service can be found in core/config/dev.exs:

config :core, :rate,
  prune_interval: 5 * 1000,
  quotas: [
    [service: :azure_blob, limit: 1, unit: :call, window: :second, scope: :local],
    [service: :azure_blob, limit: 100, unit: :byte, window: :second, scope: :local]
  ]

.. and the production configuration can be found in core/config/config.exs:

config :core, :rate,
  prune_interval: 60 * 60 * 1000,
  quotas: [
    [service: :azure_blob, limit: 1000, unit: :call, window: :minute, scope: :local],
    [service: :azure_blob, limit: 10_000_000, unit: :byte, window: :day, scope: :local],
    [service: :azure_blob, limit: 1_000_000_000, unit: :byte, window: :day, scope: :global]
  ]

Release instructions

  1. Create a Docker image
$ cd core
$ docker build  --build-arg VERSION=1.0.0 --build-arg BUNDLE=next . -t next:latest
$ docker image save next -o next.zip
  1. Run the Docker image

Several environment variables are required for running:

Variable Description Example value
BUNDLE_DOMAIN domain name my-datadonation-study.azurewebsites.net
DB_USER username <my-username>
DB_PASS password <my-password>
DB_HOST hostname domain.where.database.lives
DB_NAME name of the database in the PostgreSQL next_dev
SECRET_KEY_BASE 64-bit sequence of random characters <long-sequence-of-characters>
AZURE_BLOB_STORAGE_USER name of the storage account donated data gets stored in <name-of-storage-account>
AZURE_BLOB_CONTAINER name of the storage container <name-of-storage-container>
AZURE_SAS_TOKEN token generated by Azure for tempraroy write only access to the storage account <sas-token>
STATIC_PATH should be /static /static
SSL_DISABLED SSL is handle by Azure app services should be set to true true