Skip to content

Commit

Permalink
Merge branch 'master' into 4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
csandanov committed Aug 7, 2024
2 parents 8640acf + e2ec81e commit 9b99f86
Show file tree
Hide file tree
Showing 6 changed files with 363 additions and 4 deletions.
6 changes: 3 additions & 3 deletions .php
Original file line number Diff line number Diff line change
@@ -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
8.3#2024-08-05T17:26:03.685118Z
8.2#2024-08-05T17:26:03.685118Z
8.1#2024-08-05T17:26:03.685118Z
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
182 changes: 182 additions & 0 deletions templates/drupal11.settings.php.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
<?php
/**
* @file
* Wodby environment configuration for Drupal 10.
*/

{{ if getenv "WODBY_HOSTS" }}{{ range jsonArray (getenv "WODBY_HOSTS") }}
$wodby['hosts'][] = '{{ . }}';
{{ end }}{{ end }}

$wodby['files_dir'] = '{{ getenv "FILES_DIR" }}';
$wodby['php_storage_dir'] = '{{ getenv "DRUPAL_PHP_STORAGE_DIR" }}';
$wodby['site'] = '{{ getenv "DRUPAL_SITE" }}';
$wodby['hash_salt'] = '{{ getenv "DRUPAL_HASH_SALT" "" }}';
$wodby['sync_salt'] = '{{ getenv "DRUPAL_FILES_SYNC_SALT" "" }}';

$wodby['db']['host'] = '{{ getenv "DB_HOST" "" }}';
$wodby['db']['port'] = '{{ getenv "DB_PORT" "3306" }}';
$wodby['db']['name'] = '{{ getenv "DB_NAME" "" }}';
{{- if getenv "DB_USERNAME" }}
$wodby['db']['username'] = '{{ getenv "DB_USERNAME" }}';
{{- else }}
{{- if getenv "DB_USER" }}
$wodby['db']['username'] = '{{ getenv "DB_USER" }}';
{{- else }}
$wodby['db']['username'] = '';
{{- end }}
{{- end }}
$wodby['db']['password'] = '{{ getenv "DB_PASSWORD" "" }}';
$wodby['db']['driver'] = '{{ getenv "DB_DRIVER" "mysql" }}';

$wodby['redis']['host'] = '{{ getenv "REDIS_HOST" "" }}';
$wodby['redis']['port'] = '{{ getenv "REDIS_PORT" "6379" }}';
{{- if getenv "REDIS_PASSWORD" }}
$wodby['redis']['password'] = '{{ getenv "REDIS_PASSWORD" }}';
{{- end }}

$wodby['solr_cloud']['password'] = '{{ getenv "SOLR_CLOUD_PASSWORD" }}';
$wodby['solr_cloud']['server'] = '{{ getenv "SOLR_CLOUD_SERVER" "solr" }}';

$wodby['athenapdf']['password'] = '{{ getenv "ATHENAPDF_PASSWORD" }}';

$wodby['2'] = '{{ getenv "WODBY2" }}';
$wodby['enable_redis'] = '{{ getenv "DRUPAL_ENABLE_REDIS_CACHE" }}';

$settings['reverse_proxy_addresses'] = (function () {
$internalSubnet = '172.17.0.0';
$internalBits = 16;

$ips = array();

if (isset($_SERVER['REMOTE_ADDR'])) {
$ips[] = $_SERVER['REMOTE_ADDR'];
}

if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ips = array_merge($ips, explode(',', (string)$_SERVER['HTTP_X_FORWARDED_FOR']));
}

$proxies = [];

foreach ($ips as $ip) {
$ip = trim($ip);
$ipLong = ip2long($ip);
$internalSubnetLong = ip2long($internalSubnet);
$mask = -1 << (32 - $internalBits);
$internalSubnetLong &= $mask;

if (($ipLong & $mask) == $internalSubnetLong) {
$proxies[] = $ip;
}
}

if (isset($_SERVER['DRUPAL_REVERSE_PROXY_ADDRESSES'])) {
$proxies = array_merge(
array_filter(
array_map(function ($item) {
return trim($item);
}, explode(',', (string)$_SERVER['DRUPAL_REVERSE_PROXY_ADDRESSES']))
),
$proxies
);
}

return array_unique($proxies);
})();

$settings['reverse_proxy'] = !empty($settings['reverse_proxy_addresses']);

if (empty($settings['container_yamls'])) {
$settings['container_yamls'][] = "sites/{$wodby['site']}/services.yml";
}

if (!array_key_exists('update_free_access', $settings)) {
$settings['update_free_access'] = FALSE;
}

if (empty($settings['hash_salt'])) {
$settings['hash_salt'] = $wodby['hash_salt'];
}

if (!array_key_exists('file_scan_ignore_directories', $settings)) {
$settings['file_scan_ignore_directories'] = [
'node_modules',
'bower_components',
];
}

if (!empty($wodby['db']['host'])) {
if (!isset($databases['default']['default'])) {
$databases['default']['default'] = [];
}

$databases['default']['default'] = array_merge(
$databases['default']['default'],
[
'host' => $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'];
}
61 changes: 61 additions & 0 deletions tests/11/compose.yml
Original file line number Diff line number Diff line change
@@ -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:
28 changes: 28 additions & 0 deletions tests/11/run.sh
Original file line number Diff line number Diff line change
@@ -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
87 changes: 87 additions & 0 deletions tests/11/tests.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 9b99f86

Please sign in to comment.