Skip to content

Commit

Permalink
simplify usage, explicit env variable is no longer needed
Browse files Browse the repository at this point in the history
  • Loading branch information
amatissart committed Aug 14, 2019
1 parent 5744586 commit 3d78b06
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
4 changes: 2 additions & 2 deletions docker-compose.run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions explorer/index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<!doctype html>
<head>
<meta charset="UTF-8">
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.54.0/mapbox-gl.css' rel='stylesheet'/>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v1.2.1/mapbox-gl.css' rel='stylesheet'/>
<link href='/css/app.css' rel='stylesheet'/>
<link href='/css/font.css' rel='stylesheet'/>
<link href='/css/z_index.css' rel='stylesheet'/>
</head>

<div id="root"></div>
<script src="https://api.tiles.mapbox.com/mapbox-gl-js/v0.54.0/mapbox-gl.js"></script>
<script src="https://api.tiles.mapbox.com/mapbox-gl-js/v1.2.1/mapbox-gl.js"></script>
<script src="/main.js"></script>
28 changes: 15 additions & 13 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,28 +38,23 @@ 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=<my_cosmogony_file>`

```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

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
```
17 changes: 10 additions & 7 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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",
Expand All @@ -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,
)

0 comments on commit 3d78b06

Please sign in to comment.