Skip to content

Commit

Permalink
Merge pull request #3 from hussainweb/drupal-settings
Browse files Browse the repository at this point in the history
Add Drupal configuration settings
  • Loading branch information
hussainweb authored Jan 27, 2022
2 parents 2a149a6 + a3107fa commit bb4bf06
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,5 @@ jobs:
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }}

- name: tests
run: bats tests
run: bats --verbose-run tests

1 change: 1 addition & 0 deletions install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ project_files:
global_files:

post_install_actions:
- redis/scripts/setup-drupal-settings.sh
54 changes: 54 additions & 0 deletions redis/scripts/settings.ddev.redis.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

use Drupal\Core\Installer\InstallerKernel;

if (!InstallerKernel::installationAttempted() && extension_loaded('redis') && class_exists('Drupal\redis\ClientFactory')) {
// Set Redis as the default backend for any cache bin not otherwise specified.
$settings['cache']['default'] = 'cache.backend.redis';
$settings['redis.connection']['host'] = 'redis';
$settings['redis.connection']['port'] = 6379;

// Apply changes to the container configuration to better leverage Redis.
// This includes using Redis for the lock and flood control systems, as well
// as the cache tag checksum. Alternatively, copy the contents of that file
// to your project-specific services.yml file, modify as appropriate, and
// remove this line.
$settings['container_yamls'][] = 'modules/contrib/redis/example.services.yml';

// Allow the services to work before the Redis module itself is enabled.
$settings['container_yamls'][] = 'modules/contrib/redis/redis.services.yml';

// Manually add the classloader path, this is required for the container cache bin definition below
// and allows to use it without the redis module being enabled.
$class_loader->addPsr4('Drupal\\redis\\', 'modules/contrib/redis/src');

// Use redis for container cache.
// The container cache is used to load the container definition itself, and
// thus any configuration stored in the container itself is not available
// yet. These lines force the container cache to use Redis rather than the
// default SQL cache.
$settings['bootstrap_container_definition'] = [
'parameters' => [],
'services' => [
'redis.factory' => [
'class' => 'Drupal\redis\ClientFactory',
],
'cache.backend.redis' => [
'class' => 'Drupal\redis\Cache\CacheBackendFactory',
'arguments' => ['@redis.factory', '@cache_tags_provider.container', '@serialization.phpserialize'],
],
'cache.container' => [
'class' => '\Drupal\redis\Cache\PhpRedis',
'factory' => ['@cache.backend.redis', 'get'],
'arguments' => ['container'],
],
'cache_tags_provider.container' => [
'class' => 'Drupal\redis\Cache\RedisCacheTagsChecksum',
'arguments' => ['@redis.factory'],
],
'serialization.phpserialize' => [
'class' => 'Drupal\Component\Serialization\PhpSerialize',
],
],
];
}
18 changes: 18 additions & 0 deletions redis/scripts/setup-drupal-settings.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

set -e

if [[ $DDEV_PROJECT_TYPE != drupal* ]] || [[ $DDEV_PROJECT_TYPE =~ ^drupal(6|7)$ ]] ;
then
exit 0
fi

cp redis/scripts/settings.ddev.redis.php $DDEV_APPROOT/$DDEV_DOCROOT/sites/default/

SETTINGS_FILE_NAME="${DDEV_APPROOT}/${DDEV_DOCROOT}/sites/default/settings.php"
echo "Settings file name: ${SETTINGS_FILE_NAME}"
grep -qF 'settings.ddev.redis.php' $SETTINGS_FILE_NAME || echo "
// Include settings required for Redis cache.
if ((file_exists(__DIR__ . '/settings.ddev.redis.php') && getenv('IS_DDEV_PROJECT') == 'true')) {
include __DIR__ . '/settings.ddev.redis.php';
}" >> $SETTINGS_FILE_NAME
29 changes: 27 additions & 2 deletions tests/test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ setup() {
export DDEV_NON_INTERACTIVE=true
ddev delete -Oy ${PROJNAME} || true
cd "${TESTDIR}"
ddev config --project-name=${PROJNAME} --project-type=drupal9 --docroot=web --create-docroot
ddev start -y
}

teardown() {
Expand All @@ -16,8 +14,35 @@ teardown() {
}

@test "basic installation" {
ddev config --project-name=${PROJNAME} --project-type=drupal9 --docroot=web --create-docroot
ddev start -y
cd ${TESTDIR}
ddev get ${DIR}
ddev restart
ddev redis-cli INFO | grep "^redis_version:6."
# Check if Redis configuration was setup.
[ -f web/sites/default/settings.ddev.redis.php ]
grep -F 'settings.ddev.redis.php' web/sites/default/settings.php
}

@test "non-Drupal installation" {
ddev config --project-name=${PROJNAME} --project-type=laravel --docroot=web --create-docroot
ddev start -y
cd ${TESTDIR}
ddev get ${DIR}
ddev restart
ddev redis-cli INFO | grep "^redis_version:6."
# Drupal configuration should not be present
[ ! -f web/sites/default/settings.ddev.redis.php ]
}

@test "Drupal 7 installation" {
ddev config --project-name=${PROJNAME} --project-type=drupal7 --docroot=web --create-docroot
ddev start -y
cd ${TESTDIR}
ddev get ${DIR}
ddev restart
ddev redis-cli INFO | grep "^redis_version:6."
# Drupal configuration should not be present
[ ! -f web/sites/default/settings.ddev.redis.php ]
}

0 comments on commit bb4bf06

Please sign in to comment.