diff --git a/.php b/.php index e42fd66..1a3717a 100644 --- a/.php +++ b/.php @@ -1,3 +1,3 @@ -8.3#2024-08-02T05:43:36.115244Z -8.2#2024-08-02T05:43:36.115244Z -8.1#2024-08-02T05:43:36.115244Z \ No newline at end of file +8.3#2024-08-05T17:26:03.685118Z +8.2#2024-08-05T17:26:03.685118Z +8.1#2024-08-05T17:26:03.685118Z \ No newline at end of file diff --git a/Makefile b/Makefile index be66a1e..60388e9 100644 --- a/Makefile +++ b/Makefile @@ -68,7 +68,8 @@ buildx-push: test: ifeq ($(PHP_VER),8.3) @echo "Drupal 7 doesn't support PHP 8.3" - cd ./tests/10 && IMAGE=$(REPO):$(TAG) ./run.sh + cd ./tests/11 && IMAGE=$(REPO):$(TAG) ./run.sh +# cd ./tests/10 && IMAGE=$(REPO):$(TAG) ./run.sh else cd ./tests/10 && IMAGE=$(REPO):$(TAG) ./run.sh cd ./tests/7 && IMAGE=$(REPO):$(TAG) ./run.sh diff --git a/templates/drupal11.settings.php.tmpl b/templates/drupal11.settings.php.tmpl new file mode 100644 index 0000000..2dfdc25 --- /dev/null +++ b/templates/drupal11.settings.php.tmpl @@ -0,0 +1,182 @@ + $wodby['db']['host'], + 'port' => $wodby['db']['port'], + 'database' => $wodby['db']['name'], + 'username' => $wodby['db']['username'], + 'password' => $wodby['db']['password'], + 'driver' => $wodby['db']['driver'], + ] + ); +} + +$settings['file_public_path'] = "sites/{$wodby['site']}/files"; +$settings['file_private_path'] = $wodby['files_dir'] . '/private'; +$settings['file_temp_path'] = '/tmp'; + +if (!empty($wodby['sync_salt']) && empty($settings['config_sync_directory'])) { + $settings['config_sync_directory'] = $wodby['files_dir'] . '/config/sync_' . $wodby['sync_salt']; +} + +if (!empty($wodby['php_storage_dir'])) { + $settings['php_storage']['default']['directory'] = $wodby['php_storage_dir']; +} + +if (!empty($wodby['hosts'])) { + foreach ($wodby['hosts'] as $host) { + $settings['trusted_host_patterns'][] = '^' . str_replace('.', '\.', $host) . '$'; + } +} + +if (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'install') { + $site_mods_dir = "sites/{$wodby['site']}/modules"; + $contrib_path = is_dir('modules/contrib') ? 'modules/contrib' : 'modules'; + $contrib_path_site = is_dir("$site_mods_dir/contrib") ? "$site_mods_dir/contrib" : $site_mods_dir; + + $redis_module_path = NULL; + + if (file_exists("$contrib_path/redis")) { + $redis_module_path = "$contrib_path/redis"; + } elseif (file_exists("$contrib_path_site/redis")) { + $redis_module_path = "$contrib_path_site/redis"; + } + + if (!empty($wodby['redis']['host']) && $redis_module_path && (empty($wodby['2']) || !empty($wodby['enable_redis']))) { + $settings['redis.connection']['host'] = $wodby['redis']['host']; + $settings['redis.connection']['port'] = $wodby['redis']['port']; + if(isset($wodby['redis']['password'])) { + $settings['redis.connection']['password'] = $wodby['redis']['password']; + } + $settings['redis.connection']['base'] = 0; + $settings['redis.connection']['interface'] = 'PhpRedis'; + $settings['cache']['default'] = 'cache.backend.redis'; + $settings['cache']['bins']['bootstrap'] = 'cache.backend.chainedfast'; + $settings['cache']['bins']['discovery'] = 'cache.backend.chainedfast'; + $settings['cache']['bins']['config'] = 'cache.backend.chainedfast'; + + $settings['container_yamls'][] = "$redis_module_path/example.services.yml"; + } +} + +if (!empty($wodby['solr_cloud']['password'])) { + $server = $wodby['solr_cloud']['server']; + $config["search_api.server.{$server}"]['backend_config']['connector_config']['password'] = $wodby['solr_cloud']['password']; +} + +if (!empty($wodby['athenapdf']['password'])) { + $config['athenapdf_api.settings']['auth_key'] = $wodby['athenapdf']['password']; +} diff --git a/tests/11/compose.yml b/tests/11/compose.yml new file mode 100644 index 0000000..8b6b2ec --- /dev/null +++ b/tests/11/compose.yml @@ -0,0 +1,61 @@ +version: "2" + +services: + nginx: + image: wodby/nginx + environment: + NGINX_BACKEND_HOST: php + NGINX_VHOST_PRESET: drupal11 + NGINX_SERVER_ROOT: /var/www/html/web + NGINX_SERVER_NAME: drupal11.test + volumes: + - codebase:/var/www/html + - files:/mnt/files + depends_on: + - php + + mariadb: + image: wodby/mariadb + environment: + MYSQL_ROOT_PASSWORD: password + MYSQL_USER: drupal + MYSQL_PASSWORD: drupal + MYSQL_DATABASE: drupal + + valkey: + image: wodby/valkey + environment: + VALKEY_PASSWORD: valkey + + php: + image: $IMAGE + environment: + DEBUG: 1 + DOCROOT_SUBDIR: web + DRUPAL_VERSION: 11 + DRUPAL_SITE: default + DRUPAL_HASH_SALT: drupal-bad-hash-salt + DRUPAL_FILES_SYNC_SALT: drupal-files-sync-bad-salt + DRUPAL_ENABLE_REDIS_CACHE: 1 + WODBY_HOSTS: |- + ["drupal11.test", "drupal11.wodby.wod.by", "test.drupal11.wodby.wod.by"] + WODBY_HOST_PRIMARY: drupal11.test + WODBY_URL_PRIMARY: http://drupal11.test + DB_HOST: mariadb + DB_USER: drupal + DB_PASSWORD: drupal + DB_NAME: drupal + DB_DRIVER: mysql + REDIS_HOST: valkey + REDIS_PORT: 6379 + REDIS_PASSWORD: valkey + PHP_SENDMAIL_PATH: /bin/true + PHP_ERROR_REPORTING: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED + volumes: + - codebase:/var/www/html + - files:/mnt/files + - ./tests.sh:/usr/local/bin/tests.sh + +volumes: + codebase: + files: \ No newline at end of file diff --git a/tests/11/run.sh b/tests/11/run.sh new file mode 100755 index 0000000..16b3164 --- /dev/null +++ b/tests/11/run.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +set -e + +if [[ -n "${DEBUG}" ]]; then + set -x +fi + +check_ready() { + docker compose exec -T "${1}" make check-ready "${@:2}" -f /usr/local/bin/actions.mk +} + +docker compose up -d + +check_ready nginx max_try=10 +check_ready php max_try=10 +check_ready mariadb max_try=12 wait_seconds=5 + +# Fix php volumes permissions again +# Docker sets ephemeral shared volume ownership to default user (wodby) in nginx container (started after php) +# In case of -dev-macos version of php images wodby owner uid/gid in php and nginx containers do not match +if [[ "${IMAGE}" =~ "-dev-macos" ]]; then + docker compose exec -T php sudo init_container +fi + +docker compose exec -T --user=0 php apk add --update jq grep +docker compose exec -T php tests.sh +docker compose down -v diff --git a/tests/11/tests.sh b/tests/11/tests.sh new file mode 100755 index 0000000..24380cd --- /dev/null +++ b/tests/11/tests.sh @@ -0,0 +1,87 @@ +#!/usr/bin/env bash + +# TODO: test sites.php entries + +set -e + +if [[ -n "${DEBUG}" ]]; then + set -x +fi + +check_rq() { + echo "Checking requirement: ${1} must be ${2}" + drush rq --format=json | jq '.[] | select(.title=="'"${1}"'") | .value' | grep -q "${2}" + echo "OK" +} + +check_status() { + echo "Checking status: ${1} must be ${2}" + drush status --format=yaml | grep -q "${1}: ${2}" + echo "OK" +} + +run_action() { + make "${@}" -f /usr/local/bin/actions.mk +} + +echo -n "Checking environment variables... " +env | grep -q ^DOCROOT_SUBDIR= +env | grep -q ^DRUPAL_VERSION= +env | grep -q ^DRUPAL_SITE= +echo "OK" + +if [[ -n "${DOCROOT_SUBDIR}" ]]; then + DRUPAL_ROOT="${APP_ROOT}/${DOCROOT_SUBDIR}" +else + DRUPAL_ROOT="${APP_ROOT}" +fi + +FILES_ARCHIVE_URL="https://s3.amazonaws.com/wodby-sample-files/drupal-php-import-test/files.tar.gz" +GIT_URL="https://github.com/drupal/recommended-project" + +make git-clone url="${GIT_URL}" -f /usr/local/bin/actions.mk +# Get latest stable drupal 11 tag. +latest_ver=$(git show-ref --tags | grep -P -o '(?<=refs/tags/)11\.[0-9]+\.[0-9]+$' | sort -rV | head -n1) +make git-checkout target="${latest_ver}" -f /usr/local/bin/actions.mk + +COMPOSER_MEMORY_LIMIT=-1 composer install -n +composer require drush/drush +#composer require drupal/redis + +echo -n "Checking drush... " +drush version --format=yaml +echo "OK" + +cd "${DRUPAL_ROOT}" + +run_action files-import source="${FILES_ARCHIVE_URL}" +run_action init-drupal + +drush si -y --db-url="${DB_DRIVER}://${DB_USER}:${DB_PASSWORD}@${DB_HOST}/${DB_NAME}" + +# Comment out redis settings before enabling the module. +#sed -i "s#^\$wodby\['redis'\]#//&#" "${CONF_DIR}/wodby.settings.php" +#drush en redis -y --quiet +#sed -i "s#^//\(\$wodby\['redis'\]\)#\1#" "${CONF_DIR}/wodby.settings.php" + +run_action cache-clear target=render +run_action cache-rebuild + +check_status "root" "${DRUPAL_ROOT}" +check_status "site" "sites/${DRUPAL_SITE}" +check_status "files" "sites/${DRUPAL_SITE}/files" +check_status "private" "${FILES_DIR}/private" +check_status "temp" "/tmp" + +#check_rq "Redis" "Connected" +check_rq "Trusted Host Settings" "Enabled" +check_rq "File system" "Writable" +check_rq "Configuration files" "Protected" + +echo -n "Checking imported files... " +curl -s -I -H "host: ${WODBY_HOST_PRIMARY}" "nginx/sites/default/files/logo.png" | grep -q "200 OK" +echo "OK" + +echo -n "Checking Drupal homepage... " +curl -s -H "host: ${WODBY_HOST_PRIMARY}" "nginx" | grep -q "Drupal ${DRUPAL_VERSION} (https://www.drupal.org)" +echo "OK"