okfn/docker-ckan

Name: docker-ckan

Owner: Open Knowledge International

Description: Docker Compose setup for CKAN

Created: 2018-01-18 10:02:21.0

Updated: 2018-05-22 10:38:20.0

Pushed: 2018-04-06 06:51:59.0

Homepage:

Size: 34

Language: Python

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Docker Compose setup for CKAN

Note: :warning: This is a work in progress. There is likely to be issues so use with caution :warning:

This is a set of Docker images and configuration files to run a CKAN site

It is largely based on two existing projects:

It includes the following images, all based on Alpine Linux:

The site is configured via env vars (the base CKAN image loads ckanext-envvars), that you can set in the .env file.

Copy the included .env.example and rename it to .env to modify it depending on your own needs.

Using the default values on the .env.example file will get you a working CKAN instance. There is a sysadmin user created by default with the values defined in CKAN_SYSADMIN_NAME and CKAN_SYSADMIN_PASSWORD(ckan_admin and test by default). I shouldn't be telling you this but obviously don't run any public CKAN instance with the default settings.

To build the images:

docker-compose build

To start the containers:

docker-compose up
Development mode

To develop local extensions use the docker-compose.dev.yml file:

To build the images:

docker-compose -f docker-compose.dev.yml build

To start the containers:

docker-compose -f docker-compose.dev.yml up

See CKAN Images for more details of what happens when using development mode.

Running the debugger (pdb / ipdb)

To run a container and be able to add a breakpoint with pdb or ipdb, run the ckan-dev container with the --service-ports option:

docker-compose -f docker-compose.dev.yml run --service-ports ckan-dev

This will start a new container, displaying the standard output in your terminal. If you add a breakpoint in a source file in the src folder (import pdb; pdb.set_trace()) you will be able to inspect it in this terminal next time the code is executed.

CKAN images
+-------------------------+                +----------+
|                         |                |          |
| openknowledge/ckan-base +---------------->   ckan   | (production)
|                         |                |          |
+-----------+-------------+                +----------+
            |
            |
+-----------v------------+                 +----------+
|                        |                 |          |
| openknowledge/ckan-dev +----------------->   ckan   | (development)
|                        |                 |          |
+------------------------+                 +----------+

The Docker images used to build your CKAN project are located in the ckan/ folder. There are two Docker files:

From these two base images you can build your own customized image tailored to your project, installing any extensions and extra requirements needed.

Extending the base images

To perform extra initialization steps you can add scripts to your custom images and copy them to the /docker-entrypoint.d folder (The folder should be created for you when you build the image). Any *.sh and *.py file in that folder will be executed just after the main initialization script (prerun.py) is executed and just before the web server and supervisor processes are started.

For instance, consider the following custom image:


docker-entrypoint.d
??? setup_validation.sh
Dockerfile
Dockerfile.dev

We want to install an extension like ckanext-validation that needs to create database tables on startup time. We create a setup_validation.sh script in a docker-entrypoint.d folder with the necessary commands:

in/bash

eate DB tables if not there
er --plugin=ckanext-validation validation init-db -c $CKAN_INI

And then in our Dockerfile we install the extension and copy the initialization scripts:

 openknowledge/ckan-dev:2.7

pip install -e git+https://github.com/frictionlessdata/ckanext-validation.git#egg=ckanext-validation && \
pip install -r https://raw.githubusercontent.com/frictionlessdata/ckanext-validation/master/requirements.txt

 docker-entrypoint.d/* /docker-entrypoint.d/

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.