Skip to content

Commit

Permalink
Merge pull request #9 from webb-ben/postgres
Browse files Browse the repository at this point in the history
Postgres
  • Loading branch information
Kyle Onda authored Sep 16, 2021
2 parents 77ae91c + 27e31b8 commit f23899e
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 1,319 deletions.
9 changes: 1 addition & 8 deletions pygeoapi/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM geopython/pygeoapi:latest
FROM webbben/pygeoapi-river-runner:latest

#Add data directory
RUN mkdir /data
Expand All @@ -16,10 +16,3 @@ ADD https://www.hydroshare.org/resource/4a22e88e689949afa1cf71ae009eaf1b/data/co
COPY ./pygeoapi.config.yml /pygeoapi/local.config.yml
COPY ./schemas.opengis.net /opt/schemas.opengis.net
COPY ./pygeoapi-skin-dashboard /skin-dashboard

#Add river runner plugin
COPY ./plugin.py /pygeoapi/pygeoapi/plugin.py
COPY ./flask_app.py /pygeoapi/pygeoapi/flask_app.py
COPY ./river_runner.py /pygeoapi/pygeoapi/process/river_runner.py
COPY ./sqlite.py /pygeoapi/pygeoapi/provider/sqlite.py
COPY ./map.html /pygeoapi/pygeoapi/templates/processes/map.html
9 changes: 1 addition & 8 deletions pygeoapi/Dockerfile_gcp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM geopython/pygeoapi:latest
FROM webbben/pygeoapi-river-runner:latest

#Add data directory
RUN mkdir /data
Expand All @@ -16,10 +16,3 @@ ADD https://www.hydroshare.org/resource/4a22e88e689949afa1cf71ae009eaf1b/data/co
COPY ./pygeoapi.config.gcp.yml /pygeoapi/local.config.yml
COPY ./schemas.opengis.net /opt/schemas.opengis.net
COPY ./pygeoapi-skin-dashboard /skin-dashboard

#Add river runner plugin
COPY ./plugin.py /pygeoapi/pygeoapi/plugin.py
COPY ./flask_app.py /pygeoapi/pygeoapi/flask_app.py
COPY ./river_runner.py /pygeoapi/pygeoapi/process/river_runner.py
COPY ./sqlite.py /pygeoapi/pygeoapi/provider/sqlite.py
COPY ./map.html /pygeoapi/pygeoapi/templates/processes/map.html
9 changes: 9 additions & 0 deletions pygeoapi/Dockerfile_loader
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM webbben/pygeoapi-river-runner:latest

ADD https://svn.osgeo.org/gdal/trunk/gdal/swig/python/samples/ogr2ogr.py /pygeoapi/ogr2ogr.py

COPY ./entrypoint.sh /entrypoint.sh
RUN ["chmod", "+x", "/entrypoint.sh"]

WORKDIR /pygeoapi
ENTRYPOINT ["/entrypoint.sh"]
39 changes: 29 additions & 10 deletions pygeoapi/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,36 @@ version: "3"
services:

pygeoapi:
image: geopython/pygeoapi:latest
ports:
- 5050:80
build:
context: .
dockerfile: Dockerfile_loader
restart: always
ports:
- 5000:80
depends_on:
- db
environment:
POSTGRES_HOST: db
POSTGRES_USER: root
POSTGRES_PASSWORD: password
POSTGRES_DB: merit
volumes:
- ./pygeoapi.config.yml:/pygeoapi/local.config.yml
- ./merit_plus_simplify.gpkg:/data/merit_plus_simplify.gpkg
- ./e_merit_cats.gpkg:/data/e_merit_cats.gpkg
- ./w_merit_cats.gpkg:/data/w_merit_cats.gpkg
- ./plugin.py:/pygeoapi/pygeoapi/plugin.py
- ./flask_app.py:/pygeoapi/pygeoapi/flask_app.py
- ./river_runner.py:/pygeoapi/pygeoapi/process/river_runner.py
- ./sqlite.py:/pygeoapi/pygeoapi/provider/sqlite.py
- ./map.html:/pygeoapi/pygeoapi/templates/processes/map.html
- ./schemas.opengis.net:/opt/schemas.opengis.net

db:
image: kartoza/postgis:latest
restart: always
ports:
- 5432:5432
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: password
POSTGRES_DB: merit

adminer:
image: adminer
restart: always
ports:
- 8080:8080
119 changes: 119 additions & 0 deletions pygeoapi/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/bin/bash
# =================================================================
#
# Authors: Just van den Broecke <[email protected]>
#
# Copyright (c) 2019 Just van den Broecke
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
# =================================================================

# pygeoapi entry script

echo "START /entrypoint.sh"

set +e

export PYGEOAPI_HOME=/pygeoapi
export PYGEOAPI_CONFIG="${PYGEOAPI_HOME}/local.config.yml"
export PYGEOAPI_OPENAPI="${PYGEOAPI_HOME}/local.openapi.yml"

# gunicorn env settings with defaults
SCRIPT_NAME=${SCRIPT_NAME:=/}
CONTAINER_NAME=${CONTAINER_NAME:=pygeoapi}
CONTAINER_HOST=${CONTAINER_HOST:=0.0.0.0}
CONTAINER_PORT=${CONTAINER_PORT:=80}
WSGI_WORKERS=${WSGI_WORKERS:=4}
WSGI_WORKER_TIMEOUT=${WSGI_WORKER_TIMEOUT:=6000}
WSGI_WORKER_CLASS=${WSGI_WORKER_CLASS:=gevent}

# What to invoke: default is to run gunicorn server
entry_cmd=${1:-run}

# Shorthand
function error() {
echo "ERROR: $@"
exit -1
}

# Workdir
cd ${PYGEOAPI_HOME}

# Load postgis data
sleep 5
echo "Verifying postgis database has data"
python3 ogr2ogr.py \
-f PostgreSQL \
PG:"host='${POSTGRES_HOST}' \
user='${POSTGRES_USER}' \
password='${POSTGRES_PASSWORD}' \
dbname='${POSTGRES_DB}'" \
/data/merit_plus_simplify.gpkg \

echo "Trying to generate openapi.yml"
pygeoapi openapi generate ${PYGEOAPI_CONFIG} > ${PYGEOAPI_OPENAPI}

[[ $? -ne 0 ]] && error "openapi.yml could not be generated ERROR"

echo "openapi.yml generated continue to pygeoapi"

case ${entry_cmd} in
# Run Unit tests
test)
for test_py in $(ls tests/test_*.py)
do
# Skip tests requireing backend server or libs installed
case ${test_py} in
tests/test_elasticsearch__provider.py)
;&
tests/test_postgresql_provider.py)
;&
tests/test_mongo_provider.py)
echo "Skipping: ${test_py}"
;;
*)
python3 -m pytest ${test_py}
;;
esac
done
;;

# Run pygeoapi server
run)
# SCRIPT_NAME should not have value '/'
[[ "${SCRIPT_NAME}" = '/' ]] && export SCRIPT_NAME="" && echo "make SCRIPT_NAME empty from /"

echo "Start gunicorn name=${CONTAINER_NAME} on ${CONTAINER_HOST}:${CONTAINER_PORT} with ${WSGI_WORKERS} workers and SCRIPT_NAME=${SCRIPT_NAME}"
exec gunicorn --workers ${WSGI_WORKERS} \
--worker-class=${WSGI_WORKER_CLASS} \
--timeout ${WSGI_WORKER_TIMEOUT} \
--name=${CONTAINER_NAME} \
--bind ${CONTAINER_HOST}:${CONTAINER_PORT} \
pygeoapi.flask_app:APP
;;
*)
error "unknown command arg: must be run (default) or test"
;;
esac

echo "END /entrypoint.sh"
Loading

0 comments on commit f23899e

Please sign in to comment.