|
| 1 | +Docker |
| 2 | +====== |
| 3 | + |
| 4 | +pycsw is available as a Docker image. The image is hosted on the `dockerhub`_. |
| 5 | + |
| 6 | +Assuming you already have docker installed, you can get a pycsw instance up |
| 7 | +and running by issuing the following command:: |
| 8 | + |
| 9 | + docker run -p 8000:8000 geopython/pycsw |
| 10 | + |
| 11 | +Docker will retrieve the pycsw image from dockerhub (if needed) and then |
| 12 | +start a new container listening on port 8000. |
| 13 | + |
| 14 | +The default configuration will run pycsw with an sqlite repository backend |
| 15 | +loaded with some test data from the CITE test suite. You can use this to take |
| 16 | +pycsw for a test drive. |
| 17 | + |
| 18 | + |
| 19 | +Inspect logs |
| 20 | +------------ |
| 21 | + |
| 22 | +The default configuration for the docker image outputs logs to stdout. This is |
| 23 | +common practice with docker containers and enables the inspection of logs |
| 24 | +with the ``docker logs`` command:: |
| 25 | + |
| 26 | + # run a pycsw container in the background |
| 27 | + docker run \ |
| 28 | + --name pycsw-test \ |
| 29 | + --publish 8000:8000 \ |
| 30 | + --detach \ |
| 31 | + geopython/pycsw |
| 32 | + |
| 33 | + # inspect logs |
| 34 | + docker logs pycsw-test |
| 35 | + |
| 36 | +.. note:: |
| 37 | + |
| 38 | + In order to have pycsw logs being sent to standard output you must set |
| 39 | + ``server.logfile=`` in the pycsw configuration file. |
| 40 | + |
| 41 | + |
| 42 | +Using pycsw-admin |
| 43 | +----------------- |
| 44 | + |
| 45 | +``pycsw-admin`` can be executed on a running container by |
| 46 | +using ``docker exec``:: |
| 47 | + |
| 48 | + docker exec -ti <running-container-id> pycsw-admin.py -h |
| 49 | + |
| 50 | + |
| 51 | +Running custom pycsw containers |
| 52 | +------------------------------- |
| 53 | + |
| 54 | +pycsw configuration |
| 55 | +^^^^^^^^^^^^^^^^^^^ |
| 56 | + |
| 57 | +It is possible to supply a custom configuration file for pycsw as a bind |
| 58 | +mount or as a docker secret (in the case of docker swarm). The configuration |
| 59 | +file is searched at the value of the ``PYCSW_CONFIG`` environmental variable, |
| 60 | +which defaults to ``/etc/pycsw/pycsw.cfg``. |
| 61 | + |
| 62 | +Supplying the configuration file via bind mount:: |
| 63 | + |
| 64 | + docker run \ |
| 65 | + --name pycsw \ |
| 66 | + --detach \ |
| 67 | + --volume <path-to-local-pycsw.cfg>:/etc/pycsw/pycsw.cfg \ |
| 68 | + --publish 8000:8000 \ |
| 69 | + geopython/pycsw |
| 70 | + |
| 71 | +Supplying the configuration file via docker secrets:: |
| 72 | + |
| 73 | + # first create a docker secret with the pycsw config file |
| 74 | + docker secret create pycsw-config <path-to-local-pycsw.cfg> |
| 75 | + docker service create \ |
| 76 | + --name pycsw \ |
| 77 | + --secret src=pycsw-config,target=/etc/pycsw/pycsw.cfg \ |
| 78 | + --publish 8000:8000 |
| 79 | + geopython/pycsw |
| 80 | + |
| 81 | + |
| 82 | +sqlite repositories |
| 83 | +^^^^^^^^^^^^^^^^^^^ |
| 84 | + |
| 85 | +The default database repository is the CITE database that is used for running |
| 86 | +pycsw's test suites. Docker volumes may be used to specify a custom sqlite |
| 87 | +database path. It should be mounted under ``/var/lib/pycsw``:: |
| 88 | + |
| 89 | + # first create a docker volume for persisting the database when |
| 90 | + # destroying containers |
| 91 | + docker volume create pycsw-db-data |
| 92 | + docker run \ |
| 93 | + --volume db-data:/var/lib/pycsw \ |
| 94 | + --detach \ |
| 95 | + --publish 8000:8000 |
| 96 | + geopython/pycsw |
| 97 | + |
| 98 | + |
| 99 | +PostgreSQL repositories |
| 100 | +^^^^^^^^^^^^^^^^^^^^^^^ |
| 101 | + |
| 102 | +Specifying a PostgreSQL repository is just a matter of configuring a custom |
| 103 | +pycsw.cfg file with the correct specification. |
| 104 | + |
| 105 | +Check `pycsw's github repository`_ for an example of a docker-compose/stack |
| 106 | +file that spins up a postgis database together with a pycsw instance. |
| 107 | + |
| 108 | + |
| 109 | +Setting up a development environment with docker |
| 110 | +------------------------------------------------ |
| 111 | + |
| 112 | +Working on pycsw's code using docker enables an isolated environment that |
| 113 | +helps ensuring reproducibility while at the same time keeping your base |
| 114 | +system free from pycsw related dependencies. This can be achieved by: |
| 115 | + |
| 116 | +* Cloning pycsw's repository locally; |
| 117 | +* Starting up a docker container with appropriately set up bind mounts. In |
| 118 | + addition, the pycsw docker image supports a ``reload`` flag that turns on |
| 119 | + automatic reloading of the gunicorn web server whenever the code changes; |
| 120 | +* Installing the development dependencies by using ``docker exec`` with the |
| 121 | + root user; |
| 122 | + |
| 123 | +The following instructions set up a fully working development environment:: |
| 124 | + |
| 125 | + # clone pycsw's repo |
| 126 | + git clone https://github.com/geopython/pycsw.git |
| 127 | + |
| 128 | + # start a container for development |
| 129 | + cd pycsw |
| 130 | + docker run \ |
| 131 | + --name pycsw-dev \ |
| 132 | + --detach \ |
| 133 | + --volume ${PWD}/pycsw:/usr/lib/python3.5/site-packages/pycsw \ |
| 134 | + --volume ${PWD}/docs:/home/pycsw/docs \ |
| 135 | + --volume ${PWD}/VERSION.txt:/home/pycsw/VERSION.txt \ |
| 136 | + --volume ${PWD}/LICENSE.txt:/home/pycsw/LICENSE.txt \ |
| 137 | + --volume ${PWD}/COMMITTERS.txt:/home/pycsw/COMMITTERS.txt \ |
| 138 | + --volume ${PWD}/CONTRIBUTING.rst:/home/pycsw/CONTRIBUTING.rst \ |
| 139 | + --volume ${PWD}/pycsw/plugins:/home/pycsw/pycsw/plugins \ |
| 140 | + --publish 8000:8000 \ |
| 141 | + geopython/pycsw --reload |
| 142 | + |
| 143 | + # install additional dependencies used in tests and docs |
| 144 | + docker exec \ |
| 145 | + -ti \ |
| 146 | + --user root \ |
| 147 | + pycsw-dev pip3 install -r requirements-dev.txt |
| 148 | + |
| 149 | + # run tests (for example unit tests) |
| 150 | + docker exec -ti pycsw-dev py.test -m unit |
| 151 | + |
| 152 | + # build docs |
| 153 | + docker exec -ti pycsw-dev sh -c "cd docs && make html" |
| 154 | + |
| 155 | +.. note:: |
| 156 | + |
| 157 | + Please note that the pycsw image only uses python 3.5 and that it also does |
| 158 | + not install pycsw in editable mode. As such it is not possible to |
| 159 | + use ``tox``. |
| 160 | + |
| 161 | +Since the docs directory is bind mounted from your host machine into the |
| 162 | +container, after building the docs you may inspect their content visually, for |
| 163 | +example by running:: |
| 164 | + |
| 165 | + firefox docs/_build/html/index.html |
| 166 | + |
| 167 | + |
| 168 | +.. _dockerhub: https://hub.docker.com/r/geopython/pycsw/ |
| 169 | +.. _pycsw's github repository: https://github.com/geopython/pycsw/tree/master/docker |
0 commit comments