Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
356dae0
Add install-solr script for ddev addon
gavin-webstuff Jun 11, 2026
1331a89
Add helper to get solr9 up and running locally
gavin-webstuff Jun 11, 2026
dfc0c11
Update settings override for solr local settings file
gavin-webstuff Jun 11, 2026
39baff0
Update Solr manifest and repository checks
gavin-webstuff Jun 11, 2026
c3f1b6f
Update the precommit check for ddev solr
gavin-webstuff Jun 11, 2026
22a91eb
handle solr version other than 8 to 9
gavin-webstuff Jun 11, 2026
e24628d
Merge branch 'Annertech:main' into gavin-webstuff-solr9
gavin-webstuff Jun 15, 2026
abe3c3f
rename solr9 commands
gavin-webstuff Jul 2, 2026
496e145
update command descriptions
gavin-webstuff Jul 2, 2026
edf925d
Merge branch 'Annertech:main' into gavin-webstuff-solr9
gavin-webstuff Jul 2, 2026
40f7c82
Merge branch 'Annertech:main' into gavin-webstuff-solr9
gavin-webstuff Jul 6, 2026
88bde7a
address issue where dir is missing
gavin-webstuff Jul 6, 2026
bc4fbf9
Merge branch 'gavin-webstuff-solr9' of github.com:gavin-webstuff/anne…
gavin-webstuff Jul 6, 2026
493773e
remove the ddev-drupal-solr
gavin-webstuff Jul 15, 2026
4bf5e9a
validate that ddev primary url is set
gavin-webstuff Jul 15, 2026
05850ff
handle multiple old versions of solr conf
gavin-webstuff Jul 15, 2026
c7b22d1
handle missing services file
gavin-webstuff Jul 15, 2026
a142f7a
handle custom installed solr
gavin-webstuff Jul 15, 2026
f227899
add a snippet to set an ENV variable for use in settings.php
gavin-webstuff Jul 15, 2026
6bf6929
update cli command description
gavin-webstuff Jul 15, 2026
cd4da47
update settings file to explicit pick up ddev-solr config
gavin-webstuff Jul 15, 2026
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
19 changes: 10 additions & 9 deletions commands/host/_lib/check-ddev-solr.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
#ddev-generated
#annertech-ddev
SOLR_MANIFEST="$APPROOT/.ddev/addon-metadata/solr/manifest.yaml"
SOLR_MANIFEST="$APPROOT/.ddev/addon-metadata/ddev-solr/manifest.yaml"

if [[ ! -f "$SOLR_MANIFEST" ]]; then
pass "ddev-drupal-solr not installed — project does not use Solr"
pass "ddev-solr not installed — project does not use Solr"
else
SOLR_VERSION=$(grep -E '^version:' "$SOLR_MANIFEST" | awk -F': ' '{print $2}' | tr -d '"' | xargs)
SOLR_REPO=$(grep -E '^repository:' "$SOLR_MANIFEST" | awk -F': ' '{print $2}' | tr -d '"' | xargs)

if [[ "$SOLR_REPO" == "ddev/ddev-drupal-solr" || "$SOLR_REPO" == "ddev/ddev-drupal9-solr" ]]; then
pass "ddev-drupal-solr repository is correct ($SOLR_REPO)"
if [[ "$SOLR_REPO" == "ddev/ddev-solr" ]]; then
pass "ddev-solr repository is correct ($SOLR_REPO)"
else
fail "ddev-drupal-solr repository is '$SOLR_REPO' — expected 'ddev/ddev-drupal-solr' or 'ddev/ddev-drupal9-solr'"
warn "Install the correct addon with: 'ddev add-on get ddev/ddev-drupal-solr --version $DDEV_SOLR_VERSION'"
fail "ddev-solr repository is '$SOLR_REPO' — expected 'ddev/ddev-solr'"
warn "Install the correct addon with: 'ddev add-on get ddev/ddev-solr --version $DDEV_SOLR_VERSION'"
fi

if [[ "$SOLR_VERSION" == "$DDEV_SOLR_VERSION" ]]; then
pass "ddev-drupal-solr version is $DDEV_SOLR_VERSION"
pass "ddev-solr version is $DDEV_SOLR_VERSION"
else
fail "ddev-drupal-solr version '$SOLR_VERSION' is not supported — only $DDEV_SOLR_VERSION is compatible"
warn "Install the correct version with: 'ddev add-on get ddev/ddev-drupal-solr --version $DDEV_SOLR_VERSION'"
fail "ddev-solr version '$SOLR_VERSION' is not supported — only $DDEV_SOLR_VERSION is compatible"
warn "Install the correct version with: 'ddev add-on get ddev/ddev-solr --version $DDEV_SOLR_VERSION'"
fi
fi

86 changes: 86 additions & 0 deletions commands/host/solr9-local
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/env bash
#annertech-ddev

## Description: setup ddev-solr for local use, creates a collection & rebuilds index
## Usage: solr9-local [-c]
## Example: "ddev solr9-local"
## Example: "ddev solr9-local -c"
## Flags: [{"Name":"c","Shorthand":"c","Usage":"Run Solr setup and configuration"}]

RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m'
echo_red() { echo -e "${RED}$1${NC}" >&2; }
echo_green() { echo -e "${GREEN}$1${NC}"; }
echo_yellow() { echo -e "${YELLOW}$1${NC}"; }

SOLR_SERVER_NAME="solr"
SOLR_COLLECTION="collection_1"
RUN_SETUP=false

# Optional setup argument
if [ "$1" = "-c" ] || [ "$1" = "c" ]; then
RUN_SETUP=true
fi

echo_yellow "Configuring ddev/ddev-solr for local development"

collection_exists() {
ddev solr status 2>/dev/null | grep -q "${SOLR_COLLECTION}"
}

module_enabled() {
ddev drush pm:list --status=enabled --field=name 2>/dev/null | grep -q "search_api_solr_admin"
}

configset_uploaded() {
ddev solr zk ls /configs 2>/dev/null | grep -q "${SOLR_COLLECTION}"
}

configure_local_drupal_setup() {
if collection_exists; then
echo_yellow "↳ Collection '${SOLR_COLLECTION}' already exists, skipping creation."
else
echo_yellow "↳ Creating collection '${SOLR_COLLECTION}'..."
ddev solr create_collection --name=${SOLR_COLLECTION}
fi

if module_enabled; then
echo_yellow "↳ Module 'search_api_solr_admin' already enabled, skipping."
else
echo_yellow "↳ Enabling search_api_solr_admin module..."
ddev drush en search_api_solr_admin -y
fi

if configset_uploaded; then
echo_yellow "↳ Configset already uploaded, skipping."
else
echo_yellow "↳ Uploading configset..."
ddev drush --numShards=1 search-api-solr:upload-configset ${SOLR_SERVER_NAME}
fi
}

rebuild_index() {
echo_yellow "↳ Rebuilding search index..."
ddev drush search-api:reset-tracker
ddev drush search-api:index
}

if [ "$RUN_SETUP" = true ]; then
if ! configure_local_drupal_setup; then
echo_red "✗ Setup failed."
exit 1
fi
fi

if collection_exists; then
echo_yellow "Running search index rebuild..."
if ! rebuild_index; then
echo_red "✗ Index rebuild failed."
exit 1
fi
else
echo_yellow "↳ No collection found, skipping index rebuild. Run with -c to configure."
exit 0
fi

echo_green "✓ Solr setup complete and search index rebuilt successfully."
echo_green "Visit ${DDEV_PRIMARY_URL}/admin/config/search/search-api/server/${SOLR_SERVER_NAME}"
161 changes: 161 additions & 0 deletions commands/host/solr9-migrate
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
#!/usr/bin/env bash
#annertech-ddev

## Description: Installs ddev/ddev-solr addon and will attempt to update solr for upsun configuration
## Usage: solr9-migrate
## Example: "ddev solr9-migrate"

set -e

RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m'
echo_red() { echo -e "${RED}$1${NC}" >&2; }
echo_green() { echo -e "${GREEN}$1${NC}"; }
echo_yellow() { echo -e "${YELLOW}$1${NC}"; }

SERVICES_FILE=".platform/services.yaml"
SOLR_CONF_SOURCE="web/modules/contrib/search_api_solr/solr-conf-templates/9.x"

if [ ! -f "$SERVICES_FILE" ]; then
echo_red "✗ File not found: $SERVICES_FILE"
exit 1
fi

if [ ! -d "$SOLR_CONF_SOURCE" ]; then
echo_red "✗ Solr config templates not found at $SOLR_CONF_SOURCE. Is search_api_solr installed?"
exit 1
fi

echo_yellow "Starting Solr migration..."

remove_old_config() {
if ddev add-on list --installed | grep -q "ddev-drupal-solr"; then
echo_yellow "Removing old ddev/ddev-drupal-solr addon..."
ddev add-on remove ddev/ddev-drupal-solr
echo_green "✓ Old ddev solr configuration removed."
else
echo_yellow "ddev/ddev-drupal-solr addon not installed, checking for manual files..."

FILES_REMOVED=0

if [ -f .ddev/docker-compose.solr.yaml ]; then
echo_yellow "↳ Found .ddev/docker-compose.solr.yaml, removing..."
git rm .ddev/docker-compose.solr.yaml
FILES_REMOVED=1
fi

if git ls-files .ddev/solr | grep -q .; then
echo_yellow "↳ Found tracked files in .ddev/solr, removing..."
git rm -rf .ddev/solr
FILES_REMOVED=1
fi

if [ $FILES_REMOVED -eq 1 ]; then
git commit -m "remove manually installed solr configuration" || echo_yellow "↳ Nothing to commit."
echo_green "✓ Old solr configuration removed."
else
echo_yellow "↳ No old solr files found, skipping."
fi
fi
}

install_new_addon() {
echo_yellow "Installing ddev/ddev-solr..."
ddev add-on get ddev/ddev-solr
git add .ddev/
git commit -m "install ddev/ddev-solr"
echo_green "✓ ddev/ddev-solr installed."
}

update_env_anner() {
echo_yellow "Updating .ddev/.env..."

if [ ! -f .ddev/.env ]; then
touch .ddev/.env
fi

if grep -q "^DDEV_SOLR=" .ddev/.env; then
sed -i '/^DDEV_SOLR=/d' .ddev/.env
fi

echo 'DDEV_SOLR="ddev-solr"' >> .ddev/.env
git add .ddev/.env
git commit -m "add DDEV_SOLR to .ddev/.env" || echo_yellow "↳ Nothing to commit for .ddev/.env"
echo_green "✓ .ddev/.env updated with DDEV_SOLR=ddev-solr"
}

configure_upsun() {
echo_yellow "Configuring upsun solr..."

echo_yellow "↳ Removing old solr conf for upsun..."
OLD_SOLR_CONFS=$(find .platform/solr-conf -mindepth 1 -maxdepth 1 -type d ! -name "9.x" 2>/dev/null)

if [ -n "$OLD_SOLR_CONFS" ]; then
while IFS= read -r old_conf; do
echo_yellow "↳ Removing: $old_conf"
git rm -rf "$old_conf"
done <<< "$OLD_SOLR_CONFS"
git commit -m "remove old solr configurations"
else
echo_yellow "↳ No old solr conf directory found, skipping removal."
fi

echo_yellow "↳ Copying new solr 9 configuration..."
if [ -d ".platform/solr-conf/9.x" ]; then
echo_yellow "↳ .platform/solr-conf/9.x already exists, overwriting..."
rm -rf .platform/solr-conf/9.x
fi

cp -r "$SOLR_CONF_SOURCE" .platform/solr-conf
git add .platform/solr-conf
git commit -m "add new solr 9 configuration" || echo_yellow "↳ Nothing to commit for solr 9 configuration."
echo_green "✓ Old solr configuration replaced with solr 9 configuration."

# Update services.yaml
echo_yellow "Updating $SERVICES_FILE..."

# Solr version
if grep -q "type: solr:9.4" "$SERVICES_FILE"; then
echo_yellow "↳ Solr version already updated, skipping."
else
CURRENT_VERSION=$(grep -E 'type: solr:' "$SERVICES_FILE" | awk -F'solr:' '{print $2}' | xargs)
sed -i 's/type: solr:[0-9]\+\.[0-9]\+/type: solr:9.4/g' "$SERVICES_FILE"
echo_green "✓ solr:${CURRENT_VERSION} -> 9.4"
fi

# Solr core name
if grep -q "maincore" "$SERVICES_FILE"; then
echo_yellow "↳ Solr core name already updated, skipping."
else
sed -i 's/solr8core/maincore/g' "$SERVICES_FILE"
echo_green "✓ solr8core -> maincore"
fi

# Solr conf_dir
if grep -q "solr-conf/9.x" "$SERVICES_FILE"; then
echo_yellow "↳ Solr conf_dir already updated, skipping."
else
sed -i 's|conf_dir: !archive "solr-conf/8\.x"|conf_dir: !archive "solr-conf/9.x"|g' "$SERVICES_FILE"
echo_green "✓ solr-conf/8.x -> solr-conf/9.x"
fi

echo ""
echo_yellow "Review changes with: 'git diff $SERVICES_FILE'"
echo_yellow "If changes look good, commit with: 'git commit $SERVICES_FILE -m \"update solr to 9 configuration\"'"
}

remove_old_config
install_new_addon
configure_upsun
update_env_anner

echo ""
echo_green "✓ ddev-solr installed successfully."
echo_yellow "↳ Running 'ddev restart' to apply changes."
echo_yellow "↳ After restart, run 'ddev solr9 -c' to configure Solr and rebuild the index."
ddev restart

if [ -z "$DDEV_PRIMARY_URL" ]; then
echo_green "✓ Done."
else
echo_green "✓ Done. Solr will be available at: ${DDEV_PRIMARY_URL}:8983"
fi
26 changes: 15 additions & 11 deletions scripts/git-hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -123,27 +123,31 @@ if [ -n "$STAGED_FILES" ]; then
fi

#
# Abort commit if you are using an incompatible or unexpected ddev-drupal-solr addon
# Abort commit if you are using an incompatible Solr version
#
SOLR_MANIFEST_FILE=".ddev/addon-metadata/solr/manifest.yaml"
SOLR_MANIFEST_FILE=".ddev/addon-metadata/ddev-solr/manifest.yaml"
STAGED_FILES=$(git diff --cached --name-only | grep -F "$SOLR_MANIFEST_FILE")

if [ -n "$STAGED_FILES" ]; then
SOLR_VERSION=$(grep -E '^version:' "$SOLR_MANIFEST_FILE" | awk -F': ' '{print $2}' | tr -d '"' | xargs)
SOLR_REPO=$(grep -E '^repository:' "$SOLR_MANIFEST_FILE" | awk -F': ' '{print $2}' | tr -d '"' | xargs)
SOLR_VERSION_OUTPUT=$(ddev solr --version 2>/dev/null)

if [[ "$SOLR_REPO" != "ddev/ddev-drupal-solr" ]]; then
echo "COMMIT REJECTED: Unexpected Solr addon repository: '$SOLR_REPO'"
echo "Expected: 'ddev/ddev-drupal-solr'"
echo "Install the correct addon with: 'ddev add-on get ddev/ddev-drupal-solr --version v1.2.3'"
if [[ -z "$SOLR_VERSION_OUTPUT" ]]; then
echo "COMMIT REJECTED: Could not determine Solr version. Is ddev running?"
echo "Run 'ddev start' and try again."
exit 1
fi

if [[ "$SOLR_VERSION" != "v1.2.3" ]]; then
echo "COMMIT REJECTED: ddev-drupal-solr version '$SOLR_VERSION' is not supported."
echo "Only v1.2.3 is compatible. Install it with: 'ddev add-on get ddev/ddev-drupal-solr --version v1.2.3'"
SOLR_VERSION=$(echo "$SOLR_VERSION_OUTPUT" | awk '{print $NF}')
MAJOR_VERSION=$(echo "$SOLR_VERSION" | cut -d'.' -f1)

if [[ "$MAJOR_VERSION" != "9" ]]; then
echo "COMMIT REJECTED: Solr version '$SOLR_VERSION' is not supported."
echo "Only Solr 9.x is compatible."
echo "Reinstall with: 'ddev add-on get ddev/ddev-solr'"
exit 1
fi

echo "✓ Solr version $SOLR_VERSION is compatible."
fi

#
Expand Down
8 changes: 8 additions & 0 deletions settings.local.devmode.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
$config['search_api.server.solr']['backend_config']['connector_config']['path'] = '/';
$config['search_api.server.solr']['backend_config']['connector_config']['core'] = 'dev';

// These changes are for ddev-solr only.
if (getenv('DDEV_SOLR') === 'ddev-solr') {
$config['search_api.server.solr']['backend_config']['connector'] = 'solr_cloud_basic_auth';
$config['search_api.server.solr']['backend_config']['connector_config']['username'] = 'solr';
$config['search_api.server.solr']['backend_config']['connector_config']['password'] = 'SolrRocks';
$config['search_api.server.solr']['backend_config']['connector_config']['core'] = 'collection_1';
}

// Override SMTP configuration for DDEV.
$config['smtp.settings']['smtp_host'] = 'localhost';
$config['smtp.settings']['smtp_port'] = '1025';
Expand Down
8 changes: 8 additions & 0 deletions settings.local.perfmode.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
$config['search_api.server.solr']['backend_config']['connector_config']['path'] = '/';
$config['search_api.server.solr']['backend_config']['connector_config']['core'] = 'dev';

// These changes are for ddev-solr only.
if (getenv('DDEV_SOLR') === 'ddev-solr') {
$config['search_api.server.solr']['backend_config']['connector'] = 'solr_cloud_basic_auth';
$config['search_api.server.solr']['backend_config']['connector_config']['username'] = 'solr';
$config['search_api.server.solr']['backend_config']['connector_config']['password'] = 'SolrRocks';
$config['search_api.server.solr']['backend_config']['connector_config']['core'] = 'collection_1';
}

// Override SMTP configuration for DDEV.
$config['smtp.settings']['smtp_host'] = 'localhost';
$config['smtp.settings']['smtp_port'] = '1025';
Expand Down
Loading