Skip to content

Commit

Permalink
Allow use of different core name, fixes #12 (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfay authored Dec 31, 2022
1 parent 586956d commit 0440d2b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

## What is this?

This repository allows you to quickly install Apache Solr for Drupal 9 into a [Ddev](https://ddev.readthedocs.io) project using just `ddev get drud/ddev-drupal9-solr`. It follows the [Setting up Solr (single core) - the classic way](https://git.drupalcode.org/project/search_api_solr/-/blob/4.x/README.md#setting-up-solr-single-core-the-classic-way) recipe.
This repository allows you to quickly install Apache Solr for Drupal 9+ into a [Ddev](https://ddev.readthedocs.io) project using just `ddev get drud/ddev-drupal9-solr`. It follows the [Setting up Solr (single core) - the classic way](https://git.drupalcode.org/project/search_api_solr/-/blob/4.x/README.md#setting-up-solr-single-core-the-classic-way) recipe.

## Installation on Drupal 9
## Installation on Drupal 9+

1. `ddev get drud/ddev-drupal9-solr && ddev restart`
1. You may need to install the relevant Drupal requirements: `ddev composer require drush/drush:* drupal/search_api_solr`
Expand All @@ -21,19 +21,32 @@ This repository allows you to quickly install Apache Solr for Drupal 9 into a [D

## Explanation

This is the classic Drupal solr:8 recipe used for a long time by Drupal users and compatible with search_api_solr.
This is the classic Drupal `solr:8` image recipe used for a long time by Drupal users and compatible with `search_api_solr`.

* It installs a [`.ddev/docker-compose.solr.yaml`](docker-compose.solr.yaml) using the solr:8 docker image.
* A standard Drupal 9 solr configuration is included in [.ddev/solr/conf](solr/conf).
* A [.ddev/docker-entrypoint-initdb.d/solr-configupdate.sh](solr/docker-entrypoint-initdb.d/solr-configupdate.sh) is included and mounted into the solr container so that you can change solr config in .ddev/solr/conf with just a `ddev restart`.
* A standard Drupal 9+ Solr configuration is included in [.ddev/solr/conf](solr/conf).
* A [.ddev/docker-entrypoint-initdb.d/solr-configupdate.sh](solr/docker-entrypoint-initdb.d/solr-configupdate.sh) is included and mounted into the Solr container so that you can change Solr config in `.ddev/solr/conf` with just a `ddev restart`.

## Interacting with Apache Solr

* The Solr admin interface will be accessible at: `http://<projectname>.ddev.site:8983/solr/` For example, if the project is named `myproject` the hostname will be: `http://myproject.ddev.site:8983/solr/`.
* To access the Solr container from inside the web container use: `http://solr:8983/solr/`
* A Solr core is automatically created by default with the name "dev"; it can be accessed (from inside the web container) at the URL: `http://solr:8983/solr/dev` or from the host at `http://<projectname>.ddev.site:8983/solr/#/~cores/dev`. You can obviously create other cores to meet your needs.

## Alternate Core Name

If you want to use a core name other than the default "dev", add a `.ddev/docker-compose.solr-env.yaml` with these contents, using the core name you want to use:
```
services:
solr:
environment:
- SOLR_CORENAME=somecorename
```
1. Remove the #ddev-generated at the top of the file.
2. Change SOLR_CORE environment variable in the `environment:` section.
3. Change your Drupal configuration to use the new core.

## Caveats
* This recipe won't work with versions of solr before solr:8, and Acquia and Pantheon.io hosting require versions from 3 to 7. You'll want to see the [contributed recipes](https://github.com/drud/ddev-contrib) for older versions of solr.
* This recipe won't work with versions of Solr before `solr:8`, and Acquia and Pantheon.io hosting require versions from 3 to 7. You'll want to see the [contributed recipes](https://github.com/drud/ddev-contrib) for older versions of solr.


8 changes: 4 additions & 4 deletions docker-compose.solr.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# DDev Apache Solr recipe file.
# DDEV Apache Solr recipe file.
#ddev-generated
#
#
Expand All @@ -23,8 +23,6 @@
# accessed at the URL: http://solr:8983/solr/dev (inside web container)
# or at http://myproject.ddev.site:8983/solr/dev (on the host)

version: '3.6'

services:
solr:
# Name of container using standard ddev convention
Expand Down Expand Up @@ -70,7 +68,9 @@ services:
# `chmod +x solr
- "./solr/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d"

entrypoint: [ "sh", "-c", "docker-entrypoint.sh solr-precreate dev /solr-conf" ]
# The odd need to use $$SOLR_CORENAME here is explained in
# https://stackoverflow.com/a/48189916/215713
entrypoint: 'bash -c "VERBOSE=yes docker-entrypoint.sh solr-precreate $${SOLR_CORENAME:-dev} /solr-conf"'

external_links:
- "ddev-router:${DDEV_SITENAME}.${DDEV_TLD}"
Expand Down
3 changes: 2 additions & 1 deletion install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ pre_install_actions:

# files and directories listed here are copied into .ddev
project_files:
- solr
- solr/conf
- solr/docker-entrypoint-initdb.d/solr-configupdate.sh
- docker-compose.solr.yaml

post_install_actions:
Expand Down
4 changes: 2 additions & 2 deletions solr/docker-entrypoint-initdb.d/solr-configupdate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#ddev-generated
set -e

# Ensure "dev" core config is always up to date even after the
# Ensure "dev" (or alternate SOLR_CORENAME) core config is always up to date even after the
# core has been created. This does not execute the first time,
# when solr-precreate has not yet run.
CORENAME=dev
CORENAME=${SOLR_CORENAME:-dev}
if [ -d /var/solr/data/${CORENAME}/conf ]; then
cp /solr-conf/conf/* /var/solr/data/${CORENAME}/conf
fi

0 comments on commit 0440d2b

Please sign in to comment.