Skip to content

Commit

Permalink
chore(SLB-397): deploy drupal to platform.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
Leksat committed Jun 20, 2024
1 parent 2099de5 commit 163ecba
Show file tree
Hide file tree
Showing 10 changed files with 366 additions and 6 deletions.
10 changes: 10 additions & 0 deletions .platform/routes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'https://cms.{default}/':
type: upstream
upstream: 'cms:http'
cache:
enabled: true
cookies: ['/^SS?ESS/', '/^Drupal.visitor/']

'https://build.{default}/':
type: upstream
upstream: 'website:http'
3 changes: 3 additions & 0 deletions .platform/services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
db:
type: mariadb:10.11
disk: 2048
14 changes: 14 additions & 0 deletions apps/cms/.environment
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Statements in this file will be executed (sourced) by the shell in SSH
# sessions, in deploy hooks, in cron jobs, and in the application's runtime
# environment. This file must be placed in the root of the application, not
# necessarily the git repository's root. In case of multiple applications,
# each application can have its own .environment file.

# Allow executable app dependencies from Composer to be run from the path.
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

# This should be picked up by Platform's NVM.
NODE_VERSION=18
3 changes: 2 additions & 1 deletion apps/cms/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
!/web/themes/custom

# Lagoon integrations
/drush
/drush/sites
/drush/Commands
/.drush-lock-update

# Silverback
Expand Down
74 changes: 74 additions & 0 deletions apps/cms/.platform.app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: 'cms'

type: 'php:8.2'

dependencies:
php:
composer/composer: '^2.1'

relationships:
database: 'db:mysql'

disk: 2048

mounts:
'/web/sites/default/files':
source: local
source_path: 'files'
'/.drush':
source: local
source_path: 'drush'

build:
flavor: none

hooks:
build: |
set -ex
composer install --no-dev
cd ../..
pnpm i
pnpm turbo:prep
deploy: |
set -ex
php ./drush/platformsh_generate_drush_yml.php
cd web
drush -y deploy
web:
locations:
'/':
root: 'web'
expires: 5m
passthru: '/index.php'
# Deny access to all static files, except those specifically allowed below.
allow: false
rules:
'\.(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

'/sites/default/files':
allow: true
expires: 5m
passthru: '/index.php'
root: 'web/sites/default/files'
scripts: false
rules:
'^/sites/default/files/(css|js)':
expires: 2w
# AXXX Check if private files need special handling.

crons:
cms:
spec: '*/15 * * * *'
commands:
start: 'cd web && drush cron'
4 changes: 3 additions & 1 deletion apps/cms/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@
"drupal/userprotect": "^1.2",
"drupal/webform": "^6.1.5",
"drush/drush": "^12.5",
"enyo/dropzone": "^5.7.1"
"enyo/dropzone": "^5.7.1",
"platformsh/config-reader": "^2.4"
},
"conflict": {
"drupal/drupal": "*"
Expand Down Expand Up @@ -118,6 +119,7 @@
},
"[web-root]/sites/default/all.services.yml": "scaffold/all.services.yml",
"[web-root]/sites/default/production.settings.php": "scaffold/production.settings.php",
"[web-root]/sites/default/settings.platformsh.php": "scaffold/settings.platformsh.php",
"[web-root]/robots.txt": "scaffold/robots.txt"
},
"allowed-packages": [
Expand Down
48 changes: 44 additions & 4 deletions apps/cms/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 80 additions & 0 deletions apps/cms/drush/platformsh_generate_drush_yml.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/**
* @file
* A script that creates the .drush/drush.yml file.
*/

// This file should only be executed as a PHP-CLI script.
if (PHP_SAPI !== 'cli') {
exit;
}

require_once(__DIR__ . '/../vendor/autoload.php');

/**
* Returns a site URL to use with Drush, if possible.
*
* @return string|NULL
*/
function _platformsh_drush_site_url() {
$platformsh = new \Platformsh\ConfigReader\Config();

if (!$platformsh->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, <<<EOF
# Drush configuration file.
# This was automatically generated by the script:
# $scriptPath
options:
# Set the default site URL.
uri: $siteUrlYamlEscaped
EOF
);
if (!$success) {
echo "Failed to write file: $filename\n";
exit(1);
}

if (!chmod($filename, 0600)) {
echo "Failed to modify file permissions: $filename\n";
exit(1);
}

echo "Created Drush configuration file: $filename\n";
4 changes: 4 additions & 0 deletions apps/cms/scaffold/settings.php.append.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,7 @@ if (getenv('LAGOON_ENVIRONMENT') !== 'prod') {
// Disable key permissions check for Simple OAuth.
// https://www.drupal.org/project/simple_oauth/issues/3021054
$settings['simple_oauth.key_permissions_check'] = FALSE;

if (getenv('PLATFORM_PROJECT') && file_exists($app_root . '/' . $site_path . '/settings.platformsh.php')) {
include $app_root . '/' . $site_path . '/settings.platformsh.php';
}
Loading

0 comments on commit 163ecba

Please sign in to comment.