Skip to content
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

Creating a postgis/ckanext-spatial environment #98

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ CKAN_SMTP_MAIL_FROM=ckan@localhost

# Extensions

CKAN__PLUGINS="envvars image_view text_view recline_view datastore datapusher"
CKAN__PLUGINS="envvars image_view text_view recline_view datastore datapusher harvest ckan_harvester spatial_metadata spatial_query"
CKANEXT__SPATIAL__SEARCH_BACKEND=solr-spatial-field

CKAN__HARVEST__MQ__TYPE=redis
CKAN__HARVEST__MQ__HOSTNAME=redis
CKAN__HARVEST__MQ__PORT=6379
CKAN__HARVEST__MQ__REDIS_DB=1

13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ To start the containers:

See [CKAN Images](#ckan-images) for more details of what happens when using development mode.

## Postgis Development mode

To develop with a `postgis` + `ckanext-spaqtial` local environment
using the `solr-spatial-field` search backend use
the `docker-compose-postgis-dev.yml` file:

To build the images:

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

To start the containers:

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

### Create an extension

Expand Down
35 changes: 35 additions & 0 deletions ckan/Dockerfile-postgis.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
FROM openknowledge/ckan-dev:2.9

MAINTAINER Your Name Here <[email protected]>

# Set timezone
ARG TZ
RUN cp /usr/share/zoneinfo/$TZ /etc/localtime
RUN echo $TZ > /etc/timezone
ENV PROJ_DIR=/usr
RUN apk add --no-cache libffi-dev gcc libc-dev geos-dev geos proj-util proj-dev

# Install any extensions needed by your CKAN instance
# (Make sure to add the plugins to CKAN__PLUGINS in the .env file)
# For instance:
RUN pip install --upgrade pip && \
pip install -e git+https://github.com/ckan/ckanext-harvest.git#egg=ckanext-harvest && \
pip install -r https://raw.githubusercontent.com/ckan/ckanext-harvest/master/requirements.txt && \
pip install -e git+https://github.com/ckan/ckanext-spatial.git#egg=ckanext-spatial && \
pip install -r https://raw.githubusercontent.com/ckan/ckanext-spatial/master/requirements.txt

# Clone the extension(s) your are writing for your own project in the `src` folder
# to get them mounted in this image at runtime

# Apply any patches needed to CKAN core or any of the built extensions (not the
# runtime mounted ones)
# See https://github.com/okfn/docker-ckan#applying-patches
COPY patches ${APP_DIR}/patches

RUN for d in $APP_DIR/patches/*; do \
if [ -d $d ]; then \
for f in `ls $d/*.patch | sort -g`; do \
cd $SRC_DIR/`basename "$d"` && echo "$0: Applying patch $f to $SRC_DIR/`basename $d`"; patch -p1 < "$f" ; \
done ; \
fi ; \
done
58 changes: 58 additions & 0 deletions docker-compose-postgis-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
version: "3"

services:
ckan-dev:
container_name: ckan
build:
context: ckan/
dockerfile: Dockerfile-postgis.dev
args:
- TZ=${TZ}
env_file:
- .env
links:
- db
- solr
- redis
- datapusher
ports:
- "0.0.0.0:${CKAN_PORT}:5000"
volumes:
- ./src:/srv/app/src_extensions
- ckan_storage:/var/lib/ckan


datapusher:
container_name: datapusher
build:
context: datapusher/
ports:
- "8800:8800"

db:
container_name: db
env_file:
- .env
build:
context: postgis/
environment:
- PGDATA=/var/lib/postgresql/data/db
volumes:
- pg_data:/var/lib/postgresql/data

solr:
container_name: solr
image: ckan/ckan-solr:2.9-solr8
ports:
- "8983:8983"
volumes:
- solr_data:/opt/solr/server/solr/ckan/data/index

redis:
container_name: redis
image: redis:alpine

volumes:
ckan_storage:
pg_data:
solr_data:
14 changes: 14 additions & 0 deletions postgis/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM postgis/postgis:latest
MAINTAINER Open Knowledge Foundation

# Allow connections; we don't map out any ports so only linked docker containers can connect
RUN echo "host all all 0.0.0.0/0 md5" >> /var/lib/postgresql/data/pg_hba.conf

# Customize default user/pass/db
ENV POSTGRES_DB ckan
ENV POSTGRES_USER ckan
ARG POSTGRES_PASSWORD
ARG DATASTORE_READONLY_PASSWORD

# Include extra setup scripts (eg datastore)
ADD docker-entrypoint-initdb.d /docker-entrypoint-initdb.d
4 changes: 4 additions & 0 deletions postgis/docker-entrypoint-initdb.d/10_create_datastore.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
\set datastore_ro_password '\'' `echo $DATASTORE_READONLY_PASSWORD` '\''

CREATE ROLE datastore_ro NOSUPERUSER NOCREATEDB NOCREATEROLE LOGIN PASSWORD :datastore_ro_password;
CREATE DATABASE datastore OWNER ckan ENCODING 'utf-8';
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE DATABASE ckan_test OWNER ckan ENCODING 'utf-8';
CREATE DATABASE datastore_test OWNER ckan ENCODING 'utf-8';
2 changes: 2 additions & 0 deletions postgis/docker-entrypoint-initdb.d/30_pg.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE geometry_columns OWNER TO ckan;
ALTER TABLE spatial_ref_sys OWNER TO ckan;