diff --git a/assets/Drupal11/.upsun/config.yaml b/assets/Drupal11/.upsun/config.yaml deleted file mode 100644 index b97a71d..0000000 --- a/assets/Drupal11/.upsun/config.yaml +++ /dev/null @@ -1,148 +0,0 @@ -applications: - drupal: - # The runtime the application uses. - type: 'php:8.3' - dependencies: - php: - composer/composer: '^2.1' - runtime: - # Enable the redis extension so Drupal can communicate with the Redis cache. - extensions: - - redis - - apcu - - blackfire - # The relationships of the application with services or other applications. - # - # The left-hand side is the name of the relationship as it will be exposed - # to the application in the PLATFORM_RELATIONSHIPS variable. The right-hand - # side is in the form `:`. - relationships: - database: 'db:mysql' - redis: 'cache:redis' - # The 'mounts' describe writable, persistent filesystem mounts in the application. - mounts: - # The default Drupal files directory. - '/web/sites/default/files': - source: storage - source_path: 'files' - # Drupal gets its own dedicated tmp directory. The settings.platformsh.php - # file will automatically configure Drupal to use this directory. - '/tmp': - source: storage - source_path: 'tmp' - # Private file uploads are stored outside the web root. The settings.platformsh.php - # file will automatically configure Drupal to use this directory. - '/private': - source: storage - source_path: 'private' - # Drush needs a scratch space for its own caches. - '/.drush': - source: storage - source_path: 'drush' - # Drush will try to save backups to this directory, so it must be - # writeable even though you will almost never need to use it. - '/drush-backups': - source: storage - source_path: 'drush-backups' - # Drupal Console will try to save backups to this directory, so it must be - # writeable even though you will almost never need to use it. - '/.console': - source: storage - source_path: 'console' - # Configuration of the build of this application. - build: - flavor: composer - # The hooks executed at various points in the lifecycle of the application. - hooks: - # The build hook runs after Composer to finish preparing up your code. - # No services are available but the disk is writeable. - build: | - set -e - # The deploy hook runs after your application has been deployed and started. - # Code cannot be modified at this point but the database is available. - # The site is not accepting requests while this script runs so keep it - # fast. - deploy: | - set -e - php ./drush/platformsh_generate_drush_yml.php - # if drupal is installed, will call the following drush commands: - # - `cache-rebuild` - # - `updatedb` - # - and if config files are present, `config-import` - # cd web - bash $PLATFORM_APP_DIR/drush/platformsh_deploy_drupal.sh - # The configuration of app when it is exposed to the web. - web: - locations: - # All requests not otherwise specified follow these rules. - '/': - # The folder from which to serve static assets, for this location. - # - # This is a filesystem path, relative to the application root. - root: 'web' - # How long to allow static assets from this location to be cached. - # - # Can be a time in seconds, or -1 for no caching. Times can be - # suffixed with "s" (seconds), "m" (minutes), "h" (hours), "d" - # (days), "w" (weeks), "M" (months, as 30 days) or "y" (years, as - # 365 days). - expires: 5m - # Redirect any incoming request to Drupal's front controller. - passthru: '/index.php' - # Deny access to all static files, except those specifically allowed below. - allow: false - # Rules for specific URI patterns. - rules: - # Allow access to common static files. - '\.(avif|webp|jpe?g|png|gif|svgz?|css|js|map|ico|bmp|eot|woff2?|otf|ttf)$': - allow: true - '^/robots\.txt$': - allow: true - '^/sitemap\.xml$': - allow: true - # Deny direct access to configuration files. - '^/sites/sites\.php$': - scripts: false - '^/sites/[^/]+/settings.*?\.php$': - scripts: false - # The files directory has its own special configuration rules. - '/sites/default/files': - # Allow access to all files in the public files directory. - allow: true - expires: 5m - passthru: '/index.php' - root: 'web/sites/default/files' - # Do not execute PHP scripts from the writeable mount. - scripts: false - rules: - # Provide a longer TTL (2 weeks) for aggregated CSS and JS files. - '^/sites/default/files/(css|js)': - expires: 2w - crons: - # Run Drupal's cron tasks every 19 minutes. - drupal: - spec: '*/19 * * * *' - commands: - start: 'cd web ; drush core-cron' - source: - operations: - auto-update: - command: | - curl -fsS https://raw.githubusercontent.com/platformsh/source-operations/main/setup.sh | { bash /dev/fd/3 sop-autoupdate; } 3<&0 - root: / -services: - db: - type: mariadb:10.11 - cache: - type: redis:7.2 -routes: - "https://{default}/": - type: upstream - upstream: "drupal:http" - cache: - enabled: true - # Base the cache on the session cookie and custom Drupal cookies. Ignore all other cookies. - cookies: ['/^SS?ESS/', '/^Drupal.visitor/'] - "https://www.{default}/": - type: redirect - to: "https://{default}/" diff --git a/assets/common/.environment b/assets/common/.environment index 3e00141..70aa6c0 100644 --- a/assets/common/.environment +++ b/assets/common/.environment @@ -9,3 +9,6 @@ if [ -n "$PLATFORM_APP_DIR" -a -f "$PLATFORM_APP_DIR"/composer.json ] ; then bin=$(composer config bin-dir --working-dir="$PLATFORM_APP_DIR" --no-interaction 2>/dev/null) export PATH="${PLATFORM_APP_DIR}/${bin:-vendor/bin}:${PATH}" fi +# Set the URI for Drush commands. +export PRIMARY_URL="$(echo "$PLATFORM_ROUTES" | base64 --decode | jq -r 'to_entries[] | select(.value.primary) | .key | rtrimstr("/")')" +export DRUSH_OPTIONS_URI="$PRIMARY_URL" diff --git a/assets/common/.upsun/config.yaml b/assets/common/.upsun/config.yaml index 8a316f9..91f56dd 100644 --- a/assets/common/.upsun/config.yaml +++ b/assets/common/.upsun/config.yaml @@ -1,7 +1,7 @@ applications: drupal: # The runtime the application uses. - type: 'php:8.2' + type: 'php:7.4' dependencies: php: composer/composer: '^2.1' @@ -18,7 +18,7 @@ applications: # side is in the form `:`. relationships: database: 'db:mysql' - redis: 'cache:redis' + cache: 'cache:redis' # The 'mounts' describe writable, persistent filesystem mounts in the application. mounts: # The default Drupal files directory. @@ -35,20 +35,6 @@ applications: '/private': source: storage source_path: 'private' - # Drush needs a scratch space for its own caches. - '/.drush': - source: storage - source_path: 'drush' - # Drush will try to save backups to this directory, so it must be - # writeable even though you will almost never need to use it. - '/drush-backups': - source: storage - source_path: 'drush-backups' - # Drupal Console will try to save backups to this directory, so it must be - # writeable even though you will almost never need to use it. - '/.console': - source: storage - source_path: 'console' # Configuration of the build of this application. build: flavor: composer @@ -64,7 +50,6 @@ applications: # fast. deploy: | set -e - php ./drush/platformsh_generate_drush_yml.php # if drupal is installed, will call the following drush commands: # - `cache-rebuild` # - `updatedb` @@ -108,16 +93,13 @@ applications: # The files directory has its own special configuration rules. '/sites/default/files': # Allow access to all files in the public files directory. + # Drupal file management allows us to set extremely long cache expiry. allow: true - expires: 5m + expires: 6M passthru: '/index.php' root: 'web/sites/default/files' # Do not execute PHP scripts from the writeable mount. scripts: false - rules: - # Provide a longer TTL (2 weeks) for aggregated CSS and JS files. - '^/sites/default/files/(css|js)': - expires: 2w crons: # Run Drupal's cron tasks every 19 minutes. drupal: diff --git a/assets/common/drush/platformsh_generate_drush_yml.php b/assets/common/drush/platformsh_generate_drush_yml.php deleted file mode 100644 index 9dbb98c..0000000 --- a/assets/common/drush/platformsh_generate_drush_yml.php +++ /dev/null @@ -1,80 +0,0 @@ -inRuntime()) { - return; - } - - $routes = $platformsh->getUpstreamRoutes($platformsh->applicationName); - - // Sort URLs, with the primary route first, then by HTTPS before HTTP, then by length. - usort($routes, function (array $a, array $b) { - // false sorts before true, normally, so negate the comparison. - return - [!$a['primary'], strpos($a['url'], 'https://') !== 0, strlen($a['url'])] - <=> - [!$b['primary'], strpos($b['url'], 'https://') !== 0, strlen($b['url'])]; - }); - - // Return the url of the first one. - return reset($routes)['url'] ?: NULL; -} - -$appRoot = dirname(__DIR__); -$filename = $appRoot . '/.drush/drush.yml'; - -$siteUrl = _platformsh_drush_site_url(); - -if (empty($siteUrl)) { - echo "Failed to find a site URL\n"; - - if (file_exists($filename)) { - echo "The file exists but may be invalid: $filename\n"; - } - - exit(1); -} - -$siteUrlYamlEscaped = json_encode($siteUrl, JSON_UNESCAPED_SLASHES); -$scriptPath = __FILE__; - -$success = file_put_contents($filename, <<hasRelationship('database')) { - $creds = $platformsh->credentials('database'); +// Configure the database from the environment context. +$relationships_json = base64_decode(getenv('PLATFORM_RELATIONSHIPS')); +$relationships = json_decode($relationships_json, true); +// Example for a database relationship named 'database' +if (isset($relationships['database'])) { + // Assuming a single database relationship + $creds = $relationships['database'][0]; $databases['default']['default'] = [ 'driver' => $creds['scheme'], 'database' => $creds['path'], @@ -33,24 +35,26 @@ // Enable verbose error messages on development branches, but not on the production branch. // You may add more debug-centric settings here if desired to have them automatically enable // on development but not production. -if (isset($platformsh->branch)) { - // Production type environment. - if ($platformsh->onProduction() || $platformsh->onDedicated()) { - $config['system.logging']['error_level'] = 'hide'; - } // Development type environment. - else { - $config['system.logging']['error_level'] = 'verbose'; - } +if (getenv('PLATFORM_ENVIRONMENT_TYPE') == 'production') { + // Production environment type. + $config['system.logging']['error_level'] = 'hide'; +} else { + // Non-production environment types. + $config['system.logging']['error_level'] = 'verbose'; } // Enable Redis caching. -if ($platformsh->hasRelationship('redis') && !InstallerKernel::installationAttempted() && extension_loaded('redis') && class_exists('Drupal\redis\ClientFactory')) { - $redis = $platformsh->credentials('redis'); +// Uses relationship to a Redis-compatible backend named `cache`. +if (isset($relationships['cache']) + && !InstallerKernel::installationAttempted() + && extension_loaded('redis') + && class_exists('Drupal\redis\ClientFactory')) { + $creds = $relationships['cache'][0]; // Set Redis as the default backend for any cache bin not otherwise specified. $settings['cache']['default'] = 'cache.backend.redis'; - $settings['redis.connection']['host'] = $redis['host']; - $settings['redis.connection']['port'] = $redis['port']; + $settings['redis.connection']['host'] = $creds['host']; + $settings['redis.connection']['port'] = $creds['port']; // Apply changes to the container configuration to better leverage Redis. // This includes using Redis for the lock and flood control systems, as well @@ -97,13 +101,13 @@ ]; } -if ($platformsh->inRuntime()) { +if (getenv('PLATFORM_BRANCH')) { // Configure private and temporary file paths. if (!isset($settings['file_private_path'])) { - $settings['file_private_path'] = $platformsh->appDir . '/private'; + $settings['file_private_path'] = getenv('PLATFORM_APP_DIR') . '/private'; } if (!isset($settings['file_temp_path'])) { - $settings['file_temp_path'] = $platformsh->appDir . '/tmp'; + $settings['file_temp_path'] = getenv('PLATFORM_APP_DIR') . '/tmp'; } // Configure the default PhpStorage and Twig template cache directories. @@ -116,13 +120,13 @@ // Set the project-specific entropy value, used for generating one-time // keys and such. - $settings['hash_salt'] = empty($settings['hash_salt']) ? $platformsh->projectEntropy : $settings['hash_salt']; + $settings['hash_salt'] = empty($settings['hash_salt']) ? getenv('PLATFORM_PROJECT_ENTROPY') : $settings['hash_salt']; // This will prevent Drupal from setting read-only permissions on sites/default. $settings['skip_permissions_hardening'] = TRUE; // Set the deployment identifier, which is used by some Drupal cache systems. - $settings['deployment_identifier'] = $settings['deployment_identifier'] ?? $platformsh->treeId; + $settings['deployment_identifier'] = $settings['deployment_identifier'] ?? getenv('PLATFORM_TREE_ID');; } // The 'trusted_hosts_pattern' setting allows an admin to restrict the Host header values @@ -135,7 +139,10 @@ // Import variables prefixed with 'drupalsettings:' into $settings // and 'drupalconfig:' into $config. -foreach ($platformsh->variables() as $name => $value) { +$application_json = base64_decode(getenv('PLATFORM_APPLICATION')); +$application = json_decode($application_json, true); +$variables = isset($application['variables']) ? $application['variables'] : []; +foreach ($variables as $name => $value) { $parts = explode(':', $name); list($prefix, $key) = array_pad($parts, 3, null); switch ($prefix) { diff --git a/composer.json b/composer.json index 38f419c..438d98e 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ ], "require": { "drupal/core-composer-scaffold": "*", - "platformsh/config-reader": "*", + "drupal/core-recommended": "8.x", "drush/drush": "*", "drupal/redis": "*" }, @@ -38,10 +38,6 @@ "path": "assets/common/drush/platformsh_deploy_drupal.sh", "overwrite": false }, - "[project-root]/drush/platformsh_generate_drush_yml.php": { - "path": "assets/common/drush/platformsh_generate_drush_yml.php", - "overwrite": false - }, "[web-root]/sites/default/settings.php": { "append": "assets/common/web/sites/default/settings.php.append", "overwrite": false,