Problem/Motivation

We've been building to this for a long time.

Drupal CMS currently ships the Byte template among its dependencies, even if you don't actually intend to use it. That's because, at install time, we don't have a way to bring in site templates (or indeed, any other recipe) you choose.

I think we can make that happen.

Proposed resolution

Recipe Installer Kit lets you build up a list of recipes you want to apply. That list gets propagated in the recipes query string parameter -- it's a list of Composer package names.

As we loop through this list, we should check to see if the package exists in the code base already (i.e., it exists at the expected path). If it does, we convert it to batch operations and add it to the overall batch job, exactly as we do now.

But if it doesn't, we should add a batch operation that uses Composer to install the recipe: composer require --minimal-changes --update-with-all-dependencies PACKAGE_NAME, and when that succeeds, it converts the recipe to batch operations and appends a new batch job to apply it.

If the Composer operation fails, then it will just crap out with an exception, as would any other failed batch operation.

We will not use Package Manager for this -- at least, not at this time. Why not? Because, in the installer, we don't need most of what Package Manager gives us:

  • We're only installing stuff, not updating anything that is existing.
  • Even if something we're already running gets updated, there is no Drupal site yet to break -- we're still in the middle of installing it!
  • We'll use --minimal-changes to reduce the possibility of running code getting updated.
  • To further reduce the possibility of breaking running code, all Composer operations will happen before the operations that change runtime state -- that is, before the recipes are actually applied.

Most of the validators that ship with Package Manager -- save for maybe a few of them (WritableFilesystemValidator, DiskSpaceValidator, and MultisiteValidator spring to mind) -- are largely irrelevant whilst installing Drupal.

Furthermore, Package Manager's sandboxing capabilities are mostly there to avoid breaking a fully built, operational site. In the installer, that assumption doesn't hold. It especially doesn't hold if you're only adding packages, not changing them -- and indeed, that's the reason why Package Manager's direct-write mode was added. But Package Manager is very heavy, and very slow, and it doesn't give us much value in the installer. So we can just skip it and do Composer stuff directly.

This would not prevent PHP-TUF from playing, either. TUF operates at the Composer level and has no technical relationship to Package Manager.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

phenaproxima created an issue. See original summary.

phenaproxima’s picture

Issue summary: View changes
phenaproxima’s picture

Issue summary: View changes
catch’s picture

This would not prevent PHP-TUF from playing, either. TUF operates at the Composer level and has no technical relationship to Package Manager.

While this is true, how will php-tuf be enabled in the first place? I've generally assumed that package_manager would handle it.

and indeed, that's the reason why Package Manager's direct-write mode was added.

Is it heavy and slow in direct write mode?

phenaproxima’s picture

While this is true, how will php-tuf be enabled in the first place? I've generally assumed that package_manager would handle it.

Drupal CMS will need to enable it in the project template. That's pretty much the only way to enable it, AFAIK, since you need to opt protected repositories into TUF protection via repository-level settings in composer.json.

Is it heavy and slow in direct write mode?

Not as slow and heavy as it is in sandboxing mode, but it still does a ton of (unnecessary, at install time) status checking and validation at every step of the way.

catch’s picture

Not as slow and heavy as it is in sandboxing mode, but it still does a ton of (unnecessary, at install time) status checking and validation at every step of the way.

I'm not sure this will actually be noticeable to end users though, feels like it would be worth a try - profiling should be able to identify how much time is package manager vs. composer itself.

There's potentially massive savings in #3498026: RecipeRunner::processInstall() should allow for installing multiple modules at once too, that issue is very hard, but we know exactly what's slow and what can be saved there at least.

phenaproxima’s picture

Assigned: phenaproxima » Unassigned

I think this one is ready to go, with its minimalist scope. We can swap in Package Manager later if we want to.

Right now, in Drupal CMS, this functionality will not be surfaced because all available site templates are present in the code base, and this only does Composer stuff for projects that aren't present.

The idea is to allow the launcher app to inject a hard-coded list of additional site templates which aren't present yet. The launcher is the "happy path" for installing new dependencies -- it's a writable filesystem (since it's your desktop), and PHP is running as you. @pameeela, @hestenet, and I agree that it's the best place to pilot this functionality. So in other words, Recipe Installer Kit will support this, but only the launcher will take advantage of it.

  • phenaproxima committed bf868212 on 1.x
    feat: #3571905 Use Composer to install recipes that are not already...
phenaproxima’s picture

Status: Active » Fixed

Merged into 1.x.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • phenaproxima committed c401b92f on 1.x
    fix: #3571905 Clear extension discovery caches when Composer operation...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.