diff --git a/.eslintignore b/.eslintignore index e0588c1..1be44ff 100644 --- a/.eslintignore +++ b/.eslintignore @@ -3,3 +3,8 @@ cache dist _site !.vitepress + +# Examples are executable integration specs; they can generate full Drupal codebases under examples/*/* +# which include their own ESLint config/deps that we do not install in this repo. +examples/** +examples/*/*/** diff --git a/.github/workflows/pr-drupal-tests.yml b/.github/workflows/pr-drupal-tests.yml index 5e230aa..a763e96 100644 --- a/.github/workflows/pr-drupal-tests.yml +++ b/.github/workflows/pr-drupal-tests.yml @@ -21,6 +21,7 @@ jobs: leia-test: - examples/drupal-custom - examples/drupal-defaults + - examples/drupal-drush-uri - examples/drupal-export - examples/drupal-import - examples/drupal-mariadb diff --git a/CHANGELOG.md b/CHANGELOG.md index ae56b09..608cc76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## {{ UNRELEASED_VERSION }} - [{{ UNRELEASED_DATE }}]({{ UNRELEASED_LINK }}) +* Added `drush_uri` configuration option to set `DRUSH_OPTIONS_URI` environment variable in the appserver service. * Updated to [@lando/mariadb@1.8.0](https://github.com/lando/mariadb/releases/tag/v1.8.0) * Updated to [@lando/postgres@1.6.0](https://github.com/lando/postgres/releases/tag/v1.6.0) diff --git a/builders/_drupaly.js b/builders/_drupaly.js index 538c003..cced1bc 100644 --- a/builders/_drupaly.js +++ b/builders/_drupaly.js @@ -242,6 +242,7 @@ module.exports = { webroot: '.', xdebug: false, proxy: {}, + drush_uri: null, }, builder: (parent, config) => class LandoDrupal extends parent { constructor(id, options = {}) { @@ -290,6 +291,23 @@ module.exports = { options.services = _.merge({}, getServices(options), options.services); options.tooling = _.merge({}, getTooling(options), options.tooling); + // Set DRUSH_OPTIONS_URI based on drush_uri config or proxy settings + let drushUri = options.drush_uri; + if (!drushUri) { + const proxyUrl = options.proxy[options.proxyService]?.[0]; + if (proxyUrl) { + // Check SSL setting for the proxy service + const proxyServiceSsl = options.services[options.proxyService]?.ssl; + const ssl = proxyServiceSsl !== undefined ? proxyServiceSsl : options.services.appserver?.ssl; + drushUri = ssl ? `https://${proxyUrl}` : `http://${proxyUrl}`; + } + } + + if (drushUri) { + options.services.appserver.environment = options.services.appserver.environment || {}; + options.services.appserver.environment.DRUSH_OPTIONS_URI = drushUri; + } + // Send downstream super(id, _.merge({}, config, options)); } diff --git a/docs/config.md b/docs/config.md index 82a98f2..a41fba8 100644 --- a/docs/config.md +++ b/docs/config.md @@ -13,11 +13,12 @@ Here are the configuration options, set to the default values, for this recipe's recipe: drupal11 config: php: '8.3' - composer_version: 2-latest + composer_version: '2-latest' via: apache:2.4 - webroot: . - database: mysql:8.0 - drush: false + webroot: public + database: mysql:8.4 + drush: ^13 + drush_uri: SEE BELOW xdebug: false config: database: SEE BELOW @@ -139,6 +140,15 @@ port: 3306 You can get also get the above information, and more, by using the [`lando info`](https://docs.lando.dev/cli/info.html) command. +## Configuring Drush URI + +The `drush_uri` option allows you to set a custom URL for Drush to use when connecting to your Drupal site. This overrides the `DRUSH_OPTIONS_URI` environment variable in the `appserver` service which, by default, is automatically set to the proxy URL for the webserver you are using. You will need to run `lando rebuild` to apply changes to this setting. + +```yaml +recipe: drupal11 +config: + drush_uri: 'https://custom-uri.lndo.site' +``` ## Using custom config files diff --git a/docs/legacy/drupal-7.md b/docs/legacy/drupal-7.md index d891753..22bb492 100644 --- a/docs/legacy/drupal-7.md +++ b/docs/legacy/drupal-7.md @@ -77,7 +77,7 @@ config: While Lando will globally install Drush for you it is increasingly common and in some cases a straight-up best practice to [install a site-local Drush](https://www.drush.org/latest/install/) by requiring it in your projects `composer.json` file. -Because of how Lando's [php service](https://docs.lando.dev/plugins/php) sets up its [`PATH`](https://docs.lando.dev/plugins/php/caveats.html) this means that if you have indeed installed Drush on your own via `composer` Lando will use yours over its own. +Because of how Lando's [php service](https://docs.lando.dev/plugins/php/index.html) sets up its [`PATH`](https://docs.lando.dev/plugins/php/caveats.html) this means that if you have indeed installed Drush on your own via `composer` Lando will use yours over its own. Said more explicitly: **if you've required `drush` via `composer` in your application then this recipe will use your `drush` and not the one you've specified in this recipes config.** diff --git a/examples/drupal-drush-uri/README.md b/examples/drupal-drush-uri/README.md new file mode 100644 index 0000000..c42990e --- /dev/null +++ b/examples/drupal-drush-uri/README.md @@ -0,0 +1,89 @@ +# Drupal Drush URI Example + +This example exists primarily to test the following documentation: + +* [Drupal Recipe Configuration](https://docs.lando.dev/config/drupal.html#configuring-drush-uri) + +## Start up tests + +Run the following commands to get up and running with this example. + +```bash +# Should poweroff +lando poweroff + +# Should initialize the latest Drupal 10 codebase +rm -rf drupal-drush-uri && mkdir -p drupal-drush-uri && cd drupal-drush-uri +lando init --source remote --remote-url https://ftp.drupal.org/files/projects/drupal-10.0.x-dev.tar.gz --remote-options="--strip-components 1" --recipe drupal10 --webroot . --name lando-drupal-drush-uri + +# Should start up successfully +cd drupal-drush-uri +cp -f ../../.lando.upstream.yml .lando.upstream.yml && cat .lando.upstream.yml +lando start +``` + +## Verification commands + +Run the following commands to validate things are rolling as they should. + +```bash +# Should use default drush_uri based on proxy settings +cd drupal-drush-uri +lando exec appserver -- env | grep DRUSH_OPTIONS_URI | grep "https://lando-drupal-drush-uri.lndo.site" + +# Should use site-local drush if installed +cd drupal-drush-uri +lando composer require drush/drush +lando exec appserver -- which drush | grep "/app/vendor/bin/drush" + +# Should be able to install drupal +cd drupal-drush-uri +lando drush si --db-url=mysql://drupal10:drupal10@database/drupal10 -y + +# Should be able to use drush with default uri +cd drupal-drush-uri +lando drush status | grep "Site URI" | grep "https://lando-drupal-drush-uri.lndo.site" +``` + +## Custom drush_uri test + +Now let's test with a custom drush_uri configuration. + +```bash +# Should update the .lando.yml file +cd drupal-drush-uri +cat > .lando.yml << EOF +name: lando-drupal-drush-uri +recipe: drupal10 +config: + drush_uri: 'https://custom-uri.lndo.site' +EOF + +# Should rebuild with new configuration +cd drupal-drush-uri +lando rebuild -y + +# Should use custom drush_uri +cd drupal-drush-uri +lando exec appserver -- env | grep DRUSH_OPTIONS_URI | grep "https://custom-uri.lndo.site" + +# Should use site-local drush if installed +cd drupal-drush-uri +lando composer require drush/drush +lando exec appserver -- which drush | grep "/app/vendor/bin/drush" + +# Should be able to use drush with custom uri +cd drupal-drush-uri +lando drush status | grep "Site URI" | grep "https://custom-uri.lndo.site" +``` + +## Destroy tests + +Run the following commands to trash this app like nothing ever happened. + +```bash +# Should be destroyed with success +cd drupal-drush-uri +lando destroy -y +lando poweroff +``` diff --git a/examples/drupal10/README.md b/examples/drupal10/README.md index 237b33e..5833c80 100644 --- a/examples/drupal10/README.md +++ b/examples/drupal10/README.md @@ -69,6 +69,10 @@ lando exec appserver -- which drush | grep "/app/vendor/bin/drush" cd drupal10 lando drush si --db-url=mysql://drupal10:drupal10@database/drupal10 -y +# Should use default drush_uri based on proxy settings +cd drupal10 +lando drush uli --no-browser | tee >(cat 1>&2) | grep "lando-drupal10.lndo.site" + # Should be able to enable and access jsonapi cd drupal10 lando drush en jsonapi -y diff --git a/examples/drupal11-nginx/README.md b/examples/drupal11-nginx/README.md index 6ec2fbe..b690101 100644 --- a/examples/drupal11-nginx/README.md +++ b/examples/drupal11-nginx/README.md @@ -44,9 +44,9 @@ lando exec appserver -- curl -IL appserver_nginx | grep Server | grep nginx cd nginx lando mysql -V | grep 8.0 -# Should be running sqlite 3.45 by default +# Should be running sqlite 3.46 by default cd nginx -lando php -r "print_r(SQLite3::version());" | grep versionString | tee >(cat 1>&2) | grep 3.45 +lando php -r "print_r(SQLite3::version());" | grep versionString | tee >(cat 1>&2) | grep 3.46. # Should not enable xdebug by default cd nginx diff --git a/examples/drupal11/README.md b/examples/drupal11/README.md index da17983..6c02634 100644 --- a/examples/drupal11/README.md +++ b/examples/drupal11/README.md @@ -50,9 +50,9 @@ lando exec appserver -- curl -IL localhost | grep Server | grep 2.4 cd drupal11 lando mysql -V | grep 8.0 -# Should be running sqlite 3.45 by default +# Should be running sqlite 3.46 by default cd drupal11 -lando php -r "print_r(SQLite3::version());" | grep versionString | tee >(cat 1>&2) | grep 3.45 +lando php -r "print_r(SQLite3::version());" | grep versionString | tee >(cat 1>&2) | grep 3.46. # Should not enable xdebug by default cd drupal11 @@ -75,6 +75,10 @@ lando exec appserver -- which drush | grep "/app/vendor/bin/drush" cd drupal11 lando drush si --db-url=mysql://drupal11:drupal11@database/drupal11 -y +# Should use default drush_uri based on proxy settings +cd drupal11 +lando drush uli --no-browser | tee >(cat 1>&2) | grep "lando-drupal11.lndo.site" + # Should be able to enable and access jsonapi cd drupal11 lando drush en jsonapi -y diff --git a/examples/drupal7/README.md b/examples/drupal7/README.md index 76c5295..23d5e30 100644 --- a/examples/drupal7/README.md +++ b/examples/drupal7/README.md @@ -14,7 +14,7 @@ lando poweroff # Should initialize the latest Drupal 7 codebase rm -rf drupal7 && mkdir -p drupal7 && cd drupal7 -lando init --source remote --remote-url https://ftp.drupal.org/files/projects/drupal-7.71.tar.gz --remote-options="--strip-components 1" --recipe drupal7 --webroot . --name lando-drupal7 --option drush="^8" +lando init --source remote --remote-url https://ftp.drupal.org/files/projects/drupal-7.103.tar.gz --remote-options="--strip-components 1" --recipe drupal7 --webroot . --name lando-drupal7 # Should start up successfully cd drupal7 @@ -34,16 +34,16 @@ lando exec appserver -- curl -L localhost | grep "Drupal 7" # Should use 7.4 as the default php version cd drupal7 -lando php -v | grep "PHP 7.4" +lando php -v | tee >(cat 1>&2) | grep "PHP 7.4" # Should be running apache 2.4 by default cd drupal7 -lando exec appserver -- apachectl -V | grep 2.4 -lando exec appserver -- curl -IL localhost | grep Server | grep 2.4 +lando exec appserver -- apachectl -V | tee >(cat 1>&2) | grep 2.4 +lando exec appserver -- curl -IL localhost | grep Server | tee >(cat 1>&2) | grep 2.4 # Should be running mysql 5.7 by default cd drupal7 -lando mysql -V | grep 5.7 +lando mysql -V | tee >(cat 1>&2) | grep 5.7 # Should be using the mysql_native_password authentication plugin by default cd drupal7 @@ -59,7 +59,7 @@ lando mysql -udrupal7 -pdrupal7 drupal7 -e quit # Should use drush 8.5.x by default cd drupal7 -lando drush version | grep 8.5 +lando drush version | tee >(cat 1>&2) | grep 8.5 # Should be able to install drupal cd drupal7 @@ -67,7 +67,7 @@ lando drush si --db-url=mysql://drupal7:drupal7@database/drupal7 -y # Should have infinite memory for drush cd drupal7 -lando drush eval "phpinfo();" | grep memory_limit | grep -e "-1" +lando drush eval "phpinfo();" | grep memory_limit | tee >(cat 1>&2) | grep -e "-1" # Should have SIMPLETEST envvars set correctly cd drupal7 diff --git a/netlify.toml b/netlify.toml index 0b65fdc..2d3f271 100644 --- a/netlify.toml +++ b/netlify.toml @@ -15,7 +15,7 @@ "CHANGELOG.html", "x.com", "twitter.com", - "https://www.drupal.org", + "drupal.org", "/v/" ] skipPatterns = [ ".rss", ".gif", ".jpg" ]