HealthAnalyser Documentation

Getting started

Prerequisites

Have the following installed:


Download Repository

Clone repository and cd into it:

git clone git@github.com:strangeflavoured/health.git && cd "$(basename "$_" .git)"

Set up Secrets & Certificates

Install openssl and mkcert:

sudo apt install mkcert openssl
mkcert -install

Add .env file to repo root:

touch .env && chmod 600 .env

Add the necessary contents, see .env-example. You can find the location of the CA certificate by running

mkcert -CAROOT

Source .env to access the declared variables:

source .env

Generate TLS certificates for infrastructure and app client:

bash scripts/generate_certificate.sh $(mkcert -CAROOT) $REDIS_CERTS_DIR
bash scripts/generate_certificate.sh --client app $(mkcert -CAROOT) $REDIS_CERTS_DIR

Set up pass and add certificates and keys:

pass insert --multiline health/redis/certs/ca.pem < "$(mkcert -CAROOT)/rootCA.pem"
pass insert --multiline health/redis/certs/server.pem < "${REDIS_CERTS_DIR}/redis.pem"
pass insert --multiline health/redis/keys/server.key < "${REDIS_CERTS_DIR}/redis.key"
pass insert --multiline health/redis/certs/healthcheck.pem < "${REDIS_CERTS_DIR}/healthcheck.pem"
pass insert --multiline health/redis/keys/healthcheck.key < "${REDIS_CERTS_DIR}/healthcheck.key"
pass insert --multiline health/redis/certs/redisinsight.pem < "${REDIS_CERTS_DIR}/redisinsight.pem"
pass insert --multiline health/redis/keys/redisinsight.key < "${REDIS_CERTS_DIR}/redisinsight.key"
pass insert --multiline health/redis/certs/app.pem < "${REDIS_CERTS_DIR}/app.pem"
pass insert --multiline health/redis/keys/app.key < "${REDIS_CERTS_DIR}/app.key"

Generate safe passwords for redis, healthcheck, redisinsight, and app, and add them to pass, e.g. using openssl rand:

echo -n "$(openssl rand -base64 64)" | pass insert --echo health/redis/passwords/admin
echo -n "$(openssl rand -base64 32)" | pass insert --echo health/redis/passwords/healthcheck
echo -n "$(openssl rand -base64 32)" | pass insert --echo health/redis/passwords/insight
echo -n "$(openssl rand -base64 32)" | pass insert --echo health/redis/passwords/app

Using docker compose

Instead of using docker compose directly, always run

./scripts/compose-wrapper.sh up [options] [service...]

so pass secrets are injected. Similarly, to stop the services run

./scripts/stop.sh down [service...]

This will remove the tmpfs. See also docker cheatsheet.


Set up RedisInsight

Startup redis and redisinsight

./scripts/compose-wrapper.sh up -d redis redisinsight

Access http://<REDIS_HOST>:<REDIS_INSIGHT_PORT> in your browser, and add the database.


Run tests

./scripts/compose-wrapper.sh run --rm --build test-runner

Build documentation

./scripts/compose-wrapper.sh run --rm --build docs-compiler

To compile the pdf documentation (requires make) run

make -C docs/build/latex

The documentation can be found in docs/build/html/index.html and docs/build/latex/healthanalyser.pdf


Importer

Export Apple Health data and save the export.zip you obtain in data directory. Create an output directory within project root with permissions for container:

mkdir -p ./output && sudo chown 1000:1000 ./output

Run import_to_redis.py in sandbox to upload the data to Redis:

./scripts/compse-wrapper.sh up -d redis
./scripts/compose-wrapper.sh run --rm --build sandbox import_to_redis.py

Development

Install dev requirements

pip install --require-hashes -r requirements-dev.txt

Before a commit, run pre-commit and fix issues:

pre-commit run

Indices and tables