shaal / DrupalPod

Start Drupal contributions with 1 click.
https://shaal.github.io/DrupalPod
MIT License
163 stars 54 forks source link

Simplify running drush, composer and yarn commands #83

Closed shaal closed 2 years ago

shaal commented 2 years ago

The Problem/Issue/Bug

DrupalPod tries keeping custom image as small as possible, so it only includes ddev binary. You can run drush, composer, and yarn commands in ddev, but it creates some friction in the user experience.

How this PR Solves The Problem

This PR makes drush, composer, and yarn commands that can run from host, but will actually run inside ddev container, in the current corresponding directory.

Edit: This PR also adds node, nvm, npx as programs that can be called from host, but run in the container. php script was improved to use ddev exec_d instead of just ddev exec

fixes https://github.com/shaal/DrupalPod/issues/82

Manual Testing Instructions

  1. Open this PR in Gitpod - https://gitpod.io/#https://github.com/shaal/DrupalPod/pull/83
  2. Run composer update
  3. Confirm composer updated packages.
  4. Run drush cr
  5. Confirm drush run as expected, and cache was refreshed.
  6. Change directory - cd web/core
  7. Run yarn install
  8. Confirm yarn is installing core's Node dependencies.

Related Issue Link(s)

Release/Deployment notes

andy-blum commented 2 years ago

Composer and Yarn seem to work well, but Drush doesn't appear to pass in the command, just the call to Drush itself.

gitpod /workspace/DrupalPod (exec-d) $ drush status
Notice: running 'drush status' in ddev
Drush Commandline Tool 11.0.7

Run `drush help [command]` to view command-specific help.  Run `drush topic` to read even more documentation.

 Available commands:                                                                                                                                             
 _global:                                                                                                                                                        
   browse                                         Display a link to a given path or open link in a browser.                                                      
   drupal:directory (dd)                          Return the filesystem path for modules/themes and other key folders.                                           
   generate (gen)                                 Generate boilerplate code for modules/plugins/services etc.                                                    
   help                                           Display usage details for a command.                                                                           
   jn:get                                         Execute a JSONAPI request.                                                                                     
   list                                           List available commands.                                                                                       
   mk:docs                                        Build a Markdown document for each Drush command/generator that is available on a site.                        
   runserver (rs, serve)                          Runs PHP's built-in http server for development.                                                               
   version                                        Show Drush version.                                                                                            
 cache:                                                                                                                                                          
   cache:clear (cc)                               Clear a specific cache, or all Drupal caches.                                                                  
   cache:get (cg)                                 Fetch a cached object and display it.                                                                          
   cache:rebuild (cr, rebuild)                    Rebuild a Drupal 8 site.                                                                                       
   cache:set (cs)                                 Cache an object expressed in JSON or var_export() format.                                                      
   cache:tags (ct)                                Invalidate by cache tags.                                                                                      
 config:                                                                                                                                                         
   config:delete (cdel)                           Delete a configuration key, or a whole object.                                                                 
   config:edit (cedit)                            Open a config file in a text editor. Edits are imported after closing editor.                                  
   config:export (cex)                            Export Drupal configuration to a directory.                                                                    
   config:get (cget)                              Display a config value, or a whole configuration object.                                                       
   config:import (cim)                            Import config from a config directory.                                                                         
   config:pull (cpull)                            Export and transfer config from one environment to another.                                                    
   config:set (cset)                              Save a config value directly. Does not perform a config import.                                                
   config:status (cst)                            Display status of configuration (differences between the filesystem configuration and database configuration). 
 core:                                                                                                                                                           
   core:cron (cron)                               Run all cron hooks in all active modules for specified site.                                                   
   core:edit (conf, config)                       Edit drush.yml, site alias, and Drupal settings.php files.                                                     
   core:requirements (status-report, rq)          Information about things that may be wrong in your Drupal installation.                                        
   core:route (route)                             View information about all routes or one route.                                                                
   core:rsync (rsync)                             Rsync Drupal code or files to/from another server using ssh.                                                   
   core:status (status, st)                       An overview of the environment - Drush and Drupal.                                                             
   core:topic (topic)                             Read detailed documentation on a given topic.                                                                  
 deploy:                                                                                                                                                         
   deploy                                         Run several commands after performing a code deployment.                                                       
   deploy:hook                                    Run pending deploy update hooks.                                                                               
   deploy:hook-status                             Prints information about pending deploy update hooks.                                                          
   deploy:mark-complete                           Mark all deploy hooks as having run.                                                                           
 devel:                                                                                                                                                          
   devel:event (fne, fn-event, event)             List implementations of a given event and optionally edit one.                                                 
   devel:hook (fnh, fn-hook, hook)                List implementations of a given hook and optionally edit one.                                                  
   devel:reinstall (dre)                          Uninstall, and Install modules.                                                                                
   devel:services (devel-container-services, dcs) Get a list of available container services.                                                                    
   devel:token (token)                            List available tokens.                                                                                         
   devel:uuid (uuid)                              Generate a Universally Unique Identifier (UUID).                                                               
 entity:                                                                                                                                                         
   entity:delete (edel)                           Delete content entities.                                                                                       
   entity:save (esav)                             Load and save entities.                                                                                        
 field:                                                                                                                                                          
   field:base-info (fbi)                          List all base fields of an entity type                                                                         
   field:base-override-create (bfoc)              Create a new base field override                                                                               
   field:create (fc)                              Create a new field                                                                                             
   field:delete (fd)                              Delete a field                                                                                                 
   field:info (fi)                                List all configurable fields of an entity bundle                                                               
 image:                                                                                                                                                          
   image:derive (id)                              Create an image derivative.                                                                                    
   image:flush (if)                               Flush all derived images for a given style.                                                                    
 locale:                                                                                                                                                         
   locale:check                                   Checks for available translation updates.                                                                      
   locale:export                                  Exports to a gettext translation file.                                                                         
   locale:import                                  Imports to a gettext translation file.                                                                         
   locale:update                                  Imports the available translation updates.                                                                     
 migrate:                                                                                                                                                        
   migrate:fields-source (mfs)                    List the fields available for mapping in a source.                                                             
   migrate:import (mim)                           Perform one or more migration processes.                                                                       
   migrate:messages (mmsg)                        View any messages associated with a migration.                                                                 
   migrate:reset-status (mrs)                     Reset an active migration's status to idle.                                                                    
   migrate:rollback (mr)                          Rollback one or more migrations.                                                                               
   migrate:status (ms)                            List all migrations with current status.                                                                       
   migrate:stop (mst)                             Stop an active migration operation.                                                                            
 php:                                                                                                                                                            
   php:cli (php, core:cli, core-cli)              Open an interactive shell on a Drupal site.                                                                    
   php:eval (eval, ev)                            Evaluate arbitrary php code after bootstrapping Drupal (if available).                                         
   php:script (scr)                               Run php a script after a full Drupal bootstrap.                                                                
 pm:                                                                                                                                                             
   pm:enable (en)                                 Enable one or more modules.                                                                                    
   pm:list (pml)                                  Show a list of available extensions (modules and themes).                                                      
   pm:security (sec)                              Check Drupal Composer packages for pending security updates.                                                   
   pm:security-php (sec-php)                      Check non-Drupal PHP packages for pending security updates.                                                    
   pm:uninstall (pmu)                             Uninstall one or more modules and their dependent modules.                                                     
 queue:                                                                                                                                                          
   queue:delete                                   Delete all items in a specific queue.                                                                          
   queue:list                                     Returns a list of all defined queues.                                                                          
   queue:run                                      Run a specific queue by name.                                                                                  
 role:                                                                                                                                                           
   role:create (rcrt)                             Create a new role.                                                                                             
   role:delete (rdel)                             Delete a new role.                                                                                             
   role:list (rls)                                Display a list of all roles defined on the system.                                                             
   role:perm:add (rap, role-add-perm)             Grant specified permission(s) to a role.                                                                       
   role:perm:remove (rmp, role-remove-perm)       Remove specified permission(s) from a role.                                                                    
 site:                                                                                                                                                           
   site:alias (sa)                                Show site alias details, or a list of available site aliases.                                                  
   site:alias-convert (sa-convert, sac)           Convert legacy site alias files to the new yml format.                                                         
   site:install (si, sin)                         Install Drupal along with modules/themes/configuration/profile.                                                
   site:set (use)                                 Set a site alias that will persist for the current session.                                                    
   site:ssh (ssh)                                 Connect to a Drupal site's server via SSH, and optionally run a shell command.                                 
 sql:                                                                                                                                                            
   sql:cli (sqlc)                                 Open a SQL command-line interface using Drupal's credentials.                                                  
   sql:connect                                    A string for connecting to the DB.                                                                             
   sql:create                                     Create a database.                                                                                             
   sql:drop                                       Drop all tables in a given database.                                                                           
   sql:dump                                       Exports the Drupal DB as SQL using mysqldump or equivalent.                                                    
   sql:query (sqlq)                               Execute a query against a database.                                                                            
   sql:sanitize (sqlsan)                          Sanitize the database by removing or obfuscating user data.                                                    
   sql:sync                                       Copy DB data from a source site to a target site. Transfers data via rsync.                                    
 state:                                                                                                                                                          
   state:delete (sdel)                            Delete a state entry.                                                                                          
   state:get (sget)                               Display a state value.                                                                                         
   state:set (sset)                               Set a state value.                                                                                             
 theme:                                                                                                                                                          
   theme:enable (then)                            Enable one or more themes.                                                                                     
   theme:uninstall (thun)                         Uninstall theme.                                                                                               
 twig:                                                                                                                                                           
   twig:compile (twigc)                           Compile all Twig template(s).                                                                                  
   twig:unused                                    Find potentially unused Twig templates.                                                                        
 updatedb:                                                                                                                                                       
   updatedb (updb)                                Apply any database updates required (as with running update.php).                                              
   updatedb:status (updbst)                       List any pending database updates.                                                                             
 user:                                                                                                                                                           
   user:block (ublk)                              Block the specified user(s).                                                                                   
   user:cancel (ucan)                             Cancel user account(s) with the specified name(s).                                                             
   user:create (ucrt)                             Create a user account.                                                                                         
   user:information (uinf)                        Print information about the specified user(s).                                                                 
   user:login (uli)                               Display a one time login link for user ID 1, or another user.                                                  
   user:password (upwd)                           Set the password for the user account with the specified name.                                                 
   user:role:add (urol, user-add-role)            Add a role to the specified user accounts.                                                                     
   user:role:remove (urrol, user-remove-role)     Remove a role from the specified user accounts.                                                                
   user:unblock (uublk)                           Unblock the specified user(s).                                                                                 
 views:                                                                                                                                                          
   views:analyze (va)                             Get a list of all Views and analyze warnings.                                                                  
   views:dev (vd)                                 Set several Views settings to more developer-oriented values.                                                  
   views:disable (vdis)                           Disable the specified views.                                                                                   
   views:enable (ven)                             Enable the specified views.                                                                                    
   views:execute (vex)                            Execute a view and show a count of the results, or the rendered HTML.                                          
   views:list (vl)                                Get a list of all views in the system.                                                                         
 watchdog:                                                                                                                                                       
   watchdog:delete (wd-del, wd-delete, wd)        Delete watchdog log records.                                                                                   
   watchdog:list (wd-list)                        Interactively filter the watchdog message listing.                                                             
   watchdog:show (wd-show, ws)                    Show watchdog messages.                                                                                        
   watchdog:show-one (wd-one)                     Show one log record by ID.                                                                                     
   watchdog:tail (wd-tail, wt)                    Tail watchdog messages.
shaal commented 2 years ago

@andy-blum thank you! I just saw that and pushed another commit to fix it.

andy-blum commented 2 years ago

Everything works great now!

The only question I have at this point would be why do we have PHP on the gitpod host? Would it be better to consistently use the resources provided by DDEV?

Screen Shot 2022-04-13 at 2 47 58 PM
shaal commented 2 years ago

@andy-blum

Actually, we don't have php installed on host. This was a similar solution like drush, yarn, composer, which I will now improve using the exec_d ddev command I added.

When you run php, it's a script that runs PHP in container - ddev exec php. The reason I added PHP before, was because VSCode's Intellephense extension requires php binary file to run.

shaal commented 2 years ago

@andy-blum I added node, nvm, npx. Anything else we're missing or this is good to merge?

andy-blum commented 2 years ago

I think those should cover at least 90% of users. Did you need someone to test before merging?