totara-docker-dev icon indicating copy to clipboard operation
totara-docker-dev copied to clipboard

Add tphp command

Open scq opened this issue 2 years ago • 1 comments

This PR adds a tphp command for executing commands inside the php container.

Example:

sc ~/c/t/learn> tdb drop
Successfully dropped pgsql14 database learn_17
sc ~/c/t/learn> tdb create
Successfully created pgsql14 database learn_17
sc ~/c/t/learn> tphp install
Using PHP Container: php-8.1
Running Command: php server/admin/cli/install_database.php --adminpass=admin [email protected] --agree-license --shortname=Totara 17 development site --fullname=Totara 17 development site
Totara 17.0+ (Build: 20221108.00) command line installation program
-------------------------------------------------------------------------------
== Setting up database ==
-->System
++ Success ++
-->totara_core
++ Success ++

This makes it a bit more convenient to use the install/cron/purge/etc aliases without needing to tbash in to the container.

scq avatar Dec 21 '22 22:12 scq

I've been using it locally for a while and discovered some issues with handling of args recently, will just convert it to a draft until I fix those

scq avatar Aug 29 '23 01:08 scq

I've been using it locally for a while and discovered some issues with handling of args recently, will just convert it to a draft until I fix those

Hey @scq how far are you away from converting this back to a regular merge request and get it in? Would be a great addition.

derschatta avatar Aug 19 '24 05:08 derschatta

@derschatta I still need to solve the issue with passing arguments -- it will fail if it gets passed arguments that are too complex. I'll try and take a look at this again to get that working :D

scq avatar Aug 19 '24 05:08 scq

Fixed the issues. Bash is currently broken though, so it needs #282 first.

Things you can do:

  • tphp -- start your preferred shell in the php container (make sure to set INTERACTIVE_SHELL in .env)
  • tphp ls -- run arbitrary commands in the php container
  • tphp install -- run sh aliases
  • tphp dev/approval/simple/create_demo.php -- run php scripts
  • tphp server/admin/tool/task/cli/schedule_task.php --execute='\tool_diagnostic\task\delete_diagnostic_files_task' -- run complex commands

It autodetects if the first argument ends in .php and adds php on to the beginning, because I found that I kept leaving it off (and tphp php ... looks a little weird)

scq avatar Aug 19 '24 06:08 scq

Changed INTERACTIVE_SHELL default to zsh, seems like hardly anybody is using bash given #282

scq avatar Aug 19 '24 22:08 scq

There must be something specific needed for MacOS as I get:

/Users/username/folder/totara/docker/bin/tphp: line 13: ${i@Q}: bad substitution

when I try to use the command.

derschatta avatar Aug 20 '24 01:08 derschatta

Oh weird. I think Apple ships an ancient bash version that doesn't seem to support that parameter expansion syntax, will see if I can find another way to do it (the @Q is needed to quote the parameter).

scq avatar Aug 20 '24 04:08 scq

@derschatta okay, that should be fixed now

scq avatar Aug 22 '24 23:08 scq