From 9799ae26612a8f722c3c576cbb3ed2201e74f264 Mon Sep 17 00:00:00 2001 From: Paul Weidner Date: Fri, 4 Nov 2022 22:49:44 -0700 Subject: [PATCH 1/3] Set DRUSH_OPTIONS_URI environment variable instead of yml config. --- .environment | 3 + .platform.app.yaml | 1 - drush/platformsh_generate_drush_yml.php | 80 ------------------------- 3 files changed, 3 insertions(+), 81 deletions(-) delete mode 100644 drush/platformsh_generate_drush_yml.php diff --git a/.environment b/.environment index 3e001416..c5469708 100644 --- a/.environment +++ b/.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 default site URL for drush. +export DRUSH_OPTIONS_URI=$(echo $PLATFORM_ROUTES | base64 --decode | jq -r 'map(select(.primary == true)) | first | .production_url') \ No newline at end of file diff --git a/.platform.app.yaml b/.platform.app.yaml index 7a63cc7d..aab961ab 100644 --- a/.platform.app.yaml +++ b/.platform.app.yaml @@ -80,7 +80,6 @@ hooks: # fast. deploy: | set -e - php ./drush/platformsh_generate_drush_yml.php # if drupal is installed, will call the following drush commands: # - `cache-rebuild` # - `updatedb` diff --git a/drush/platformsh_generate_drush_yml.php b/drush/platformsh_generate_drush_yml.php deleted file mode 100644 index 9dbb98c1..00000000 --- a/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, << Date: Fri, 2 Dec 2022 10:54:31 -0800 Subject: [PATCH 2/3] Correct logic to select upstream routes and sort by primary and https --- .environment | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.environment b/.environment index c5469708..8ff89c91 100644 --- a/.environment +++ b/.environment @@ -11,4 +11,4 @@ if [ -n "$PLATFORM_APP_DIR" -a -f "$PLATFORM_APP_DIR"/composer.json ] ; then fi # Set the default site URL for drush. -export DRUSH_OPTIONS_URI=$(echo $PLATFORM_ROUTES | base64 --decode | jq -r 'map(select(.primary == true)) | first | .production_url') \ No newline at end of file +export DRUSH_OPTIONS_URI=$(echo $PLATFORM_ROUTES | base64 --decode | jq -r 'to_entries | map(select(.value.type == "upstream")) | sort_by(.value.primary, .key) | reverse | [.[].key] | first') \ No newline at end of file From 8188d0a0e60e1a690e17fa28b96e060149a4e776 Mon Sep 17 00:00:00 2001 From: Paul Weidner Date: Fri, 2 Dec 2022 11:07:48 -0800 Subject: [PATCH 3/3] Only select upstream routes for the current application name --- .environment | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.environment b/.environment index 8ff89c91..c471d0f3 100644 --- a/.environment +++ b/.environment @@ -11,4 +11,4 @@ if [ -n "$PLATFORM_APP_DIR" -a -f "$PLATFORM_APP_DIR"/composer.json ] ; then fi # Set the default site URL for drush. -export DRUSH_OPTIONS_URI=$(echo $PLATFORM_ROUTES | base64 --decode | jq -r 'to_entries | map(select(.value.type == "upstream")) | sort_by(.value.primary, .key) | reverse | [.[].key] | first') \ No newline at end of file +export DRUSH_OPTIONS_URI=$(echo $PLATFORM_ROUTES | base64 --decode | jq -r "to_entries | map(select(.value.upstream == \"$PLATFORM_APPLICATION_NAME\")) | sort_by(.value.primary, .key) | reverse | [.[].key] | first") \ No newline at end of file