-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(SLB-397): platform.sh integration
- Loading branch information
Showing
22 changed files
with
560 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Platform.sh env vars. Used for all apps. | ||
# The file is a script which is executed in Dash. | ||
|
||
export PREVIEW_URL=$(echo $PLATFORM_ROUTES | base64 --decode | jq -r 'to_entries[] | select (.value.id == "preview") | .key') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
cms: | ||
type: 'php:8.2' | ||
|
||
dependencies: | ||
php: | ||
composer/composer: '^2.1' | ||
|
||
runtime: | ||
extensions: | ||
- sodium | ||
|
||
relationships: | ||
database: 'db:mysql' | ||
|
||
disk: 2048 | ||
|
||
mounts: | ||
'/apps/cms/web/sites/default/files': | ||
source: local | ||
source_path: 'files' | ||
'/.drush': | ||
source: local | ||
source_path: 'drush' | ||
|
||
variables: | ||
env: | ||
NVM_VERSION: v0.39.3 | ||
NODE_VERSION: v18.20.2 | ||
|
||
build: | ||
flavor: none | ||
|
||
hooks: | ||
build: | | ||
set -ex | ||
# Install NVM and switch to node version defined in env vars. Script from | ||
# https://docs.platform.sh/languages/nodejs/node-version.html#use-nvm | ||
set +x | ||
unset NPM_CONFIG_PREFIX | ||
export NVM_DIR="$PLATFORM_APP_DIR/.nvm" | ||
if [ ! -d "$PLATFORM_CACHE_DIR/.nvm" ]; then | ||
mkdir -p $PLATFORM_CACHE_DIR/.nvm | ||
fi | ||
ln -s $PLATFORM_CACHE_DIR/.nvm $NVM_DIR | ||
if [ ! -d "$PLATFORM_CACHE_DIR/.nvm/versions/node/$NODE_VERSION" ]; then | ||
export NVM_INSTALL_FILE="${PLATFORM_CACHE_DIR}/nvm_${NVM_VERSION}_install.sh" | ||
if [ ! -f "$NVM_INSTALL_FILE" ]; then | ||
wget -nc -O "$NVM_INSTALL_FILE" "https://raw.githubusercontent.com/nvm-sh/nvm/$NVM_VERSION/install.sh" | ||
fi | ||
bash $NVM_INSTALL_FILE | ||
fi | ||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" | ||
nvm use "$NODE_VERSION" | ||
set -x | ||
npm install -g [email protected] | ||
pnpm i | ||
pnpm turbo:prep:cms | ||
deploy: | | ||
set -ex | ||
cd apps/cms | ||
php ./drush/platformsh_generate_drush_yml.php | ||
cd web | ||
../vendor/bin/drush -y deploy | ||
web: | ||
locations: | ||
'/': | ||
root: 'apps/cms/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: 'apps/cms/web/sites/default/files' | ||
scripts: false | ||
rules: | ||
'^/sites/default/files/(css|js)': | ||
expires: 2w | ||
# Ensure that private files are not accessible. | ||
'^/sites/default/files/private/.*': | ||
allow: false | ||
|
||
crons: | ||
drupal: | ||
spec: '*/15 * * * *' | ||
cmd: 'cd apps/cms/web && ../vendor/bin/drush cron' | ||
|
||
################################################################################ | ||
|
||
preview: | ||
type: 'nodejs:18' | ||
|
||
# AXXX check | ||
# relationships: | ||
# cms: 'cms:http' | ||
|
||
disk: 1024 | ||
|
||
web: | ||
commands: | ||
start: cd apps/preview && pnpm start | ||
|
||
build: | ||
flavor: none | ||
|
||
hooks: | ||
build: | | ||
set -ex | ||
npm install -g [email protected] | ||
pnpm i | ||
pnpm turbo:prep:preview | ||
################################################################################ | ||
|
||
publisher: | ||
type: 'nodejs:18' | ||
|
||
disk: 1024 | ||
|
||
mounts: | ||
'/.cache': | ||
source: local | ||
source_path: 'cache' | ||
|
||
web: | ||
commands: | ||
start: cd apps/website && pnpm start | ||
|
||
build: | ||
flavor: none | ||
|
||
hooks: | ||
build: | | ||
set -ex | ||
npm install -g [email protected] | ||
pnpm i | ||
pnpm turbo:prep:website |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'https://cms.{default}/': | ||
id: cms | ||
type: upstream | ||
upstream: 'cms:http' | ||
cache: | ||
enabled: true | ||
cookies: ['/^SS?ESS/', '/^Drupal.visitor/'] | ||
|
||
'https://preview.{default}/': | ||
id: preview | ||
type: upstream | ||
upstream: 'preview:http' | ||
|
||
'https://build.{default}/': | ||
id: publisher | ||
type: upstream | ||
upstream: 'publisher:http' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
db: | ||
type: mariadb:10.11 | ||
disk: 2048 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
/** | ||
* @file | ||
* A script that creates the .drush/drush.yml file. | ||
* | ||
* Copied from https://github.com/platformsh-templates/drupal10 (paths adjusted) | ||
*/ | ||
|
||
// 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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
# We don't want install composer dependencies in node environments, so we check | ||
# for composer command. But, on Platform.sh, composer exists even in nodejs | ||
# containers. | ||
if (command -v composer >/dev/null) && ([ -z "$PLATFORM_PROJECT" ] || [ "$PLATFORM_APPLICATION_NAME" = "cms" ]); then | ||
composer install | ||
else | ||
echo 'Skipping composer install.' | ||
fi |
Oops, something went wrong.