Rework Docker setup, provide for remote DB, add example JSON
This commit is contained in:
parent
1f8741a14b
commit
6ef16787ab
8 changed files with 96 additions and 22 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -2,4 +2,4 @@
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.py[cod]
|
*.py[cod]
|
||||||
*$py.class
|
*$py.class
|
||||||
|
.DS_Store
|
||||||
|
|
15
Dockerfile
15
Dockerfile
|
@ -1,15 +0,0 @@
|
||||||
FROM ubuntu:15.10
|
|
||||||
WORKDIR /setup
|
|
||||||
RUN apt-get update
|
|
||||||
RUN apt-get install -y postgresql-9.4
|
|
||||||
RUN apt-get install -y postgresql-server-dev-9.4
|
|
||||||
RUN apt-get install -y postgis
|
|
||||||
RUN apt-get install -y python3-dev
|
|
||||||
RUN apt-get install -y python3-pip
|
|
||||||
RUN pip3 install --system uwsgi
|
|
||||||
ADD /setup* /setup/
|
|
||||||
ADD /requirements.txt /setup/
|
|
||||||
USER postgres
|
|
||||||
RUN service postgresql start && /setup/setup.sh
|
|
||||||
WORKDIR /app
|
|
||||||
CMD service postgresql start && uwsgi --http :8080 --wsgi-file backend.py --callable app
|
|
10
Dockerfile-backend
Normal file
10
Dockerfile-backend
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
FROM ubuntu:15.10
|
||||||
|
RUN apt-get update
|
||||||
|
RUN apt-get install -y postgresql-server-dev-all
|
||||||
|
RUN apt-get install -y python3-dev
|
||||||
|
RUN apt-get install -y python3-pip
|
||||||
|
RUN pip3 install uwsgi
|
||||||
|
ADD /requirements.txt /app/
|
||||||
|
WORKDIR /app
|
||||||
|
RUN pip3 install -r requirements.txt
|
||||||
|
CMD uwsgi --http :8080 --wsgi-file backend.py --callable app
|
4
Dockerfile-postgres
Normal file
4
Dockerfile-postgres
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
FROM postgres:9.5
|
||||||
|
RUN apt-get update
|
||||||
|
RUN apt-get install -y postgis
|
||||||
|
ADD /setup.sql /docker-entrypoint-initdb.d/
|
13
backend.py
13
backend.py
|
@ -1,14 +1,21 @@
|
||||||
# backend.py
|
# backend.py
|
||||||
# openeventdatabase
|
# openeventdatabase
|
||||||
|
|
||||||
|
import os
|
||||||
import falcon
|
import falcon
|
||||||
import psycopg2
|
import psycopg2
|
||||||
import uuid
|
import uuid
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
def db_connect():
|
||||||
|
db_host = os.getenv("DB_HOST","localhost")
|
||||||
|
db_password = os.getenv("POSTGRES_PASSWORD","")
|
||||||
|
db = psycopg2.connect(dbname="oedb",host=db_host,password=db_password,user="postgres")
|
||||||
|
return db
|
||||||
|
|
||||||
class StatsResource(object):
|
class StatsResource(object):
|
||||||
def on_get(self, req, resp):
|
def on_get(self, req, resp):
|
||||||
db = psycopg2.connect("dbname=oedb")
|
db = db_connect()
|
||||||
cur = db.cursor()
|
cur = db.cursor()
|
||||||
cur.execute("SELECT count(*) as events_count, max(createdate) as last_created, max(lastupdate) as last_updated from events;")
|
cur.execute("SELECT count(*) as events_count, max(createdate) as last_created, max(lastupdate) as last_updated from events;")
|
||||||
stat = cur.fetchone()
|
stat = cur.fetchone()
|
||||||
|
@ -23,7 +30,7 @@ class StatsResource(object):
|
||||||
|
|
||||||
class EventResource(object):
|
class EventResource(object):
|
||||||
def on_get(self, req, resp, id):
|
def on_get(self, req, resp, id):
|
||||||
db = psycopg2.connect("dbname=oedb")
|
db = db_connect()
|
||||||
cur = db.cursor()
|
cur = db.cursor()
|
||||||
# get event geojson Feature
|
# get event geojson Feature
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
|
@ -66,7 +73,7 @@ WHERE events_id=%s;""", (id,))
|
||||||
else:
|
else:
|
||||||
when = "["+event_start+", "+event_stop+")"
|
when = "["+event_start+", "+event_stop+")"
|
||||||
# connect to db and insert
|
# connect to db and insert
|
||||||
db = psycopg2.connect("dbname=oedb")
|
db = db_connect()
|
||||||
cur = db.cursor()
|
cur = db.cursor()
|
||||||
# get the geometry part
|
# get the geometry part
|
||||||
geometry=json.dumps(j['geometry'])
|
geometry=json.dumps(j['geometry'])
|
||||||
|
|
21
docker-compose.yml
Normal file
21
docker-compose.yml
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
version: '2'
|
||||||
|
|
||||||
|
services:
|
||||||
|
postgres:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile-postgres
|
||||||
|
environment:
|
||||||
|
POSTGRES_DB: oedb
|
||||||
|
POSTGRES_PASSWORD:
|
||||||
|
backend:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile-backend
|
||||||
|
ports:
|
||||||
|
- 8080:8080
|
||||||
|
environment:
|
||||||
|
DB_HOST: postgres
|
||||||
|
POSTGRES_PASSWORD:
|
||||||
|
volumes:
|
||||||
|
- .:/app/
|
50
examples/event.json
Normal file
50
examples/event.json
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
{
|
||||||
|
"geometry":
|
||||||
|
{
|
||||||
|
"type": "Polygon",
|
||||||
|
"coordinates": [
|
||||||
|
[
|
||||||
|
[
|
||||||
|
2.3581337928771973,
|
||||||
|
48.9261508727225
|
||||||
|
],
|
||||||
|
[
|
||||||
|
2.3581552505493164,
|
||||||
|
48.925847757044224
|
||||||
|
],
|
||||||
|
[
|
||||||
|
2.3575007915496826,
|
||||||
|
48.9258266093701
|
||||||
|
],
|
||||||
|
[
|
||||||
|
2.3577260971069336,
|
||||||
|
48.92278125079759
|
||||||
|
],
|
||||||
|
[
|
||||||
|
2.3581552505493164,
|
||||||
|
48.92259795940312
|
||||||
|
],
|
||||||
|
[
|
||||||
|
2.3625540733337402,
|
||||||
|
48.92277420114101
|
||||||
|
],
|
||||||
|
[
|
||||||
|
2.362285852432251,
|
||||||
|
48.92628480697097
|
||||||
|
],
|
||||||
|
[
|
||||||
|
2.3581337928771973,
|
||||||
|
48.9261508727225
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
,
|
||||||
|
"properties":{
|
||||||
|
"type":"football"
|
||||||
|
,"what":"France-Roumanie 2016"
|
||||||
|
,"what:series":"Euro 2016"
|
||||||
|
,"start":"2016-06-10T21:00+01:00"
|
||||||
|
,"stop":"2016-06-10T23:30+01:00"
|
||||||
|
}
|
||||||
|
}
|
3
setup.sh
3
setup.sh
|
@ -1,3 +0,0 @@
|
||||||
pip3 install -r requirements.txt
|
|
||||||
createdb oedb
|
|
||||||
psql oedb < setup.sql
|
|
Loading…
Add table
Add a link
Reference in a new issue