Skip to content

Commit

Permalink
Merge pull request #1 from JiscSD/UKDSB-319-Create-ckan-docker-image
Browse files Browse the repository at this point in the history
Create UKDS CKAN Docker Image
  • Loading branch information
chris-daly authored Dec 11, 2024
2 parents fbda797 + 5e3e77e commit e549788
Show file tree
Hide file tree
Showing 20 changed files with 696 additions and 32 deletions.
13 changes: 13 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto

# Explicitly declare text files you want to always be normalized and converted
# to native line endings on checkout.
# *.txt text

# Declare files that will always have LF line endings on checkout.
*.sh text eol=lf

# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary
1 change: 1 addition & 0 deletions .github/workflows/build-and-test-2.10-py3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ jobs:
with:
ckan-major-version: "2.10"
docker-file: "Dockerfile.py3.10"
ckan-services-version: "2.10"
1 change: 1 addition & 0 deletions .github/workflows/build-and-test-2.10.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ jobs:
uses: ./.github/workflows/reusable-build-and-test.yml
with:
ckan-major-version: "2.10"
ckan-services-version: "2.10"
1 change: 1 addition & 0 deletions .github/workflows/build-and-test-2.11.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ jobs:
uses: ./.github/workflows/reusable-build-and-test.yml
with:
ckan-major-version: "2.11"
ckan-services-version: "2.11"
1 change: 1 addition & 0 deletions .github/workflows/build-and-test-2.9-py3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ jobs:
with:
ckan-major-version: "2.9"
docker-file: "Dockerfile.py3.9"
ckan-services-version: "2.9"
1 change: 1 addition & 0 deletions .github/workflows/build-and-test-2.9.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ jobs:
uses: ./.github/workflows/reusable-build-and-test.yml
with:
ckan-major-version: "2.9"
ckan-services-version: "2.9"
1 change: 1 addition & 0 deletions .github/workflows/build-and-test-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ jobs:
uses: ./.github/workflows/reusable-build-and-test.yml
with:
ckan-major-version: "master"
ckan-services-version: "master"
10 changes: 10 additions & 0 deletions .github/workflows/build-and-test-ukds.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Build and test CKAN UKDS images

on: push

jobs:
call-reusable-workflow:
uses: ./.github/workflows/reusable-build-and-test.yml
with:
ckan-major-version: "ukds-2.11"
ckan-services-version: "2.11"
8 changes: 6 additions & 2 deletions .github/workflows/reusable-build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@ on:
required: false
default: 'Dockerfile'
type: string
ckan-services-version:
required: true
default: 'latest'
type: string

jobs:
build_and_test:
runs-on: ubuntu-latest
services:
solr:
image: ckan/ckan-solr:${{ inputs.ckan-major-version }}-solr9
image: ckan/ckan-solr:${{ inputs.ckan-services-version }}-solr9
ports:
- 8983:8983
postgres:
image: ckan/ckan-postgres-dev:${{ inputs.ckan-major-version }}
image: ckan/ckan-postgres-dev:${{ inputs.ckan-services-version }}
ports:
- 5432:5432
env:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@

# other
.vscode
.venv
.idea
65 changes: 35 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
# Pre-configured CKAN Docker images

This is the repository of the official [Docker images](https://hub.docker.com/r/ckan/ckan-base/) for [CKAN](https://github.com/ckan/ckan/).
This is the repository of the official [Docker images](https://hub.docker.com/r/ckan/ckan-base/)
for [CKAN](https://github.com/ckan/ckan/).

Please raise issues or code contributions at [github:ckan/ckan-docker-base](https://github.com/ckan/ckan-docker-base)

The images will usually be used as a Docker Compose install in conjunction with other Docker images that make up the CKAN platform. The official CKAN Docker install is located here: [ckan-docker](https://github.com/ckan/ckan-docker)

The following CKAN versions are available in base or dev forms. They are distinguished from one another using different Docker image tags:

| CKAN Version | Type | Base image | Docker tag | Notes |
| --- | --- | --- | --- | --- |
| **2.11.x** | **base image** | `python:3.10-slim-bookworm` | `ckan/ckan-base:2.11`, `ckan/ckan-base:2.11.0`, `ckan/ckan-base:2.11-py3.10`, `ckan/ckan-base:2.11.0-py3.10` | |
| **2.11.x** | **dev image** | `python:3.10-slim-bookworm` | `ckan/ckan-dev:2.11`, `ckan/ckan-dev:2.11.0`, `ckan/ckan-dev:2.11-py3.10`, `ckan/ckan-dev:2.11.0-py3.10` | |
| 2.10.x | base image | `python:3.10-slim-bookworm` | `ckan/ckan-base:2.10-py3.10`, `ckan/ckan-base:2.10.5-py3.10` | |
| 2.10.x | dev image | `python:3.10-slim-bookworm` | `ckan/ckan-dev:2.10-py3.10`, `ckan/ckan-dev:2.10.5-py3.10` | |
| 2.10.x | base image | `alpine:3.17` | `ckan/ckan-base:2.10.5`, `ckan/ckan-base:2.10` | :warning: Deprecated. Please use a Python/Debian based image |
| 2.10.x | dev image | `alpine:3.17` | `ckan/ckan-dev:2.10.5`, `ckan/ckan-dev:2.10` | :warning: Deprecated. Please use a Python/Debian based image |
| 2.9.x | base image | `python:3.9-slim-bookworm` | `ckan/ckan-base:2.9-py3.9`, `ckan/ckan-base:2.9.11-py3.9` | |
| 2.9.x | dev image | `python:3.9-slim-bookworm` | `ckan/ckan-dev:2.9-py3.9`, `ckan/ckan-dev:2.9.11-py3.9` | |
| 2.9.x | base image | `alpine:3.15` | `ckan/ckan-base:2.9.11`, `ckan/ckan-base:2.9` | :warning: Deprecated. Please use a Python/Debian based image |
| 2.9.x | dev image | `alpine:3.15` | `ckan/ckan-dev:2.9.11`, `ckan/ckan-dev:2.9` | :warning: Deprecated. Please use a Python/Debian based image |
| master | base image | `python:3.10-slim-bookworm` | `ckan/ckan-base:master`, `ckan/ckan-base:master-py3.10` | Built daily, do not use in production |
| master | dev image | `python:3.10-slim-bookworm` | `ckan/ckan-dev:master`, `ckan/ckan-dev:master-py3.10` | Built daily, do not use in production |

In addition to the Docker tags listed above, there are additional ones published for each of these images [releases](https://github.com/ckan/ckan-docker-base/releases), in the form:

ckan/ckan-base:{major_version}-py{python_version}-{release_name}


Older CKAN versions might be available as [image tags](https://hub.docker.com/r/ckan/ckan-base/tags) but note that these are not supported as per [CKAN's release policy](https://docs.ckan.org/en/latest/maintaining/releases.html#supported-versions).

The images will usually be used as a Docker Compose install in conjunction with other Docker images that make up the
CKAN platform. The official CKAN Docker install is located here: [ckan-docker](https://github.com/ckan/ckan-docker)

The following CKAN versions are available in base or dev forms. They are distinguished from one another using different
Docker image tags:

| CKAN Version | Type | Base image | Docker tag | Notes |
|-----------------|----------------|-----------------------------|--------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------|
| **2.11.x** | **base image** | `python:3.10-slim-bookworm` | `ckan/ckan-base:2.11`, `ckan/ckan-base:2.11.0`, `ckan/ckan-base:2.11-py3.10`, `ckan/ckan-base:2.11.0-py3.10` | |
| **2.11.x** | **dev image** | `python:3.10-slim-bookworm` | `ckan/ckan-dev:2.11`, `ckan/ckan-dev:2.11.0`, `ckan/ckan-dev:2.11-py3.10`, `ckan/ckan-dev:2.11.0-py3.10` | |
| 2.10.x | base image | `python:3.10-slim-bookworm` | `ckan/ckan-base:2.10-py3.10`, `ckan/ckan-base:2.10.5-py3.10` | |
| 2.10.x | dev image | `python:3.10-slim-bookworm` | `ckan/ckan-dev:2.10-py3.10`, `ckan/ckan-dev:2.10.5-py3.10` | |
| 2.10.x | base image | `alpine:3.17` | `ckan/ckan-base:2.10.5`, `ckan/ckan-base:2.10` | :warning: Deprecated. Please use a Python/Debian based image |
| 2.10.x | dev image | `alpine:3.17` | `ckan/ckan-dev:2.10.5`, `ckan/ckan-dev:2.10` | :warning: Deprecated. Please use a Python/Debian based image |
| 2.9.x | base image | `python:3.9-slim-bookworm` | `ckan/ckan-base:2.9-py3.9`, `ckan/ckan-base:2.9.11-py3.9` | |
| 2.9.x | dev image | `python:3.9-slim-bookworm` | `ckan/ckan-dev:2.9-py3.9`, `ckan/ckan-dev:2.9.11-py3.9` | |
| 2.9.x | base image | `alpine:3.15` | `ckan/ckan-base:2.9.11`, `ckan/ckan-base:2.9` | :warning: Deprecated. Please use a Python/Debian based image |
| 2.9.x | dev image | `alpine:3.15` | `ckan/ckan-dev:2.9.11`, `ckan/ckan-dev:2.9` | :warning: Deprecated. Please use a Python/Debian based image |
| master | base image | `python:3.10-slim-bookworm` | `ckan/ckan-base:master`, `ckan/ckan-base:master-py3.10` | Built daily, do not use in production |
| master | dev image | `python:3.10-slim-bookworm` | `ckan/ckan-dev:master`, `ckan/ckan-dev:master-py3.10` | Built daily, do not use in production |
| **ukds-2.11.0** | **base image** | `python:3.12-slim-bookworm` | `ckan/ckan-base:ukds_2.11.0`, `ckan/ckan-base:ukds_2.11.0-py3.12` | |
| **ukds-2.11.0** | **dev image** | `python:3.12-slim-bookworm` | `ckan/ckan-dev:ukds_2.11.0`, `ckan/ckan-dev:ukds_2.11.0-py3.12` | |

In addition to the Docker tags listed above, there are additional ones published for each of these
images [releases](https://github.com/ckan/ckan-docker-base/releases), in the form:

ckan/ckan-base:{major_version}-py{python_version}-{release_name}

Older CKAN versions might be available as [image tags](https://hub.docker.com/r/ckan/ckan-base/tags) but note that these
are not supported as
per [CKAN's release policy](https://docs.ckan.org/en/latest/maintaining/releases.html#supported-versions).

### Repo structure

Expand Down Expand Up @@ -61,7 +67,6 @@ Once the maintainers decide it's time to do a new release, changes should be doc
part of the release notes. Publishing the new release will trigger the actions that push
the images to Docker Hub.


### Building the images locally

The images can be built locally for development and debugging purposes
Expand All @@ -85,11 +90,11 @@ Available actions:
For instance:

```
./build.sh build ukds base
./build.sh build 2.11
./build.sh build master
./build.sh build 2.10 base
./build.sh build 2.9 dev
```


175 changes: 175 additions & 0 deletions ckan-ukds-2.11/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
ARG ENV=base

FROM python:3.12-slim-bookworm AS python


# ┌─────────────────────────────────────────────────────────────┐
# │ │
# │ Base image (Production env) │
# │ --------------------------- │
# │ This is always built │
# │ │
# └─────────────────────────────────────────────────────────────┘


FROM python AS base

# Tag passed through via the Makefile
ARG CKAN_REF=${CKAN_REF}
# Make it available to child images
ENV CKAN_REF=${CKAN_REF}
ENV CKAN_INSTALL_VERSION=2.11

# Internals, you probably don't need to change these
ENV TZ=EN_GB
ENV APP_DIR=/srv/app
ENV SRC_DIR=${APP_DIR}/src
ENV CKAN_INI=${APP_DIR}/ckan.ini
ENV PIP_SRC=${SRC_DIR}
ENV CKAN_STORAGE_PATH=/var/lib/ckan
ENV GIT_URL=https://github.com/ckan/ckan.git

# Customize these in the environment (.env) file if needed
ENV CKAN_SITE_URL=http://localhost:5000
ENV CKAN__PLUGINS="image_view text_view datatables_view datastore envvars"

# UWSGI options
ENV UWSGI_HARAKIRI=50

WORKDIR ${APP_DIR}

# Check for updates
RUN apt-get update && \
apt-get upgrade -y

# Set up timezone
RUN echo ${TZ} > /etc/timezone

# Set LC_ALL=en_GB.UTF-8 will ensure that all locale-dependent operations in the current environment
# will use English language and United States cultural conventions with UTF-8 character encoding
ENV LC_ALL=en_GB.UTF-8

# Set the locale
RUN apt-get update && \
apt-get install --no-install-recommends -y locales && \
apt-get clean && \
sed -i "/$LC_ALL/s/^# //g" /etc/locale.gen && \
dpkg-reconfigure --frontend=noninteractive locales && \
update-locale LANG=${LC_ALL}

# Install system libraries
RUN apt-get install --no-install-recommends -y \
apt-utils \
g++ \
git \
libpq-dev \
libtool \
linux-headers-generic \
mc \
nano \
wget && \
apt-get clean

# Create the src directory
RUN mkdir -p ${SRC_DIR}

# Install uwsgi, the CKAN application, the dependency packages for CKAN plus some confiquration
RUN pip3 install -U pip && \
pip3 install uwsgi && \
cd ${SRC_DIR} && \
pip3 install -e git+${GIT_URL}@${CKAN_INSTALL_VERSION}#egg=ckan && \
cd ckan && \
pip3 install --no-binary markdown -r requirements.txt && \
# Install CKAN envvars to support loading config from environment variables
pip3 install -e git+https://github.com/okfn/[email protected]#egg=ckanext-envvars && \
# Install CKAN Plugins
pip3 install ckanext-pdfview \
ckanext-envvars \
ckanext-geoview \
ckanext-matomo \
ckanext-xloader && \
pip3 install -r https://raw.githubusercontent.com/ckan/ckanext-xloader/master/requirements.txt && \
pip3 install -e git+https://github.com/ckan/ckanext-pages.git#egg=ckanext-pages && \
pip3 install -U requests[security] && \
pip3 install -e git+https://github.com/ckan/ckanext-harvest.git#egg=ckanext-harvest && \
pip3 install -r ${SRC_DIR}/ckanext-harvest/requirements.txt && \
pip3 install -e git+https://github.com/ckan/ckanext-dcat.git#egg=ckanext-dcat && \
pip3 install -r ${SRC_DIR}/ckanext-dcat/requirements.txt && \
pip3 install -e git+https://github.com/JiscSD/ckanext-customised_fields_from_tag_vocabulary.git#egg=ckanext-customised_fields_from_tag_vocabulary && \
pip3 install -r ${SRC_DIR}/ckanext-customised-fields-from-tag-vocabulary/requirements.txt && \
pip3 install -e git+https://github.com/JiscSD/ckanext-ukdstheme.git#egg=ckanext-ukdstheme && \
pip3 install -r ${SRC_DIR}/ckanext-ukdstheme/requirements.txt && \
pip3 install -e git+https://github.com/JiscSD/ckanext-dataset_geo_display.git#egg=ckanext-dataset_geo_display && \
pip3 install -r ${SRC_DIR}/ckanext-dataset-geo-display/requirements.txt && \
# Create and update CKAN config
ckan generate config ${CKAN_INI} && \
ckan config-tool ${CKAN_INI} "SECRET_KEY = " && \
ckan config-tool ${CKAN_INI} "ckan.plugins = ${CKAN__PLUGINS}"

# Create ckan and ckan-sys users and the ckan-sys group plus set up the storage path
RUN groupadd -g 502 ckan-sys && \
useradd -rm -d /srv/app -s /bin/bash -g ckan-sys -u 502 ckan-sys && \
useradd -rm -d /srv/app -s /bin/bash -g ckan-sys -u 503 ckan

COPY setup/prerun.py ${APP_DIR}
COPY setup/start_ckan.sh ${APP_DIR}
ADD https://raw.githubusercontent.com/ckan/ckan/${CKAN_INSTALL_VERSION}/wsgi.py ${APP_DIR}
RUN chmod 644 ${APP_DIR}/wsgi.py

# Create entrypoint directory for children image scripts
RUN mkdir -p /docker-entrypoint.d && \
chmod 755 /docker-entrypoint.d

# Set the ownership of the app directory, usr/local and the entrypoint directory to the ckan-sys user
RUN chown -R ckan-sys:ckan-sys ${APP_DIR} && \
chown -R ckan-sys:ckan-sys /docker-entrypoint.d && \
chown -R ckan-sys:ckan-sys /usr/local

# Set the ownership of the CKAN config file, src and the storage path to the ckan user
RUN chown ckan:ckan-sys ${APP_DIR}/ckan.ini && \
chown -R ckan:ckan-sys ${APP_DIR}/src && \
mkdir -p ${CKAN_STORAGE_PATH} && \
chown -R ckan:ckan-sys ${CKAN_STORAGE_PATH}

USER ckan

EXPOSE 5000

CMD ["/srv/app/start_ckan.sh"]


# ┌─────────────────────────────────────────────────────────────┐
# │ │
# │ Dev image (Development env) │
# │ --------------------------- │
# │ This is only built when ENV=dev │
# │ │
# └─────────────────────────────────────────────────────────────┘


FROM base AS dev

ENV SRC_EXTENSIONS_DIR=${APP_DIR}/src_extensions

USER root

RUN cd ${SRC_DIR}/ckan && \
pip3 install -r https://raw.githubusercontent.com/ckan/ckan/${CKAN_INSTALL_VERSION}/dev-requirements.txt

COPY --chown=ckan-sys:ckan-sys setup/unsafe.cert setup/unsafe.key setup/start_ckan_development.sh setup/install_src.sh ${APP_DIR}

# Update local directories
RUN mkdir -p ${SRC_EXTENSIONS_DIR} /var/lib/ckan && \
chown -R ckan-sys:ckan-sys ${SRC_EXTENSIONS_DIR} && \
chown -R ckan:ckan-sys /var/lib/ckan/ && \
chmod 775 ${SRC_EXTENSIONS_DIR}

USER ckan

CMD ["/srv/app/start_ckan_development.sh"]


# ──────────────────────────────────────────────────────────────


FROM ${ENV} AS final
1 change: 1 addition & 0 deletions ckan-ukds-2.11/PYTHON_VERSION.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
1 change: 1 addition & 0 deletions ckan-ukds-2.11/VERSION.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ukds-2.11
Loading

0 comments on commit e549788

Please sign in to comment.