lando / core-next

Next generation Lando v4 runtime
https://docs.lando.dev/v/next
GNU General Public License v3.0
4 stars 4 forks source link

Tooling: Allow Chaining of Custom Tooling Commands #31

Open AaronFeledy opened 4 years ago

AaronFeledy commented 4 years ago

As a Lando user who frequently builds custom tooling to execute common tasks, I find that some of those tasks get repeated within more than one command. For example:

tooling:
  install-deps:
    description: Install project dependencies
    cmd:
      - appserver: cd /app/drupal && COMPOSER_PROCESS_TIMEOUT=600 composer install
      - nodejs: yarn install
  install-db:
    description: Download and install project database
    cmd:
      - appserver: /app/drupal && platform db:dump --gzip --environment=develop --file=db_dump.sql.gz --yes
      - database: cd /app/drupal && /helpers/sql-import.sh db_dump.sql.gz
      - appserver: cd /app/drupal && /app/drupal/vendor/bin/drush cache:rebuild
      - appserver: cd /app/drupal && /app/drupal/vendor/bin/drush updatedb --yes
      - appserver: cd /app/drupal && /app/drupal/vendor/bin/drush config:import --yes
      - appserver: cd /app/drupal && /app/drupal/vendor/bin/drush config:import --yes
      - appserver: cd /app/drupal && /app/drupal/vendor/bin/drush cache:rebuild
      - appserver: cd /app/drupal && /app/drupal/vendor/bin/drush user:login
  install-everything:
    description: Download and install project dependencies and database
    cmd:
      - appserver: cd /app/drupal && COMPOSER_PROCESS_TIMEOUT=600 composer install
      - nodejs: yarn install
      - appserver: /app/drupal && platform db:dump --gzip --environment=develop --file=db_dump.sql.gz --yes
      - database: cd /app/drupal && /helpers/sql-import.sh db_dump.sql.gz
      - appserver: cd /app/drupal && /app/drupal/vendor/bin/drush cache:rebuild
      - appserver: cd /app/drupal && /app/drupal/vendor/bin/drush updatedb --yes
      - appserver: cd /app/drupal && /app/drupal/vendor/bin/drush config:import --yes
      - appserver: cd /app/drupal && /app/drupal/vendor/bin/drush config:import --yes
      - appserver: cd /app/drupal && /app/drupal/vendor/bin/drush cache:rebuild
      - appserver: cd /app/drupal && /app/drupal/vendor/bin/drush user:login

services:
  appserver:
    run:
      - appserver: cd /app/drupal && COMPOSER_PROCESS_TIMEOUT=600 composer install
      - nodejs: yarn install
      - appserver: /app/drupal && platform db:dump --gzip --environment=develop --file=db_dump.sql.gz --yes
      - database: cd /app/drupal && /helpers/sql-import.sh db_dump.sql.gz
      - appserver: cd /app/drupal && /app/drupal/vendor/bin/drush cache:rebuild
      - appserver: cd /app/drupal && /app/drupal/vendor/bin/drush updatedb --yes
      - appserver: cd /app/drupal && /app/drupal/vendor/bin/drush config:import --yes
      - appserver: cd /app/drupal && /app/drupal/vendor/bin/drush config:import --yes
      - appserver: cd /app/drupal && /app/drupal/vendor/bin/drush cache:rebuild
      - appserver: cd /app/drupal && /app/drupal/vendor/bin/drush user:login

So much repetition there.

Lando can help solve this problem by allowing the chaining of tooling commands from within the command definition. More simply, this means allowing one Lando command to call another. In a perfect world, this would work, not only for custom tooling commands, but built-in tooling and build steps as well. This would allow reduced duplication of commands and the above functionality could be defined more like this:

services:
  appserver:
    run: -install-everything

tooling:
  install-deps:
    description: Install project dependencies
    cmd:
      - appserver: cd /app/drupal && COMPOSER_PROCESS_TIMEOUT=600 composer install
      - nodejs: yarn install
  install-db:
    description: Download and install project database
    cmd:
    - appserver: /app/drupal && platform db:dump --gzip --environment=develop --file=db_dump.sql.gz --yes
    - lando: db-import /app/drupal/db_dump.sql.gz
    - appserver: cd /app/drupal && /app/drupal/vendor/bin/drush cache:rebuild
    - appserver: cd /app/drupal && /app/drupal/vendor/bin/drush updatedb --yes
    - appserver: cd /app/drupal && /app/drupal/vendor/bin/drush config:import --yes
    - appserver: cd /app/drupal && /app/drupal/vendor/bin/drush config:import --yes
    - appserver: cd /app/drupal && /app/drupal/vendor/bin/drush cache:rebuild
    - appserver: cd /app/drupal && /app/drupal/vendor/bin/drush user:login

  install-everything:
    description: Download and install project dependencies and database
    cmd:
      - lando: install-deps
      - lando: install-db
pirog commented 4 years ago

I'm not against this feature but i will note that this likely would be very difficult to implement and i personally do not have the bandwidth to do it

RichardDavies commented 4 years ago

+1 on this feature request. I would like to be able to have this feature too.

iainp999 commented 4 years ago

+1 from me too. I have similar situation with regards to repetition.

stale[bot] commented 3 years ago

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.

edurenye commented 3 years ago

This would help a lot to simplify things, also when you have a tool with a long list of commands and one of the commands needs a different user, then you could have another tool with that user and just reference to it.

julien-langlois commented 3 years ago

I agree with what has already been said. I'm currently working on a large Drupal project with several separate databases and Git projects, being able to chain Lando's tooling commands would make my job much easier.

Do we have any idea how to implement this feature?

klonos commented 3 years ago

Yup, we could also use this as a workaround for lando/docs#47.

DuaelFr commented 2 years ago

That would be great! It could work like composer does (https://getcomposer.org/doc/articles/scripts.md#referencing-scripts) I guess. I hope it will be implemented some day. (I have no idea how to help with that though)

LucyTurtle commented 1 year ago

I would like this ability!

pirog commented 1 year ago

moving this ticket to the https://github.com/lando/core-next repo since it will be addressed in Lando 4

AlexSkrypnyk commented 2 weeks ago

@pirog Lando 4 is being in the works for several years, but we could really benefit from this feature in Lando 3.

The use case is quite significant: having a "build" or "full-build" command defined that would use other existing tooling commands so that devs could have a single command to get from "0 to 100".

In other non-lando projects, we are using Ahoy and Task that do allow these things. Lando not having this capability makes people have to use another wrapper (like that Ahoy or Task) around Lando which makes things more complicated than they should be.

Is it possible to develop this and bring it to v3 of Lando if this is a sponsored work?

test-bdd:
    service: appserver
    description: Run BDD tests
    cmd: vendor/bin/behat

  test-unit:
    service: appserver
    description: Run unit tests
    cmd: vendor/bin/phpunit

  test:  <- something like this but without sub-process
    cmd: |
      lando test-unit
      lando test-bdd
reynoldsalec commented 2 weeks ago

@AlexSkrypnyk drop me a line in the Lando Slack (https://www.launchpass.com/devwithlando) or talk to @AaronFeledy on the Drupal Slack (sounds like you've already reached out there).

edurenye commented 1 day ago

Calling tools from events should be part of the fix also since the issue about that https://github.com/lando/lando/issues/751 has been closed as a duplicate of this issue.