benchkram / bob

Bob is a high-level build tool for multi-language projects.
https://bob.build
Apache License 2.0
466 stars 14 forks source link

`bob run` pre+post scripts #32

Open Equanox opened 2 years ago

puengel commented 2 years ago

Run Workflow

Assumption

Pre can be handled by dependencies. --> No need for further implementation.

Post is meant to be done after a Task has finished. Since our run tasks are meant to stay alive it doesn't make sense to do anything after stopping this task.

Init is meant to run as soon as the run task is in a running state (e.g. docker-compose up has all containers in running|healthy state). This is what is meant to be implemented with this ticket.

Leads to following run workflow:

flowchart TD
  A[$:bob run environment] --> B{Has dependencies?};
  B -- Yes --> C[Build dependencies!];
  B -- No --> D[Start Runtask environment!];
  C ----> D[Start Runtask environment!];
  D --> E{Is running?};
  E -- No --> F[Wait];
  F --> E;
  E -- Yes --> G{Has Init Task?};
  G -- No --> H[Done. Wait for SigStop.];
  G -- Yes --> I[Run Init Task!];
  I --> H;
rdnt commented 2 years ago

A usecase for a post script could be to clean up some files that could have been generated during the run time of an interactive task, e.g. logfiles.

Equanox commented 2 years ago

I agree for our current use case init is the behavior we want and it makes sense to ommit Pre/Post for now .

Executing Init This seems to be a good place https://github.com/benchkram/bob/blob/main/pkg/ctl/commander.go#L16 to trigger the init script run. binary&compose start procedure is over at this point in time. Control is given to the TUI to assure output is correctly streamed to the user.

Working together with the TUI

From a implementation standpoint it seems to be required that init must fullfill the Control interface https://github.com/benchkram/bob/blob/main/pkg/ctl/commander.go#L164 to receive the stop/cancel cmd from the TUI correctly. Though it requires us to reuse the shell from the build tasks... the implementation could be relatively easy as restart is not required and the shell can handle a canceable context, see https://github.com/benchkram/bob/blob/main/bobtask/run.go

Run task A run-task with init looks like this?

run:
  server:
    type: binary
    path: ./build/server
    init: |-
      ./run-database-init.sh

In the case of init: being used on multiple levels in a pipeline the init cmd's should only be executed when the umbrella task triggers. Could make signal handling much easier.

Out of scope: We made the experience that often script can only be executed after preconditions are fulfilled like a /health route returning 200. Same for database ram pup as it takes a while till a database is functional when started detached. Tough i would leave those kind of preconditions checks to the script called with init.

Equanox commented 2 years ago

Pre scripts closed by #84