-
-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds a Dockerfile to pycsw repo #534
Adds a Dockerfile to pycsw repo #534
Conversation
Codecov Report
@@ Coverage Diff @@
## master #534 +/- ##
=======================================
Coverage 55.93% 55.93%
=======================================
Files 29 29
Lines 6338 6338
Branches 1342 1342
=======================================
Hits 3545 3545
- Misses 2412 2413 +1
+ Partials 381 380 -1
Continue to review full report at Codecov.
|
For now this image can be tested by running: cd pycsw
PYCSW_VERSION=$(cat VERSION.txt)
# build the image (later on it will be available on docker hub)
docker build -t geopython/pycsw:$PYCSW_VERSION .
# launch a container that uses the default config
docker run --rm -ti -p 8000:8000 geopython/pycsw:$PYCSW_VERSION
# pycsw is now running on port 8000, stop the docker container by pressing ctrl+c A more involved setup, where we create a custom configuration file and also set up a docker volume to hold the database: # copy and tweak the config file,
# specifying repository.url as sqlite:////home/pycsw/data/pycsw-db.sqlite
cp default-sample.cfg ~/my-custom-config.cfg
#create a docker volume in order to persist the data even when the container is destroyed
docker volume create my-pycsw-data
# run a container with our custom settings and data volume
docker run \
--name pycsw-test \
--detach \
--publish 8000:8000 \
--volume $HOME/my-custom-config.cfg:/etc/pycsw/pycsw.cfg
--volume my-pycsw-data:/home/pycsw/data
geopython/pycsw:$PYCSW_VERSION
# use pycsw-admin to initialize the data repository
docker exec -ti pycsw-test pycsw-admin.py -f /etc/pycsw/pycsw.cfg -c setup_db
# inspect logs
docker logs -f pycsw-test
# pycsw is running on port 8000 of the host, stop it by running
# docker rm -f pycsw-test Things to notice:
|
Running the tests on a container can be done by:
$ docker run \
--rm
-ti
--user root
--entrypoint sh
geopython/pycsw:$PYCSW_VERSION
pip3 install -r requirements-dev.txt
su pycsw
py.test -m unit
py.test -m functional -k 'not harvesting' |
This PR is nearing completion. I'm still working on ensuring that the image works OK with postgis containers, but other than that it seems to be going good. I plan to ask for review soon |
I think this PR is ready. Could you please review? Notable stuff:
Missing stuff for closing #530:
|
@ricardogsilva thanks for the info. I've created (an empty) Docker project at https://hub.docker.com/r/geopython/pycsw/ and assigned a pycsw team (currently yourself, @kalxas and myself) with write access. Let me know if this works for you. We need to update the project short and full description on the Docker page (or does this get picked up from somewhere in the Dockerfile or pycsw GitHub repo?). |
@tomkralidis Thanks for that :) I think I'll wait for @kalxas review before proceeding with the setup of the dockerhub repo. |
bin/entrypoint.py
Outdated
"--error-logfile=-", | ||
"--workers={}".format(gunicorn_workers) | ||
] | ||
pycsw_server_command.append("--workers={}".format(gunicorn_workers)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is not needed, I forgot to delete it. I'll do it shortly
bin/entrypoint.py
Outdated
|
||
|
||
def _create_pycsw_schema(database_url, table): | ||
admin.setup_db(database=database_url, table=table, home="/home/pycsw") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the end this function became shorter than intended. I guess I'll remove it and just use the single line above
docker/docker-stack.yml
Outdated
- db-data:/var/lib/postgresql/data/pgdata | ||
|
||
pycsw: | ||
image: ricardogsilva/pycsw:${PYCSW_DOCKER_VERSION} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The image identifier is wrong, I should be using geopython/pycsw
instead of ricardogsilva/pycsw
. I'll update this too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like I still have some final touch ups to do.
bin/entrypoint.py
Outdated
logger.debug("Reading pycsw config...") | ||
config = SafeConfigParser() | ||
config.read("/etc/pycsw/pycsw.cfg") | ||
db_url = config.get("repository", "database") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should retrieve config from the environment instead of assuming it is still the default value
bin/entrypoint.py
Outdated
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--verbose", action="store_true") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull log level from the pycsw config instead of making it a call flag
Hi @ricardogsilva |
I changed the status of this PR back to WIP because I am having trouble mounting volumes for being able to persist |
Thanks @ricardogsilva |
There was a problem with using the python:3.5-alpine image together with geos and shapely. The `shapely.wkt.loads` function could crash with a segmentation fault if it received an invalid input (we have a unit test that checks this)
- Docker image does not keep pycsw source code in a local dir anymore - entrypoint script is starting to work with postgresql as well - added docker-stack file in order to use docker-compose and docker swarms
- entrypoint script now makes use of the PYCSW_CONFIG environment variable - log level for the entrypoint script is taken from pycsw config
Now providing a custom pycsw.cfg inside the docker directory
4088e74
to
782d4eb
Compare
Allright I think this is ready. Custom sqlite databases can be mounted on # build the docker image
docker build -t geopython/pycsw:$(cat VERSION.txt) .
# create a docker volume
docker volume create pycsw-database
# run a container, mounting a custom pycsw config and the previously created volume too
docker run \
-v <local-path-to-custom-pycsw.cfg>:/etc/pycsw/pycsw.cfg \
-v pycsw-database:/var/lib/pycsw \
-p 8000:8000 \
geopython/pycsw:$(cat VERSION.txt) In the following example, a new volume is created by docker to store the contents of the pycsw sqlite database. This volume is persisted after the container is destroyed. @kalxas can you pease review, at your convenience? |
Overview
This PR adds a
Dockerfile
to pycsw.This work may be continued afterwards in order to enable automated builds on docker hub.
Related Issue / Discussion
Contributions and Licensing
(as per https://github.com/geopython/pycsw/blob/master/CONTRIBUTING.rst#contributions-and-licensing)