Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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","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}"
125 changes: 125 additions & 0 deletions commands/host/solr9-migrate
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#!/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"

echo_yellow "Installing ddev/ddev-solr addon..."

remove_old_config() {
echo_yellow "Removing old ddev solr configuration..."

if [ -f .ddev/docker-compose.solr.yaml ]; then
git rm .ddev/docker-compose.solr.yaml
else
echo_yellow "↳ .ddev/docker-compose.solr.yaml not found, skipping."
fi

if git ls-files .ddev/solr | grep -q .; then
git rm -rf .ddev/solr
else
echo_yellow "↳ No tracked files in .ddev/solr, skipping."
fi

git commit -m "remove the ddev drupal solr" || echo_yellow "↳ Nothing to commit for old config removal."
echo_green "✓ Old ddev solr configuration removed."
}

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."
}

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

# Replace solr conf directory
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 "↳ Removing old solr conf for upsun..."
OLD_SOLR_CONF=$(find .platform/solr-conf -mindepth 1 -maxdepth 1 -type d ! -name "9.x" 2>/dev/null | head -1)

if [ -n "$OLD_SOLR_CONF" ]; then
echo_yellow "↳ Found old solr conf: $OLD_SOLR_CONF, removing..."
git rm -rf "$OLD_SOLR_CONF"
git commit -m "remove the old solr configuration ($OLD_SOLR_CONF)"
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
if [ ! -f "$SERVICES_FILE" ]; then
echo_red "✗ File not found: $SERVICES_FILE"
exit 1
fi

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

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
echo_green "✓ Done. Solr will be available at: ${DDEV_PRIMARY_URL}:8983"
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
7 changes: 5 additions & 2 deletions settings.local.devmode.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@
$config['stage_file_proxy.settings']['origin'] = getenv('STAGE_FILE_PROXY_URL');

// Override SOLR configuration for DDEV.
$config['search_api.server.solr']['backend_config']['connector_config']['scheme'] = 'http';
$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']['host'] = 'solr';
$config['search_api.server.solr']['backend_config']['connector_config']['core'] = 'collection_1';
$config['search_api.server.solr']['backend_config']['connector_config']['port'] = '8983';
$config['search_api.server.solr']['backend_config']['connector_config']['path'] = '/';
$config['search_api.server.solr']['backend_config']['connector_config']['core'] = 'dev';
$config['search_api.server.solr']['backend_config']['connector_config']['scheme'] = 'http';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't this break all projects that update the add-on but haven't updated SOLR yet?
What is our plan of action here? We update everything at the same time?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah i was thinking we would be updating everything as it should be, but i guess we could still do that and move the solr settings file to its own like the redis, e.g settings.ddev.solr.php and copy it in with the new command solr9-local, as its not a requirement on every project

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would personally prefer the single file over multiple ones, feels like noise, but it's not a bad idea.

In any case, lets run this against a couple of projects next week, see how it works, and then merge it.


// Override SMTP configuration for DDEV.
$config['smtp.settings']['smtp_host'] = 'localhost';
Expand Down
7 changes: 5 additions & 2 deletions settings.local.perfmode.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@
$config['stage_file_proxy.settings']['origin'] = getenv('STAGE_FILE_PROXY_URL');

// Override SOLR configuration for DDEV.
$config['search_api.server.solr']['backend_config']['connector_config']['scheme'] = 'http';
$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']['host'] = 'solr';
$config['search_api.server.solr']['backend_config']['connector_config']['core'] = 'collection_1';
$config['search_api.server.solr']['backend_config']['connector_config']['port'] = '8983';
$config['search_api.server.solr']['backend_config']['connector_config']['path'] = '/';
$config['search_api.server.solr']['backend_config']['connector_config']['core'] = 'dev';
$config['search_api.server.solr']['backend_config']['connector_config']['scheme'] = 'http';

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