docker-ckan/Readme.md

114 lines
5.3 KiB
Markdown
Raw Normal View History

2020-09-23 10:00:07 +02:00
# Dockerized CKAN
[![build-status](https://github.com/keitaroinc/docker-ckan/workflows/Docker%20Image%20Build/badge.svg?branch=master)](https://github.com/keitaroinc/docker-ckan/actions) [![License][]][1] [![Docker Pulls][]][2] [![Chat on Gitter][]][3]
2020-09-23 10:00:07 +02:00
This repository contains base docker images, examples and docker-compose used to build and run CKAN.
2019-03-08 14:27:11 +01:00
We build and publish docker images built using this repository to Dockerhub:
- [CKAN docker images](https://hub.docker.com/r/keitaro/ckan).
- [Datapusher docker images](https://hub.docker.com/r/keitaro/ckan-datapusher)
2019-03-08 14:27:11 +01:00
and Github Container Registry:
- [CKAN docker images on GHCR](https://github.com/orgs/keitaroinc/packages/container/package/ckan)
- [Datapusher docker images on GHCR](https://github.com/orgs/keitaroinc/packages/container/package/datapusher)
Looking to run CKAN on Kubernetes? Check out our [CKAN Helm Chart](https://github.com/keitaroinc/ckan-helm)!
2019-03-08 14:27:11 +01:00
## Overview
2021-01-16 02:42:37 +01:00
Images are provided in two flavors:
- [Alpine Linux](https://alpinelinux.org/) based images
- [Ubuntu Focal](https://ubuntu.com/) based images are the ones ending with `-focal` in the tag name
The Docker containers include only the required extensions to start a CKAN instance. The docker images are built using a multi-stage docker approach in order to produce slim production grade docker images with the right libraries and configuration. This multi-stage approach allows us to build python binary wheels in the build stages that later on we install in the main stage.
2019-03-08 14:27:11 +01:00
Directory layout:
- [compose](./compose) - contains a docker-compose setup allowing users to spin up a CKAN setup easily using [docker-compose](https://docs.docker.com/compose/)
- [images](./images) - includes docker contexts for building all supported CKAN versions and datapusher
- [examples](./examples) - includes examples on how to extend the CKAN docker images and how to run them
2019-03-08 14:27:11 +01:00
## Running CKAN using docker-compose
To start CKAN using docker-compose, simply change into the *compose* directory and run
2019-03-08 14:27:11 +01:00
```sh
cd compose
docker-compose build
docker-compose up
2019-03-08 14:27:11 +01:00
```
Check if CKAN was succesfuly started on http://localhost:5000.
2019-03-08 14:27:11 +01:00
### Configuration
In order to configure CKAN within docker-compose we use both build/up time variables loaded via the [.env](./compose/.env) file, and runtime variables loaded via the [.ckan-env](./compose/.ckan-env) file.
2019-03-08 14:27:11 +01:00
Variables in the [.env](./compose/.env) file are loaded when running `docker-compose build` and `docker-compose up`, while variables in [.ckan-env](./compose/.ckan-env) file are used withing the CKAN container at runtime to configure CKAN and CKAN extensions using [ckanext-envvars](https://github.com/okfn/ckanext-envvars).
2019-03-08 14:27:11 +01:00
## Extending CKAN docker images
Check some examples of extending CKAN docker images in the [examples](./examples) directory.
2019-03-08 14:27:11 +01:00
We recommend to use a multi-stage approach to extend the docker images that we provide here. To extend the images the following Dockerfile structure is recommended:
```docker
###################
### Extensions ####
###################
FROM ghcr.io/keitaroinc/ckan:2.9.2 as extbuild
2019-03-08 14:27:11 +01:00
# Switch to the root user
USER root
2019-03-08 14:27:11 +01:00
# Install any system packages necessary to build extensions
RUN apk add --no-cache python3-dev
2019-03-08 14:27:11 +01:00
# Fetch and build the custom CKAN extensions
RUN pip wheel --wheel-dir=/wheels git+https://github.com/acmecorp/ckanext-acme@0.0.1#egg=ckanext-acme
2019-03-08 14:27:11 +01:00
############
### MAIN ###
############
FROM ghcr.io/keitaroinc/ckan:2.9.2
2019-03-08 14:27:11 +01:00
# Add the custom extensions to the plugins list
ENV CKAN__PLUGINS envvars image_view text_view recline_view datastore datapusher acme
2019-03-08 14:27:11 +01:00
# Switch to the root user
USER root
2019-03-08 14:27:11 +01:00
COPY --from=extbuild /wheels /srv/app/ext_wheels
2019-03-08 14:27:11 +01:00
# Install and enable the custom extensions
RUN pip install --no-index --find-links=/srv/app/ext_wheels ckanext-acme && \
2021-03-12 17:36:12 +01:00
ckan config-tool ${APP_DIR}/production.ini "ckan.plugins = ${CKAN__PLUGINS}" && \
chown -R ckan:ckan /srv/app
2019-03-08 14:27:11 +01:00
# Remove wheels
RUN rm -rf /srv/app/ext_wheels
2019-03-08 14:27:11 +01:00
# Switch to the ckan user
USER ckan
```
2019-03-08 14:27:11 +01:00
2020-09-21 08:51:52 +02:00
### Adding init and afterinit scripts
You can add scripts to CKAN custom images and copy them to the *docker-entrypoint.d* directory. Any *.sh or *.py file in that directory will be executed before the main initialization script (prerun.py) is executed.
You can add scripts to CKAN custom images and copy them to the *docker-afterinit.d* directory. Any *.sh or *.py file in that directory will be executed after the main initialization script (prerun.py) is executed.
## Build
To build a CKAN image run:
```sh
docker build --tag ghcr.io/keitaroinc/ckan:2.9.2 images/ckan/2.9
```
The -tag ghcr.io/keitaroinc/ckan:2.9.2 flag sets the image name to ghcr.io/keitaroinc/ckan:2.9.2 and 'images/ckan/2.9' at the end tells docker build to use the context into the specified directory where the Dockerfile and related contents are.
## Upload to DockerHub
>*It's recommended to upload built images to DockerHub*
To upload the image to DockerHub run:
```sh
docker push [options] <docker-hub-namespace>/ckan:<image-tag>
```
2020-09-23 10:00:07 +02:00
[License]: https://img.shields.io/badge/license-Apache--2.0-blue.svg?style=flat
[1]: https://opensource.org/licenses/Apache-2.0
[Docker Pulls]: https://img.shields.io/docker/pulls/keitaro/ckan.svg?style=flat
[2]: https://hub.docker.com/r/keitaro/ckan
[Chat on Gitter]: https://badges.gitter.im/gitterHQ/gitter.svg
[3]: https://gitter.im/keitaroinc/docker-ckan