drunomics / phapp-cli

Standardized console commands for managing PHP applications.
MIT License
7 stars 3 forks source link

Complete the phapp exec command allow customization via the manifest #28

Open fago opened 6 years ago

fago commented 6 years ago

The command allows wrapping /bin/bash per project to selectively running commands in containers

It should be included in regular output, like others. e.g.

source dotenv/load.sh
./scripts/util/exec.sh - <<SCRIPT
> echo Working dir: && pwd
> SCRIPT

Usage examples:

Without any argument, it should default to /bin/bash - thus open a new shell.

Executing manifest commands needs to be reworked, so that the API function includes the exec wrapper always.

However, we do not want to run the exec wrapper for "build" by default. But that should be configurable per project. To achieve that, we provide the name of the command to be executed in the variable "PHAPP_COMMAND". This new variable should be provided to all commands and be documented in the README as "A variable that is set to the name of the command executed if some command script of the phapp manifest is currently executed."

Then in the project templates, we control the exec command via dotenv variables: COMMAND_EXEC_PREFIX: "docker compose exec web"

and apply them conditionally in the manifest:

setup: ...
exec:
  # Default to running build commands on the host.
  if  $PHAPP_COMMAND = 'build' ; then 
    COMMAND_EXEC_PREFIX=''
  fi
  $COMMAND_EXEC_PREFIX $@
fago commented 3 years ago

I think the better way to handle this to allow re-using existing phapp commands and simple add "phapp exec" as new command. Then other commands that want to use phapp can simple do

$phapp exec

in order to switch context as needed. The exec script helper can itself be clever enough to only switch into the container when needed then.