From 6159e927b1ee9d35d0ebc2b27cb488983c4bd1d1 Mon Sep 17 00:00:00 2001 From: hw Date: Thu, 27 Jan 2022 12:43:29 -0500 Subject: [PATCH 1/4] feat: copy Drupal specific settings. See #2 --- install.yaml | 1 + redis/scripts/settings.ddev.redis.php | 54 ++++++++++++++++++++++++++ redis/scripts/setup-drupal-settings.sh | 16 ++++++++ tests/test.bats | 3 ++ 4 files changed, 74 insertions(+) create mode 100644 redis/scripts/settings.ddev.redis.php create mode 100755 redis/scripts/setup-drupal-settings.sh diff --git a/install.yaml b/install.yaml index 0457836..5ac2e01 100644 --- a/install.yaml +++ b/install.yaml @@ -15,3 +15,4 @@ project_files: global_files: post_install_actions: +- redis/scripts/setup-drupal-settings.sh diff --git a/redis/scripts/settings.ddev.redis.php b/redis/scripts/settings.ddev.redis.php new file mode 100644 index 0000000..d54e897 --- /dev/null +++ b/redis/scripts/settings.ddev.redis.php @@ -0,0 +1,54 @@ +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', + ], + ], + ]; +} diff --git a/redis/scripts/setup-drupal-settings.sh b/redis/scripts/setup-drupal-settings.sh new file mode 100755 index 0000000..3d042e1 --- /dev/null +++ b/redis/scripts/setup-drupal-settings.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +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 diff --git a/tests/test.bats b/tests/test.bats index 46926f5..0949525 100644 --- a/tests/test.bats +++ b/tests/test.bats @@ -20,4 +20,7 @@ teardown() { 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 } From 67196d40a303aa4de4bffacb3e9442aa74b5516f Mon Sep 17 00:00:00 2001 From: hw Date: Thu, 27 Jan 2022 13:20:49 -0500 Subject: [PATCH 2/4] fix: the script should break in case there is an error --- .github/workflows/tests.yml | 2 +- redis/scripts/setup-drupal-settings.sh | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6a01a53..3ef2606 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 diff --git a/redis/scripts/setup-drupal-settings.sh b/redis/scripts/setup-drupal-settings.sh index 3d042e1..6fdc73e 100755 --- a/redis/scripts/setup-drupal-settings.sh +++ b/redis/scripts/setup-drupal-settings.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +set -e + if [[ $DDEV_PROJECT_TYPE != drupal* ]] || [[ $DDEV_PROJECT_TYPE =~ ^drupal(6|7)$ ]] ; then exit 0 From 1da77a73d8aba41c68436c06412b2228f36440fd Mon Sep 17 00:00:00 2001 From: hw Date: Thu, 27 Jan 2022 13:25:34 -0500 Subject: [PATCH 3/4] fix: missing variable in script --- redis/scripts/setup-drupal-settings.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redis/scripts/setup-drupal-settings.sh b/redis/scripts/setup-drupal-settings.sh index 6fdc73e..95226c0 100755 --- a/redis/scripts/setup-drupal-settings.sh +++ b/redis/scripts/setup-drupal-settings.sh @@ -7,7 +7,7 @@ then exit 0 fi -cp redis/scripts/settings.ddev.redis.php $DDEV_APPROOT/DDEV_DOCROOT/sites/default/ +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}" From a3107fa783063ea6867b7496fd01f6508859a17a Mon Sep 17 00:00:00 2001 From: hw Date: Thu, 27 Jan 2022 13:27:56 -0500 Subject: [PATCH 4/4] test: add tests for Drupal 7 and non-Drupal systems --- tests/test.bats | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/tests/test.bats b/tests/test.bats index 0949525..c4ab65d 100644 --- a/tests/test.bats +++ b/tests/test.bats @@ -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() { @@ -16,6 +14,8 @@ 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 @@ -24,3 +24,25 @@ teardown() { [ -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 ] +}