Skip to content

Commit

Permalink
Merge pull request #6 from ckan/solr-9
Browse files Browse the repository at this point in the history
Build images for Solr 9
  • Loading branch information
amercader authored Jul 10, 2023
2 parents c126e04 + 036f2ee commit 72e54ac
Show file tree
Hide file tree
Showing 11 changed files with 245 additions and 13 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/ckan210-solr8.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: CKAN 2.10 with Solr 8

on: push

jobs:
call-reusable-workflow:
uses: ./.github/workflows/reusable.yml
with:
ckan_version: "2.10"
ckan_branch: "dev-v2.10"
solr_version: "8"
11 changes: 11 additions & 0 deletions .github/workflows/ckan210-solr9.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: CKAN 2.10 with Solr 9

on: push

jobs:
call-reusable-workflow:
uses: ./.github/workflows/reusable.yml
with:
ckan_version: "2.10"
ckan_branch: "dev-v2.10"
solr_version: "9"
11 changes: 11 additions & 0 deletions .github/workflows/ckan29-solr8.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: CKAN 2.9 with Solr 8

on: push

jobs:
call-reusable-workflow:
uses: ./.github/workflows/reusable.yml
with:
ckan_version: "2.9"
ckan_branch: "dev-v2.9"
solr_version: "8"
11 changes: 11 additions & 0 deletions .github/workflows/ckan29-solr9.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: CKAN 2.9 with Solr 9

on: push

jobs:
call-reusable-workflow:
uses: ./.github/workflows/reusable.yml
with:
ckan_version: "2.9"
ckan_branch: "dev-v2.9"
solr_version: "9"
2 changes: 1 addition & 1 deletion .github/workflows/publish-solr-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Build ckan-solr master
uses: docker/build-push-action@v3
with:
context: solr-8
context: solr-9
file: solr-8/Dockerfile
build-args: |
CKAN_BRANCH=master
Expand Down
86 changes: 86 additions & 0 deletions .github/workflows/reusable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Reusable CKAN Test workflow

on:
workflow_call:
inputs:
ckan_version:
required: true
type: string
ckan_branch:
required: true
type: string
solr_version:
required: true
type: string


jobs:
build:
runs-on: ubuntu-20.04
services:
postgres:
image: ckan/ckan-postgres-dev:master
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
ports:
- 5432:5432
redis:
image: redis:3
ports:
- 6379:6379
env:
# Given that CKAN is executed in the runner, we need to map service's port and set URL to localhost.
# We are avoiding the CKAN_ patterns since test should be run in strict mode
SQLALCHEMY_URL: postgresql://ckan_default:pass@localhost/ckan_test
DATASTORE_WRITE_URL: postgresql://datastore_write:pass@localhost/datastore_test
DATASTORE_READ_URL: postgresql://datastore_read:pass@localhost/datastore_test
SOLR_URL: http://localhost:8983/solr/ckan
REDIS_URL: redis://localhost:6379/1
steps:
- uses: actions/checkout@v3
- name: Build Solr image
run: |
cd solr-${{ inputs.solr_version }}
make build CKAN_VERSION=${{ inputs.ckan_version }}
docker run --name ckan-solr -p 8983:8983 -d ckan/ckan-solr:${{ inputs.ckan_version }}-solr${{ inputs.solr_version }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Clone CKAN repositry
run: git clone https://github.com/ckan/ckan.git
- name: Checkout CKAN ${{ inputs.ckan_branch }}
run: |
cd ckan
git checkout ${{ inputs.ckan_branch }}
- name: Install requirements-setuptools.txt (CKAN 2.9 only)
if: ${{ inputs.ckan_branch == 'dev-v2.9'}}
run: |
cd ckan
pip install -r requirement-setuptools.txt
pip install wheel
- name: Install requirements and CKAN
run: |
cd ckan
pip install -U pip
pip install -r requirements.txt
pip install -r dev-requirements.txt
# Change to `pip install .` when #7221 is merged
pip install -e .
pip check
- name: Set config file
run: |
cd ckan
ckan config-tool test-core.ini sqlalchemy.url=${SQLALCHEMY_URL}
ckan config-tool test-core.ini ckan.datastore.write_url=${DATASTORE_WRITE_URL}
ckan config-tool test-core.ini ckan.datastore.read_url=${DATASTORE_READ_URL}
ckan config-tool test-core.ini solr_url=${SOLR_URL}
ckan config-tool test-core.ini ckan.redis.url=${REDIS_URL}
- name: Execute tests
run: |
cd ckan
ckan -c test-core.ini db init
pytest --ckan-ini=test-core.ini ckan/tests ckanext
28 changes: 17 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,25 @@ Pre-configured Solr Docker images for CKAN.

**Note:** These images are built on top of [the upstream Solr images](https://github.com/apache/docker-solr#readme). These images receive bug fixes from time to time which we pull into ours, but you won't get them unless you re-pull the CKAN Solr image.

The recommended Solr version for the currently supported CKAN version is **[Solr 9](https://solr.apache.org/downloads.html#about-versions-and-support)**.

You can get a local Solr instance targeting a specific CKAN version by running the following command:

docker run --name ckan-solr -p 8983:8983 -d ckan/ckan-solr:2.10
docker run --name ckan-solr -p 8983:8983 -d ckan/ckan-solr:2.10-solr9

The following versions are available as different image tags:

| CKAN Version | Solr version | Docker tag | Notes |
| --- | --- | --- | --- |
| 2.10 | Solr 8 | `ckan/ckan-solr:2.10` | |
| 2.10 | Solr 8 | `ckan/ckan-solr:2.10-spatial` | Contains fields needed for the [ckanext-spatial](https://docs.ckan.org/projects/ckanext-spatial/en/latest/spatial-search.html) geo search |
| **2.10** | **Solr 9** | `ckan/ckan-solr:2.10-solr9` | This is the recommended version if you are unsure which one to use |
| 2.10 | Solr 9 | `ckan/ckan-solr:2.10-solr9-spatial` | Contains fields needed for the [ckanext-spatial](https://docs.ckan.org/projects/ckanext-spatial/en/latest/spatial-search.html) geo search |
| 2.10 | Solr 8 | `ckan/ckan-solr:2.10-solr8` (previously `ckan/ckan-solr:2.10`) | |
| 2.10 | Solr 8 | `ckan/ckan-solr:2.10-solr8-spatial` (previously `ckan/ckan-solr:2.10-spatial`) | Contains fields needed for the [ckanext-spatial](https://docs.ckan.org/projects/ckanext-spatial/en/latest/spatial-search.html) geo search |
| 2.9 | Solr 9 | `ckan/ckan-solr:2.9-solr9` | Requires at least CKAN 2.9.5 |
| 2.9 | Solr 9 | `ckan/ckan-solr:2.9-solr9-spatial` | Contains fields needed for the [ckanext-spatial](https://docs.ckan.org/projects/ckanext-spatial/en/latest/spatial-search.html) geo search |
| 2.9 | Solr 8 | `ckan/ckan-solr:2.9-solr8` | Requires at least CKAN 2.9.5 |
| 2.9 | Solr 8 | `ckan/ckan-solr:2.9-solr8-spatial` | Contains fields needed for the [ckanext-spatial](https://docs.ckan.org/projects/ckanext-spatial/en/latest/spatial-search.html) geo search |
| master | Solr 8 | `ckan/ckan-solr:master` | The `master` image is built nightly |
| master | Solr 9 | `ckan/ckan-solr:master` | The `master` image is built nightly |

The following tags are no longer supported:

Expand All @@ -34,34 +39,35 @@ All these images expose the CKAN Solr endpoint at **http://localhost:8983/solr/c

### Building the images

For the Solr 8 based image (ie CKAN 2.10), go to the `solr-8` directory and use the Makefile included:
Go to the relevant folder for the Solr version (eg `solr-9`) and use the Makefile included:

# Default version in 2.10
make build

# Specify a different version
make build CKAN_VERSION=2.9

Note that pre-CKAN 2.10 images use tags with a `-solr8` suffix, ie `ckan/ckan-solr:2.9-solr8`


### Use your own configuration files

If you want to play around with the solr config files you can copy them from the container to your local host and then run the container with a bind mount.

1. Run a container (eg `multi`):
1. Run a container:

docker run --name ckan-solr -p 8983:8983 -d ckan/ckan-solr:multi
docker run --name ckan-solr -p 8983:8983 -d ckan/ckan-solr:2.10-solr9

2. Copy the config file of the target core to your machine (eg `ckan-2.9`):
2. Copy the config file of the target core to your machine (eg `ckan`):

docker cp ckan-solr:/opt/solr/server/solr/ckan-2.9/conf ./my_conf
docker cp ckan-solr:/opt/solr/server/solr/ckan/conf ./my_conf

3. Stop the container:

docker stop ckan-solr

4. Run the container with a bind mount:

docker run -p 8983:8983 --mount type=bind,source="$(pwd)"/my_conf,target=/opt/solr/server/solr/ckan-2.9/conf -d ckan/ckan-solr:multi
docker run -p 8983:8983 --mount type=bind,source="$(pwd)"/my_conf,target=/opt/solr/server/solr/ckan/conf -d ckan/ckan-solr:2.10-solr9

5. Edit your local files

Expand Down
2 changes: 1 addition & 1 deletion solr-8/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.PHONY: all help build build-all push
SHELL := /bin/bash
CKAN_VERSION=2.10
TAG_NAME="ckan/ckan-solr:$(CKAN_VERSION)"
TAG_NAME="ckan/ckan-solr:$(CKAN_VERSION)-solr8"
TAG_NAME_SPATIAL="ckan/ckan-solr:$(CKAN_VERSION)-solr8-spatial"
TAG_NAME_LEGACY="ckan/ckan-solr:$(CKAN_VERSION)-solr8"

Expand Down
21 changes: 21 additions & 0 deletions solr-9/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM solr:9

EXPOSE 8983

ARG CKAN_BRANCH="dev-v2.10"

ENV SOLR_CONFIG_DIR="/opt/solr/server/solr/configsets"
ENV SOLR_SCHEMA_FILE="$SOLR_CONFIG_DIR/ckan/conf/managed-schema"

USER root

# Create a CKAN configset by copying the default one
RUN cp -R $SOLR_CONFIG_DIR/_default $SOLR_CONFIG_DIR/ckan

# Update the schema
ADD https://raw.githubusercontent.com/ckan/ckan/$CKAN_BRANCH/ckan/config/solr/schema.xml $SOLR_SCHEMA_FILE
RUN chmod 644 $SOLR_SCHEMA_FILE

USER solr

CMD ["sh", "-c", "solr-precreate ckan $SOLR_CONFIG_DIR/ckan"]
57 changes: 57 additions & 0 deletions solr-9/Dockerfile.spatial
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
FROM solr:9

EXPOSE 8983

ARG CKAN_BRANCH="dev-v2.10"

ENV SOLR_INSTALL="/opt/solr/"
ENV SOLR_CONFIG_DIR="$SOLR_INSTALL/server/solr/configsets"
ENV SOLR_SCHEMA_FILE="$SOLR_CONFIG_DIR/ckan/conf/managed-schema"

ARG JTS_VERSION="1.19.0"
ARG JTS_JAR_FILE="$SOLR_INSTALL/server/solr-webapp/webapp/WEB-INF/lib/jts-core-$JTS_VERSION.jar"

USER root

# Create a CKAN configset by copying the default one
RUN cp -R $SOLR_CONFIG_DIR/_default $SOLR_CONFIG_DIR/ckan

# Update the schema
ADD https://raw.githubusercontent.com/ckan/ckan/$CKAN_BRANCH/ckan/config/solr/schema.xml $SOLR_SCHEMA_FILE

# Install JTS JAR file
ADD https://repo1.maven.org/maven2/org/locationtech/jts/jts-core/$JTS_VERSION/jts-core-$JTS_VERSION.jar \
$JTS_JAR_FILE
RUN chmod 644 $JTS_JAR_FILE

# Add the spatial field type definitions and fields

## RPT
ENV SOLR_RPT_FIELD_DEFINITION '<fieldType name="location_rpt" class="solr.SpatialRecursivePrefixTreeFieldType" \
spatialContextFactory="JTS" \
autoIndex="true" \
validationRule="repairBuffer0" \
distErrPct="0.025" \
maxDistErr="0.001" \
distanceUnits="kilometers" />'

ENV SOLR_RPT_FIELD '<field name="spatial_geom" type="location_rpt" indexed="true" multiValued="true" />'

RUN sed -i "/<types>/a $SOLR_RPT_FIELD_DEFINITION" $SOLR_SCHEMA_FILE
RUN sed -i "/<fields>/a $SOLR_RPT_FIELD" $SOLR_SCHEMA_FILE

## BBox
ENV SOLR_BBOX_FIELDS '<field name="bbox_area" type="float" indexed="true" stored="true" /> \
<field name="maxx" type="float" indexed="true" stored="true" /> \
<field name="maxy" type="float" indexed="true" stored="true" /> \
<field name="minx" type="float" indexed="true" stored="true" /> \
<field name="miny" type="float" indexed="true" stored="true" />'

RUN sed -i "/<fields>/a $SOLR_BBOX_FIELDS" $SOLR_SCHEMA_FILE


RUN chmod 644 $SOLR_SCHEMA_FILE

USER solr

CMD ["sh", "-c", "solr-precreate ckan $SOLR_CONFIG_DIR/ckan"]
18 changes: 18 additions & 0 deletions solr-9/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.PHONY: all help build build-all push
SHELL := /bin/bash
CKAN_VERSION=2.10
TAG_NAME="ckan/ckan-solr:$(CKAN_VERSION)-solr9"
TAG_NAME_SPATIAL="ckan/ckan-solr:$(CKAN_VERSION)-solr9-spatial"

all: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'


build: ## Build a Solr 9 image for a specific CKAN version, `make build CKAN_VERSION=2.9` (default is 2.10)
docker build -t $(TAG_NAME) .
docker build -t $(TAG_NAME_SPATIAL) -f Dockerfile.spatial .

push: ## Push an image to the Docker registry, `make push CKAN_VERSION=2.9` (default is 2.10)
docker push $(TAG_NAME)
docker push $(TAG_NAME_SPATIAL)

0 comments on commit 72e54ac

Please sign in to comment.