Skip to content

Commit

Permalink
- Changes to Dockerfile, now using ubuntu 17.10 due to protoc
Browse files Browse the repository at this point in the history
- Changes in folder structure
  • Loading branch information
TimMcCauley committed Feb 26, 2018
1 parent a2e053a commit fb33ee7
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 21 deletions.
40 changes: 40 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# gunicorn-flask

# requires this ubuntu version due to protobuf library update
FROM ubuntu:17.10
MAINTAINER Timothy Ellersiek <timothy@openrouteservice.org>

RUN apt-get update
RUN apt-get install -y python python-pip python-virtualenv gunicorn git nano

# Install protobuf
#RUN apt-get install -y autoconf automake libtool curl make g++ unzip
#RUN git clone https://github.com/google/protobuf.git protobuf
#WORKDIR /protobuf
#RUN ./autogen.sh
#RUN ./configure
#RUN make
#RUN make check
#RUN make install
#RUN ldconfig

RUN apt-get install -y build-essential protobuf-compiler libprotobuf-dev

# Setup flask application
RUN mkdir -p /deploy/app

COPY gunicorn_config.py /deploy/gunicorn_config.py
COPY manage.py /deploy/app/manage.py

COPY requirements.txt /deploy/app/requirements.txt
RUN pip install -r /deploy/app/requirements.txt

COPY openpoiservice /deploy/app/openpoiservice
COPY ops_settings_docker.yml /deploy/app/openpoiservice/server/ops_settings.yml

WORKDIR /deploy/app

EXPOSE 5000

# Start gunicorn
CMD ["/usr/bin/gunicorn", "--config", "/deploy/gunicorn_config.py", "manage:app"]
52 changes: 41 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,42 @@ to query the service via the API.

[![Build Status](https://travis-ci.org/realpython/flask-skeleton.svg?branch=master)](https://travis-ci.org/realpython/flask-skeleton)

## Quick Start
## Installation

### Basics
You can either run openpoiservice on your host machine in a virtual environment or simply with docker. The Dockerfile
installs a WSGI server (gunicorn) which starts the flask service on port 5000.

### Run as Docker Container (Flask + Gunicorn)

Make your necessary changes to the settings in `ops_settings_docker.yml`. This file will be copied to the docker container.
If you are planning to import a different osm file, please download it to the `osm folder` as this will
be a shared volume. Afterwards run:


```sh
$ docker-compose up -d -f /path/to/docker-compose.yml
```

Once the container is built you can either, create the database:

```sh
$ docker exec -it container_name python manage.py create_db
```

To delete the database:

```sh
$ docker exec -it container_name python manage.py drop_db
```

To import the OSM data:

```sh
$ docker exec -it container_name python manage.py import_data
```


### Run in Virtual Environment

1. Create and activate a virtualenv
2. This repository uses [imposm.parser](https://imposm.org/docs/imposm.parser/latest/index.html) to parse the
Expand All @@ -27,20 +60,17 @@ do the job.
- **OS X** Using homebrew` on OS X `brew install protobuf` will suffice.
3. Afterwards you can install the necessary requirements via pipwith `pip install -r requirements.txt`

### Set Environment Variables

Update *openpoiservice/server/ops_settings.yml* with your database, and then run:

```sh
$ export APP_SETTINGS="openpoiservice.server.config.ProductionConfig"
```
### Prepare settings.yml

(or
Update `openpoiservice/server/ops_settings.yml` with your necessary settings and then run one of the following
commands.

[
```sh
$ export APP_SETTINGS="openpoiservice.server.config.DevelopmentConfig"
$ export APP_SETTINGS="openpoiservice.server.config.ProductionConfig|DevelopmentConfig"
```
)
]


### Create the POI DB
Expand Down
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version: '2'
version: '3'
services:
openpoiservice-flask:
gunicorn_flask:
build: .
#volumes:
#- ./:/var/www/crypto
volumes:
- ./osm:/deploy/app/osm
ports:
- "5000:5000"
6 changes: 1 addition & 5 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)


app = create_app()
cli = FlaskGroup(create_app=create_app)

Expand Down Expand Up @@ -44,7 +43,6 @@ def drop_db():

@cli.command()
def import_data():

"""Imports osm pbf data to postgis."""

db.drop_all()
Expand All @@ -54,10 +52,8 @@ def import_data():
logger.info("Starting to import data...")

# add option to add multiple osm pbf files
parser.run_import(os.path.join(os.getcwd(), ops_settings['osm_file']))
parser.run_import(os.path.join(os.getcwd() + '/osm', ops_settings['osm_file']))


if __name__ == '__main__':

cli()

2 changes: 1 addition & 1 deletion openpoiservice/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def create_app(self):
def setUp(self):
db.create_all()

parser.run_import(os.path.join(os.getcwd(), ops_settings['osm_file_tests']))
parser.run_import(os.path.join(os.getcwd() + '/osm', ops_settings['osm_file_tests']))

def tearDown(self):
db.session.remove()
Expand Down
46 changes: 46 additions & 0 deletions ops_settings_docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
attribution: "openrouteservice.org | OpenStreetMap contributors"
maximum_categories: 5
# meters
maximum_search_radius_for_linestrings: 2000
maximum_search_radius_for_points: 2000
maximum_search_radius_for_polygons: 2000
# square meters
maximum_area: 25000
# meters
maximum_linestring_length: 500000
# limit of pois
response_limit: 2000
osm_file: bremen-latest.osm.pbf
osm_file_tests: bremen-tests.osm.pbf

provider_parameters:
table_name: ops_planet_pois
db_name: gis
user_name: gis_admin
password: admin
host: localhost
port: 5433
column_mappings:
# https://wiki.openstreetmap.org/wiki/Key:name
name:
common_values: ['str']
filterable: 'like'
# https://wiki.openstreetmap.org/wiki/Key:wheelchair
wheelchair:
common_values: ['yes', 'limited', 'no', 'designated']
filterable: 'equals'
# https://wiki.openstreetmap.org/wiki/Key:smoking
smoking:
common_values: ['dedicated','yes','separated','isolated', 'no', 'outside']
filterable: 'equals'
# https://wiki.openstreetmap.org/wiki/Key:fee
fee:
common_values: ['yes','no', 'str']
filterable: 'equals'
# https://wiki.openstreetmap.org/wiki/Key:opening_hours
opening_hours:
# https://wiki.openstreetmap.org/wiki/Key:phone
phone:
# https://wiki.openstreetmap.org/wiki/Key:website
website:
File renamed without changes.
File renamed without changes.

0 comments on commit fb33ee7

Please sign in to comment.