Repository navigation
Add Composer based workflow #2405
Description
I was perusing the issue queue related to issue #1993 and was going to submit some feedback related to #2251 (comment). I was thinking about how Drupal 9 workflow has embraced composer and the workflow isn't like Drupal 7 - Drupal 8.7 where you download the project. I feel Lando should add features to simplify working with composer based projects, such as Drupal 8.8/9+ and I'm sure WordPress is close behind (johnpbloch/wordpress, fancyguy/webroot-installer). There are obviously many others.
Issue: It seems that going forward for Drupal 8.8+/9 that lando init command should not use a remote-url to download Drupal. At least not as the default.
Instead, lando docs and lando init process should reflect Drupal best practices for local development to build a project using composer. (Drupal.org guide currently suggests DDEV for local setup!?).
Lando Idea: Composer Project Made Easy
Lando should make initializing a new php project from composer easy, such as starting a new Drupal or WordPress project.
Perhaps something similar to:
lando init
From where should we get your app's codebase?
❯ composer 👈 👈
? What recipe do you want to use? drupal9
❯ drupal9
? Where is your webroot relative to the init destination? web
? What do you want to call this app? my-drupal9-projectNote: composer as a source for codebase would be a ✨ new feature. ✨
Example Result
The above example process might result in a lando.yml config similar to:
name: my-drupal9-project
recipe: drupal9
config:
webroot: drupal9/web
services:
appserver:
composer:
drupal/recommended-project: ^9
drush/drush: ^10
build:
- composer installNote: The above .lando.yml config does not work. I'm not certain why not, but it seems close. It's based on limited Lando docs about composer, see: Automatically composer install before my app starts
Working Example
An example .lando.yml that does work, and is how I currently accomplish managing sites with composer, uses run: commands during build, re-build, and destroy. I've been using this basic file for drupal 8+ projects.
name: my-drupal9-project
recipe: drupal9
config:
webroot: web
services:
appserver:
run:
- echo "▶️ Downloading Drupal and dependencies using Composer ..."
- composer create-project --no-install --remove-vcs 'drupal/recommended-project:^9' temp
- bash -c "(shopt -s dotglob && mv /app/temp/* /app) && rmdir temp" # move composer files to "app" then remove "temp"
- composer require --sort-packages -- 'drush/drush:^10'
- echo "▶️ Installing Drupal ..."
- drush si standard -y --db-url=mysql://drupal9:drupal9@database:3306/drupal9
- echo " ▶️ Note login credentials ⬆ ⬆"
events:
# Fix composer permissions bug during re-build/destroy: https://www.drupal.org/docs/develop/using-composer/starting-a-site-using-drupal-composer-project-templates
pre-uninstall:
- echo "▶️ Fix composer bug permissions for rebuild and remove composer files"
- chmod u+wX /app/web/sites/default && rm -R /app/composer.* Voilà! lando start will build and install Drupal. lando rebuild and lando destroy require events due to a known composer bug. Note: I also delete composer files as I consider it generated code based on contents of .lando.yml.
Activity
pirog commentedon Jun 17, 2020
@mdrmike i think this idea is good.
however, its worth noting that there is no "default" for initializing a drupal site, the documented "getting started" section in the drupal docs is just one possible way to get drupal.
the primary reason it does not use composer currently is because a composer based drupal installation is fundamentally at odds with how lando init works. in particular:
the utility container that is used to grab code from a source in lando init does not have php/composer installed in it by default. when that code runs we also do not yet know details of your application which may be relevant for dependency installation eg the php version. so it is sort of a chicken and the egg problem.
I think in order to get this to work we'd need to have some sort of logic that tells lando to do stuff using the appserver container after the landofile from the init is created. this would be a big change. we also would probably want this to be generic enough to handle other
create-projectscaffolding.mdrmike commentedon Jun 17, 2020
I'm happy for the feedback! Yes, using the word "default" was confusing. I just meant Lando documentation/examples going forward should reflect current Drupal8/9 recommended practices, and why I linked to Drupal.org local development guide.
Lando Init Use Cases
My understanding of
lando initis to allow a new user to get to work, by removing complexity of internals, such as details on how to create a.lando.yml? If this is correct, I think it follows thatlando initshould support the "new &/or less technical" Drupal/WorPress developers.In other words,
lando initdoesn't have to be robust and generic enough to handle all composer projects, it already does if you're technically adept with the internals. Butlando initshould handle typical use cases so that its so easy Drupal.org or WordPress.org would link to it as an easy way to get started, yet robust enough to be professional and build upon.Update Lando Docs
In the meantime, maybe its easiest to just update Lando Drupal 8/9 Docs to demonstrate current Drupal 8/9.x practices?
Example: Drupal 9 Local Development
Here are the steps to install Drupal 9 using lando and composer. The workflow is based upon Drupal 8.8+ recommendation to use composer to manage Drupal and all dependencies (modules, themes, libraries). Lando makes it simple in a few easy steps.
Overview
lando initto create configuration for new Drupal project by answering promptslando startlando composerto create Drupal scaffoldinglando composer --devto get drush, and optionally other development moduleslando composerto get project moduleslando drushto install websitegitand commit.lando.ymlandcomposer.jsonfiles to your git repo. Note: it's typically best practice to ignore other project code from your own git repo.Note 👈 👈 👈 Above: IMO, This warning is both ugly and confusing for a new user. (Lando v3.0.5)
Additional Resources on Developing with Composer
Drupal.org: Using Composer to Install Drupal and Manage Dependencies
Drupal.org: Using Composer to Download and Update Files
Drupal.org: Drupal.org local development guide
pirog commentedon Jun 29, 2020
@mdrmike i think the lowest barrier to entry flow should be what we recommend, right now i think that is to
lando initwith the tar/git repo. We certainly can document how to currently do this withcomposer create-projectIN ADDITION. You can see the Laravel docs for an example of how that would work now.I have to say that i think we want to have a low touch way to handle
composer create-projectgenerally as part oflando init. If we are getting into the business of implementing specific start states we are going to find ourselves in a difficult position as far as maintenance and upkeep is concerned. Ultimately if we dont do that upkeep the user is likely to pay the price. I'd much rather prefer something like:We could also consider "aliases" for specific implementations of the above, which feel very similar to your proposal eg the above would be equivalent to
And then when you are done you've got the drupal project running in the directory you indicated for installation, usually this is just the directory you invoke the command from. I think this would provide a more consistent overall experience for
lando init. The trick here is going to be figuring out the chicken and the egg problem discussed here #2405 (comment) but i think there are a few ways to get around that. If we can do that then everything after that just becomes the usual business eg more or less what you hadlando start lando composer require --dev --sort-packages -- 'drush/drush:^10' lando drush site:install -y --db-url=mysql://drupal9:drupal9@database:3306/drupal9On the Drush warning front: FWIW
WARN ==> May need site-local drushno longer shows up like this as of3.0.7, instead a larger message with an explanation and link to the drush docs is provided.pirog commentedon Jun 29, 2020
@dustinleblanc @serundeputy id be interested to get your feedback here. it would be great (and easy, and robust) way to support something like this.
gitressa commentedon Jul 18, 2020
I just revisited the chicken/egg challenge, using an OS which comes with PHP 7.2 by default: If I try to start a fresh Drupal 9 project with
composer create-project drupal/recommended-projectComposer complains about un-resolvable PHP version requirements (Your requirements could not be resolved [...] drupal/core 9.0.2 requires php >=7.3 ...) since Composer is checking against the host PHP version, not Lando, since it is not part of the picture yet.The chicken/egg situation of course happens since I need to be in the Drupal folder to start Lando before I can use
lando composerwith Lando's version 7.3 of PHP.In theory you can override Composer PHP version via
.composer/config.jsonfile, which doesn't seem to work. The "hacky" solution I use is to install PHP 7.3 on the host machine.--ignore-platform-reqsflag also exists, but it doesn't seem ideal.I would be fine with something like this, to start a Composer based Drupal 8/9 installation (is
--no-devstill a thing though?), allowing configurable options, as suggested in #2405 (comment):lando init --source composer --composer-project "drupal/recommended-project:^9" --composer-opts "create-project --no-dev --no-install --remove-vcs"An alias option like
lando init --source composer --recipe drupal9would be great, with as few assumptions as possible, I guess the equivalent of this?lando init --source composer --composer-project "drupal/recommended-project:^9" --composer-opts "create-project" --webroot webI suppose the
--recipe drupal9should emulate the current procedure you need to run achieve this?DDEV seem to have a start-d9-composer-based-installation-in-folder solution:
dustinleblanc commentedon Jul 20, 2020
That method DDev uses should work with Lando too, init an empty project in the current working directory, start lando, run composer, bingo. Having a wrapper for a composer source is a cool idea though. I like
lando init --source composer vendor/project --recipe some-recipegitressa commentedon Jul 20, 2020
Do you mean the DDEV approach should work currently in Lando @dustinleblanc? Would you care to share the commands? Like I outlined before, my OS has PHP 7.2, so using host Composer does not work for me ... it has to be Lando Composer.
dustinleblanc commentedon Jul 20, 2020
Yeah this should work:
mkdir my-appcd my-applando init -r drupal8# d9 should also work I think? Also, select current working directory for the code locationlando startlando composer create-project some/project --some-flags-and-stuffThe only thing you have to deal with then is that the project will be nested one directory deep and you may have to configure the web root, etc.
gitressa commentedon Jul 20, 2020
Thanks for a fast reply. Having to configure and move stuff around is what I want to avoid, though ... I assume this is what DDEV has solved.
pirog commentedon Jul 20, 2020
i think @dustinleblanc is saying "this is something you can do in the meantime" while we work on advancing this issue
dustinleblanc commentedon Jul 20, 2020
If not for having to keep the .lando.yml in the root directory, you'd be able to init right into your current working directory, but alas, composer will yell at you that the directory is not empty, which the reason our examples init the project in a nested directory. I definitely agree that being able to one-liner it to setup in your current directory would be awesome, but the current workflow is only a hop skip and a jump away from that. We can definitely put the smoother version on the list o things to do, I can imagine it not being hard with our current init formats anyway
gitressa commentedon Jul 20, 2020
Yeah, there are many possible ways to jump through hoops to make it somehow work ... Like I wrote, I currently just bump up my host PHP version, but ideally Lando should be able contain "everything", to be able to define in code (
.lando.yml) PHP versions, MySQL, Solr, etc. as well as create a project with Composer. So a one-liner would be awesome, and high on my wish list :-)mdrmike commentedon Aug 1, 2020
@gitressa I think your comments are good to note, but are dependent on OS environment and I would think outside scope of this feature request. But not my place to say. It's also worth noting in my example, lando handles php+composer setup ... so no version mismatches... or chicken+egg issue to speak of.
FWIW, the
.lando.ymlWorking Example in my original post does the same thing as #2405 (comment)Using Working Example
thats it
mdrmike commentedon Aug 1, 2020
@pirog You say "the chicken and the egg..." ??? I feel I'm missing something... at least for Drupal? This is a Working Example (.lando.yml) from my original post, the only requirement is lando. That means nothing to do with host environment as @gitressa mentioned in a comment. Maybe my example works because it uses a
drupalrecipe? If so, perhaps a solution/requirement is to determine a compatible recipe before allowing to use composer as a source?Sooo, I agree with basically everything else you & @dustinleblanc have written since. The crux of what I was hoping for was something like
lando init --source composer vendor/project --recipe some-recipewould generate a working.lando.ymlfor non-technical/lazy users. The upside is it uses "Drupal recommend practices".Example
This is a non-working init example to generate the config file, but the
.lando.ymlfile works as is.lando init --name test --source composer 'drupal/recommended-project' --recipe drupal9would generate something like:
.lando.ymllando startThat's it! serious ... boomshakalaka !
gitressa commentedon Sep 12, 2020
When the patch in the issue composer create-project should require PHP 7.3 gets implemented, being able to start a project, without checking the (irrelevant) host machine PHP with
lando init --source composer --recipe drupal9will become more urgent.stale commentedon Oct 2, 2021
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions and please check out this if you are wondering why we auto close issues.
stale commentedon Apr 16, 2022
We haven't heard anything here for about a year so we are automatically closing this issue to keep things tidy. If this is in error then please post in this thread and request the issue be reopened!