From 3d78b0644f0b036e64030c7f698e10bcedd3dfb5 Mon Sep 17 00:00:00 2001 From: Adrien M Date: Wed, 14 Aug 2019 08:53:27 +0200 Subject: [PATCH] simplify usage, explicit env variable is no longer needed --- docker-compose.run.yml | 4 ++-- explorer/index.html | 4 ++-- readme.md | 28 +++++++++++++++------------- tasks.py | 17 ++++++++++------- 4 files changed, 29 insertions(+), 24 deletions(-) diff --git a/docker-compose.run.yml b/docker-compose.run.yml index 0b587ee..1bab4cc 100644 --- a/docker-compose.run.yml +++ b/docker-compose.run.yml @@ -8,10 +8,10 @@ services: image: osmwithoutborders/cosmogony-importer env_file: .env volumes: - - ${PATH_TO_COSMOGONY_DIR:-./cosmogony_data}:/mnt/data + - ${PATH_TO_COSMOGONY_DIR:-./cosmogony_data}:/mnt/data:ro data-dashboard: image: osmwithoutborders/cosmogony-data-dashboard volumes: - - ${PATH_TO_COSMOGONY_DIR:-./cosmogony_data}:/mnt/data + - ${PATH_TO_COSMOGONY_DIR:-./cosmogony_data}:/mnt/data:ro - data-dashboard:/mnt/data-dashboard diff --git a/explorer/index.html b/explorer/index.html index 5055555..34592b4 100644 --- a/explorer/index.html +++ b/explorer/index.html @@ -1,12 +1,12 @@ - +
- + diff --git a/readme.md b/readme.md index d5957d8..dcc5538 100644 --- a/readme.md +++ b/readme.md @@ -6,6 +6,13 @@ The main goal of this tool is to have some visual and geographical feedback on [ ## Install +#### Requirements + + * docker + * docker-compose + * python >= 3.6 + +#### Quick guide to install Docker on Ubuntu ```bash sudo apt update sudo apt install apt-transport-https ca-certificates curl software-properties-common @@ -31,22 +38,17 @@ You may need to run it with `sudo`, as it launches `docker-compose` commands. The easiest way to run it: ```bash -pipenv install -``` +# Install python dependencies in a new virtualenv +pipenv install --deploy -```bash -pipenv run inv -e run-local +# Start cosmogony explorer services and import cosmogony data from an input file +pipenv run inv -e run-local cosmogony.json ``` -You can set a path to the cosmogony data by changing the environment variable `PATH_TO_COSMOGONY_DIR`. -You can do this either just with a classic environment variable, or by changing the file `.env`. -By default it will load the data in the `./cosmogony_data/` directory. +Accepted cosmogony formats are `.json` and `.jsonl.gz`. -By default it will load a file named `cosmogony.json` in this directory. You can change the file name with the cli parameter `--cosmogony-file-name=` - -```bash -PATH_TO_COSMOGONY_DIR=./my_data_dir pipenv run inv -e run-local --cosmogony-file-name=cosmo_lux.json -``` +> Note that during the import process the directory where the cosmogony file is located will +be mounted as a read-only docker volume. ## Development @@ -54,5 +56,5 @@ If you want to change stuff in the repository, you need to build custom images. To do this, you just need to add the `--build-dockers` argument to the `invoke` commands: ```bash -PATH_TO_COSMOGONY_DIR=./my_data_dir pipenv run inv -e run-local --cosmogony-file-name=cosmo_lux.json --build-dockers +pipenv run inv -e run-local cosmogony.json --build-dockers ``` diff --git a/tasks.py b/tasks.py index 3e1966f..1564304 100644 --- a/tasks.py +++ b/tasks.py @@ -6,7 +6,7 @@ @task() -def run_local(ctx, cosmogony_file_name="cosmogony.json", build_dockers=False): +def run_local(ctx, cosmogony_file_name, build_dockers=False): pop_stack(ctx, build_dockers) run_explorer(ctx, cosmogony_file_name, restart_tiles=True) open_browser(ctx) @@ -15,9 +15,12 @@ def run_local(ctx, cosmogony_file_name="cosmogony.json", build_dockers=False): def open_browser(ctx): explorer_port = ctx.run(""" docker inspect -f '{{(index .NetworkSettings.Ports "80/tcp" 0).HostPort}}' $(docker-compose ps -q explorer) - """) + """, hide=True) port = explorer_port.stdout.split('\n')[0] - ctx.run(f"sensible-browser 'http://localhost:{port}/#/2.5/32/0'") + explorer_url = f'http://localhost:{port}' + print(f'Cosmogony explorer is running on {explorer_url}') + if ctx.run('which sensible-browser', warn=True, hide=True).ok: + ctx.run(f"sensible-browser '{explorer_url}/#/2.5/32/0'") @task() @@ -37,8 +40,7 @@ def _run_container(ctx, container_name, job, cosmogony_data_dir=None): @task(default=True) def run_explorer(ctx, cosmogony_file_name="cosmogony.json", restart_tiles=False): - cosmogony_data_dir, cosmogony_file_name = os.path.split(cosmogony_file_name) - cosmogony_data_dir = cosmogony_data_dir or None + cosmogony_data_dir, cosmogony_file_name = os.path.split(os.path.realpath(cosmogony_file_name)) path_in_container = f"/mnt/data/{cosmogony_file_name}" _run_container(ctx, "importer", @@ -57,16 +59,17 @@ def run_explorer(ctx, cosmogony_file_name="cosmogony.json", restart_tiles=False) if restart_tiles: ctx.run("docker-compose restart tiles", pty=True) - generate_data_dashboard(ctx, cosmogony_file_name) + generate_data_dashboard(ctx, cosmogony_file_name, cosmogony_data_dir) def _get_docker_compose(): return os.environ.get("COMPOSE_FILE", "docker-compose.yml") @task() -def generate_data_dashboard(ctx, cosmogony_file_name="cosmogony.json"): +def generate_data_dashboard(ctx, cosmogony_file_name, cosmogony_data_dir): _run_container( ctx, "data-dashboard", f"--cosmogony=/mnt/data/{cosmogony_file_name} --output=/mnt/data-dashboard/test_results.json", + cosmogony_data_dir=cosmogony_data_dir, )