Skip to content

Commit

Permalink
Merge pull request #50 from jorgejesus/pywps_4.2
Browse files Browse the repository at this point in the history
Pywps 4.2.1 implementation
  • Loading branch information
Jorge Samuel Mendes de Jesus authored Feb 9, 2019
2 parents 86db2e4 + cc493f9 commit 6952875
Show file tree
Hide file tree
Showing 18 changed files with 252 additions and 147 deletions.
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
language: python

dist: xenial

python:
- "2.7"
- "3.4"
Expand All @@ -9,8 +12,8 @@ git:

install:
- sudo apt-get update -qq
- sudo apt-get install -qq gdal-bin libgdal-dev libgdal1h libgdal1-dev libgeos-dev python-dev python3-dev
- pip install GDAL==1.10.0 --global-option=build_ext --global-option="-I/usr/include/gdal"
- sudo apt-get install -qq gdal-bin libgdal1i libgdal1-dev libgdal-dev libgeos-dev python-dev python3-dev
- pip install GDAL==1.11.1 --global-option=build_ext --global-option="-I/usr/include/gdal"
- pip install -r requirements.txt

before_script:
Expand Down
196 changes: 148 additions & 48 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,100 +1,134 @@
PyWPS demo with docker support
==============================
Clone pywps-flask, install libraries, build docker image (due to GDAL compiling lasts quite long)::
============
Installation
============

The app depends on PyWPS and several other libraries that are listed in
``requirements.txt``. It is advisable to run it using a python virtualenv to prevent package instalation problems::

$ virtualenv -p python3 pywps_flask_env
$ cd pywps_flask_dir
$ . bin/activate
$ git clone https://github.com/geopython/pywps-flask
$ cd pywps-flask
$ pip3 install -r requirements.txt
$ cd pywps-flask/docker/alpine/flask
$ docker build -t pywps_container .


Clone pywps and OWSLib::
If python virtualenv is not an option::

$ git clone https://github.com/lazaa32/pywps.git
$ git clone https://github.com/lazaa32/OWSLib.git
$ git clone https://github.com/geopython/pywps-flask
$ cd pywps-flask
$ pip3 install -r requirements.txt

Set PYTHONPATH::

$ export PYTHONPATH=$PYTHONPATH:$PWD/OWSLib:$PWD/pywps

Run server::
For Debian based systems you will need to install GDAL with::

python3 demo.py
$ sudo apt-get install python3-gdal


PyWPS example service
========================
When using only using `requirement.txt`, the `pywps-flask` will run for the directory that was pulled from github, for a system wise installation is it advisable to use `setup.py`::

This is a simple example service written using PyWPS. It has been tested with
QGIS 1.8.
$ git clone https://github.com/geopython/pywps-flask
$ cd pywps-flask
$ python3 setup.py install


Installation
------------
The app depends on PyWPS and several other libraries that are listed in
``requirements.txt``. You can install them with pip::

$ pip install -r requirements.txt
=======
Running
=======

For Debian based systems you will need to install GDAL with::
Simply run the python file::

$ sudo apt-get install python-gdal
$ python3 demo.py -a

For Windows systems install you need to install Shapely and GDAL by using Python Wheels.
If you have Shapely already installed you might have to uninstall it and installed as a Wheel for it to work::
The flag `-a` will bind to the ip range `0.0.0.0` and is normally the safest option access to `pypwps-flask`

Download the corresponding wheel for Shapely: http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely
The `-d` option will run pywps-flask as daemon and to stop it is necessary to determine the PID and kill it, one trick is to use fuser to determine PID, and then use it to kill the process::

Download the corresponding wheel for GDAL: http://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal
$ fuser tcp/5000
$ kill -15 <PID RETURNED PREVIOUSLY>

$ pip install wheel

$ pip install Shapely?x.x.x?cpxx?none?win_xxx.whl

$ pip install GDAL?x.x.x?cpxx?none?win_xxx.whl
==============
Docker images
==============

The docker folder contains 2 subfolders, each subfolder contains a differente pywps implementation.

Running
-------
Simply run the python file::
Folder ``flask`` has the default pywps-flask implementation using only Flask while folder ``nginx`` implements pywps using Nginx and Green unicorn as WSGI server. While folder ``ubuntu`` has the same images but using phusion image (ubuntu 18.04)


$ python demo.py

Flask-Alpine (basic)
--------------------

Docker
------
The docker folder contains 2 subfolders, each subfolder contains a differente pywps implementation. Folder ``flask``
has the default pywps-flask implementation using only Flask while folder ``nginx`` implements pywps using Nginx and Green unicorn as WSGI server.
Basic pywps image is based on Alpine 3.8 and will run the native Flask service, this is not apropriate for production. The docker file can be found in: ``docker/alpine/flask/Dockerfile``


Docker-flask
------------

To build the image (inside the folder with the Dockerfile)::

$ docker build -t pywps4-demo:latest .
$ docker build -t pywps/flask-alpine .

And to run it::

$ docker run -p 5000:5000 pywps4-demo:latest
$ docker run -p 5000:5000 pywps/flask-alpine:latest


Pywps will be available in the following URL::

$ http://localhost:5000


Docker-nginx

Gunicorn-Alpine (production)
----------------------------

This image implements the previous ``flask-alpine image`` (you need to build it first, or it will be automatically pulled from dockerhub) but wrapping flask in a WSGI server (gunicorn) where each worker runs a an app. This image allows for the following environment variables:

- GU_WORKERS - Numer or workers. Gunicorn uses a set of workers to run pywps (normally ``workers = (2 * cpu) + 1``). (default: 5)
- GU_PORT - Port running Gunicorn (default:8081)



Gunicorn-Alpine is locate in folder ``docker/alpine/gunicorn/Dockerfile``

This image can already be implemented in production but it is advisable to use Nginx for HTTP load balance and Gunicorn as WSGI server (see below)

To build the image (inside the folder with the Dockerfile)::

$ docker build -t pywps/gunicorn-alpine:latest .


And to run it::

$ docker run -p 8081:8081 -it pywps/gunicorn-alpine:latest

or::
$ docker run -e GU_WORKERS=10 -e GU_PORT=8082 -p 8082:8082 -it pywps/gunicorn-alpine:latest

Pywps will be available at the following URL::

$ http://localhost:8082


Nginx-Alpine
------------

To build the image (inside the folder with the Dockerfile)::
This is the complete stack intented for production, to have a stack we require to use ``docker-compose``
to build two images: ``pywps/gunicorn-alpine:latest`` and ``pywps/nginx-alpine:latest``

$ docker build -t pywps4-demo .
Those images will be pulled from dockerhub, but they can compiled locally by building Flask-Alpine, Gunicron-Alpine and Nginx-Alpine, in this case only showing for nginx::


Gunicorn uses a set of workers to run pywps (normally ``workers = (2 * cpu) + 1``), the default value used was 5 but it can be overwritten by setting the env flag GU_WORKERS::
$ cd docker/alpine/nginx/Dockerfile
$ docker build -t pywps/nginx-alpine:latest .

Then the stack can be started using docker compose::

$ docker run -e GU_WORKERS=10 -p 80:80 -it pywps4-demo:nginx
$ docker-compose up


In this case pywps (only the WPS) will be avalable on::
Expand All @@ -103,11 +137,77 @@ In this case pywps (only the WPS) will be avalable on::
http://localhost


Flask-Ubuntu (basic)
--------------------

The same as ``Flask-Ubuntu`` but using phusion image (ubuntu 18.04)::


$ cd docker/ubuntu/flask
$ docker build -t pywps/flask-ubuntu:latest .

And to run it::
$ docker run -p 5000:5000 pywps/flask-ubuntu


Nginx-Ubuntu (production)
-------------------------

This image is based on ``Flask-Ubuntu`` and will require it (either build locally or pull from dockerhub). This image has Nginx and Gunicorn totally integrated as services in a docker image::


$ cd docker/ubuntu/nginx
$ docker build -t pywps/nginx-ubuntu .

And to run it::

$ docker run -p 80:80 pywps/nginx-ubuntu

It is possible to set the number of Gunicorn workers:

* GU_WORKERS - Numer or workers. (default: 5)

e.g::

$ docker run -e GU_WORKERS=10 -p 80:80 pywps/nginx-ubuntu



Volumes
-------


Named volumes allow for container content to be available in the host system. The most important folders in pywps containers are:

* /pywps-flask/logs
* /pywps-flask/outputs
* /pywps-flask/processes

And file:
* /pywps-flask/pywps.cfg

Named volumes need to be created prior to ``docker run``::

$ docker volume create pywps_logs
$ docker volume create pywps_outputs
$ docker volume create pywps_processes
To check the path on the host to volume and other information::


$ docker volume ls pywps_processes


To run a docker will all the volumes available in the host::

$ docker run -p 5000:5000 -v pywps_logs:/pywps-flask/pywps_logs \
-v pywps_outputs:/pywps-flask/pywps_outputs \
-v pywps_processes:/pywps-flask/pywps_processes \
-v pywps_cfg:/pywps-flask/pywps.cfg pywps/flask-alpine:latest


THE END
=======


2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0.0
4.2.1
31 changes: 16 additions & 15 deletions docker/alpine/flask/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
FROM alpine:3.6
MAINTAINER Jorge S. Mendes de Jesus <jorge.dejesus@geocat.net>
FROM alpine:3.8
MAINTAINER Jorge S. Mendes de Jesus <jorge.dejesus@protonmail.com>

ARG GDAL_VERSION=2.3.2
ARG GDAL_VERSION=2.4.0
ARG XERCES_VERSION=3.2.2
ARG PROCESSOR_N=4
ARG FLASK_GIT=https://github.com/jorgejesus/pywps-flask.git
ARG FLASK_BRANCH=pywps_4.2

RUN apk update && apk add --no-cache \
git \
Expand All @@ -27,35 +29,34 @@ RUN apk add --no-cache \
--repository http://dl-cdn.alpinelinux.org/alpine/edge/testing \
geos \
geos-dev


#Compiling Xerces
RUN wget http://www.apache.org/dist/xerces/c/3/sources/xerces-c-${XERCES_VERSION}.tar.gz -O /tmp/xerces-c-${XERCES_VERSION}.tar.gz && \
tar xvf /tmp/xerces-c-${XERCES_VERSION}.tar.gz -C /tmp && \
cd /tmp/xerces-c-${XERCES_VERSION} && \
RUN wget http://www.apache.org/dist/xerces/c/3/sources/xerces-c-$XERCES_VERSION.tar.gz -O /tmp/xerces-c-$XERCES_VERSION.tar.gz && \
tar xvf /tmp/xerces-c-$XERCES_VERSION.tar.gz -C /tmp && \
cd /tmp/xerces-c-$XERCES_VERSION && \
LDFLAGS="-s" ./configure --prefix=/usr/local/src/xerces && \
make -j $PROCESSOR_N install

# Install GDAL
RUN wget http://download.osgeo.org/gdal/${GDAL_VERSION}/gdal-${GDAL_VERSION}.tar.gz -O /tmp/gdal.tar.gz && \
RUN wget http://download.osgeo.org/gdal/$GDAL_VERSION/gdal-$GDAL_VERSION.tar.gz -O /tmp/gdal.tar.gz && \
tar xzf /tmp/gdal.tar.gz -C /tmp && \
cd /tmp/gdal-${GDAL_VERSION} && \
cd /tmp/gdal-$GDAL_VERSION && \
LDFLAGS="-s" ./configure --with-expat=yes --with-xerces=/opt/xerces --with-geos=yes \
&& make -j ${PROCESSOR_N} && make install
&& make -j $PROCESSOR_N && make install

RUN cd /tmp/gdal-${GDAL_VERSION}/swig/python \
RUN cd /tmp/gdal-$GDAL_VERSION/swig/python \
&& python3 setup.py install

RUN rm -rf /var/cache/apk/*

RUN git clone https://github.com/geopython/pywps-flask.git

RUN git clone $FLASK_GIT -b $FLASK_BRANCH --single-branch
WORKDIR /pywps-flask
RUN pip3 install -r requirements.txt


ENTRYPOINT ["/usr/bin/python3", "demo.py","-a"]

#docker build -t pywps-flask .
#docker run -p 5000:5000 pywps-flask
#docker build -t pywps/flask-alpine .
#docker run -p 5000:5000 pywps/flask-alpine:latest
#http://localhost:5000/wps?request=GetCapabilities&service=WPS
#http://localhost:5000/wps?request=DescribeProcess&service=WPS&identifier=all&version=1.0.0
10 changes: 5 additions & 5 deletions docker/alpine/gunicorn/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM pywps/flask-alpine:3.6
MAINTAINER Jorge Samuel Mendes de Jesus <jorge.dejesus@geocat.net>
FROM pywps/flask-alpine:latest
MAINTAINER Jorge Samuel Mendes de Jesus <jorge.dejesus@protonmail.com>

#For Gunicorn
ARG GU_WORKERS=5
Expand All @@ -17,7 +17,7 @@ RUN ln -s /pywps-flask/wsgi/pywps.wsgi /pywps-flask/wsgi/pywps_app.py

ENTRYPOINT ["/run_all.sh"]

#Build: docker build -t pywps4:gunicorn .
#Usage: docker run -p 8081:8081 -it pywps4:nginx
#Usage w/ 10 workers: docker run -e GU_WORKERS=10 -e GU_PORT=8082 -p 8082:8082 -it pywps4:gunicorn
#Build: docker build -t pywps/gunicorn-alpine:latest .
#Usage: docker run -p 8081:8081 -it pywps/gunicorn-alpine:latest
#Usage w/ 10 workers: docker run -e GU_WORKERS=10 -e GU_PORT=8082 -p 8082:8082 -it pywps/gunicorn-alpine:latest

7 changes: 4 additions & 3 deletions docker/alpine/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
FROM nginx:1.13.7-alpine
FROM nginx:1.15.7-alpine
MAINTAINER Jorge Samuel Mendes de Jesus <[email protected]>

RUN rm /etc/nginx/conf.d/default.conf
COPY pywps.conf /etc/nginx/conf.d/pywps.conf


#Build: docker build -t pywps4:nginx .
#Usage: docker run -p 80:80 -it pywps4:nginx
#Build: docker build -t pywps/nginx-alpine:latest .
#Usage: docker-compose up
#Usage: docker run -p 80:80 -it pywps/nginx-alpine:latest
4 changes: 2 additions & 2 deletions docker/alpine/nginx/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ version: '3.1'

services:
pywps:
image: pywps/gunicorn-alpine:3.6
image: pywps/gunicorn-alpine:latest
nginx:
image: pywps/nginx-alpine:3.6
image: pywps/nginx-alpine:latest
build: .
depends_on:
- pywps
Expand Down
Loading

0 comments on commit 6952875

Please sign in to comment.