Skip to content

Commit

Permalink
working version
Browse files Browse the repository at this point in the history
  • Loading branch information
antoine-de committed Oct 24, 2018
1 parent cd45679 commit 17efdc3
Show file tree
Hide file tree
Showing 14 changed files with 170 additions and 70 deletions.
1 change: 0 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ POSTGRES_USER=cosmogony
POSTGRES_PASSWORD=cosmogony
POSTGRES_HOST=postgres
POSTGRES_PORT=5432

17 changes: 17 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[[source]]

url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"

[requires]

python_version = "3.6"

[dev-packages]



[packages]

invoke = "*"
42 changes: 42 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions docker-compose.build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: "3"

services:
tiles:
build: ./tiles
image: osmwithoutborders/cosmogony-tiles

api:
build: ./api
image: osmwithoutborders/cosmogony-api

explorer:
build: ./explorer
image: osmwithoutborders/cosmogony-explorer

importer:
build: ./importer
image: osmwithoutborders/cosmogony-importer
18 changes: 18 additions & 0 deletions docker-compose.run.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: "3"

volumes:
data-dashboard:

services:
importer:
image: osmwithoutborders/cosmogony-importer
env_file: .env
volumes:
- ${PATH_TO_COSMOGONY_DIR:-./cosmogony_data}:/mnt/data

data-dashboard:
image: cosmogony-data-dashboard
# image: osmwithoutborders/cosmogony-data-dashboard
volumes:
- ${PATH_TO_COSMOGONY_DIR:-./cosmogony_data}:/mnt/data
- data-dashboard:/mnt/data-dashboard
33 changes: 18 additions & 15 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
version: "3"

volumes:
pgdata:
data-dashboard:

services:
postgres:
image: "openmaptiles/postgis:2.9"
volumes:
- pgdata:/var/lib/postgresql/data
ports:
- 127.0.0.1:5432:5432
- 5432
env_file: .env
cosmogony-importer:
build: ./importer
env_file: .env
depends_on:
- postgres
cosmogony-tiles:
build: ./tiles

tiles:
image: osmwithoutborders/cosmogony-tiles
env_file: .env
depends_on:
- postgres
ports:
- 127.0.0.1:6767:6767
cosmogony-api:
build: ./api
- 6767

api:
image: osmwithoutborders/cosmogony-api
env_file: .env
depends_on:
- postgres
ports:
- 127.0.0.1:8000:8000
- 8000

explorer:
build: ./explorer
image: osmwithoutborders/cosmogony-explorer
depends_on:
- cosmogony-api
- api
ports:
- 8585:80
- 8585:80 # TODO remove this
volumes:
- data-dashboard:/mnt/data_dashboard
2 changes: 0 additions & 2 deletions explorer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ RUN cd /tmp/cosmo_build &&\
node ./node_modules/webpack/bin/webpack --mode='production' && \
rm -rf ./node_modules



FROM nginx:alpine
COPY nginx.vh.default.conf /etc/nginx/conf.d/default.conf
COPY --from=builder /tmp/cosmo_build/ /usr/share/nginx/html/
11 changes: 9 additions & 2 deletions explorer/nginx.vh.default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,21 @@ server {
}

location /tiles/ {
proxy_pass http://cosmogony-tiles:6767/;
proxy_pass http://tiles:6767/;
}

location /api/ {
proxy_pass http://cosmogony-api:8000/;
proxy_pass http://api:8000/;
add_header 'Access-Control-Allow-Origin' '*';
}

location /data {
# In the dockerfile we mounted the file generated by https://github.com/osm-without-borders/cosmogony-data-dashboard
# in /mnt/data_dashboard
alias /mnt/data_dashboard;
}


#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
Expand Down
1 change: 1 addition & 0 deletions explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"webpack-cli": "^2.0.4"
},
"dependencies": {
"axios": "^0.18.0",
"ejs": "^2.6.1",
"expressjs": "^1.0.1"
}
Expand Down
16 changes: 12 additions & 4 deletions explorer/src/vues/routes/data_dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,21 @@
</template>

<script>
import testResults from '../../data/test_results'
import axios from "axios";
export default {
name: "data_dashboard",
data : function () {
data () {
return {
testResults
testResults: null
}
}
},
mounted() {
axios({ method: "GET", "url": "/data/test_results.json" }).then(result => {
this.testResults = result.data;
}, error => {
console.error(error);
});
},
}
</script>
2 changes: 0 additions & 2 deletions importer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,3 @@ RUN pip install pipenv
RUN pipenv install --system --deploy

RUN chmod +x import.py

CMD sleep infinity
22 changes: 18 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

The main goal of this tool is to have some visual and geographical feedback on [Cosmogony](https://github.com/osm-without-borders/cosmogony) output.

:construction::warning: This is a work in progress, and deeply connected to the Cosmogony output format :construction::warning:

![cosmogony demo](./demo.gif)


Expand All @@ -12,8 +10,24 @@ The main goal of this tool is to have some visual and geographical feedback on [
This will run docker-compose containers, import the cosmogony zones to
Postgis, pre-generate tiles, and launch the explorer in your browser.


You may need to run it with `sudo`, as it launches `docker-compose` commands.

The easiest way to run it:

```bash
pipenv install
```

```bash
pipenv run inv -e run-local
```

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.

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
./run_explorer.sh cosmogony.json
PATH_TO_COSMOGONY_DIR=./my_data_dir pipenv run inv -e run-local --cosmogony-file-name=cosmo_lux.json
```
23 changes: 0 additions & 23 deletions run_explorer.sh

This file was deleted.

34 changes: 17 additions & 17 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,40 @@
logging.basicConfig(level=logging.INFO)

@task()
def run_local(ctx, cosmogony_file, build_dockers=False):
def run_local(ctx, cosmogony_file_name='cosmogony.json', build_dockers=False):
pop_stack(ctx)
run_explorer(ctx, cosmogony_file, use_local_file=True)
run_explorer(ctx, cosmogony_file_name)
ctx.run("sensible-browser 'http://localhost:8585/#/2.5/32/0'")

@task()
def pop_stack(ctx, build_dockers=False):
if build_dockers:
ctx.run("docker-compose build --pull")
ctx.run("docker-compose up -d")
ctx.run("sleep 10") # TODO do better to wait for pg
ctx.run("sleep 5") # TODO do better to wait for pg

@task(default=True)
def run_explorer(ctx, cosmogony_file, use_local_file=False):
def _run_container(ctx, container_name, job):
main_docker_files = _get_docker_compose()
run_docker_files = {'COMPOSE_FILE': main_docker_files + ':docker-compose.run.yml'}
ctx.run(f"docker-compose run --rm {container_name} {job}", env=run_docker_files)

if use_local_file:
# TODO com'
file_name = os.path.basename(cosmogony_file)
path_in_container = f"/mnt/data/{file_name}"
volume = f"-v `dirname $(realpath {cosmogony_file})`:/mnt/data"
else:
# TODO com'
volume = ""
path_in_container = cosmogony_file

ctx.run(f"docker-compose run --rm {volume} importer ./import.py import_data {path_in_container}", env=run_docker_files)
@task(default=True)
def run_explorer(ctx, cosmogony_file_name='cosmogony.json'):

path_in_container = f'/mnt/data/{cosmogony_file_name}'
_run_container(ctx, "importer", f"./import.py import_data {path_in_container}")

ctx.run("docker-compose exec tiles /usr/bin/t_rex generate -c /config_generate.toml --minzoom 0 --maxzoom 6 --overwrite true --progress true", pty=True)

ctx.run("docker-compose run --rm importer ./import.py publish", env=run_docker_files)
_run_container(ctx, "importer", f"./import.py publish")
ctx.run("docker-compose exec tiles /publish_tiles.sh", pty=True)

generate_data_dashboard(ctx, cosmogony_file_name)

def _get_docker_compose():
return os.environ.get('COMPOSE_FILE', 'docker-compose.yml')

@task()
def generate_data_dashboard(ctx, cosmogony_file_name='cosmogony.json'):
_run_container(ctx, "data-dashboard", f"--cosmogony=/mnt/data/{cosmogony_file_name} --output=/mnt/data-dashboard/test_results.json")

0 comments on commit 17efdc3

Please sign in to comment.