feat(fly): add `background` option to `execute` command

Signed-off-by: Jonathan Giroux <giroux.jo@gmail.com>
This commit is contained in:
Jonathan Giroux 2023-11-21 13:00:45 +01:00
parent a5e79ffa13
commit 6da6b104a0
No known key found for this signature in database
GPG Key ID: 8D0FBD94F9E534EC
2 changed files with 15 additions and 0 deletions

View File

@ -24,6 +24,7 @@ import (
)
type ExecuteCommand struct {
Background bool `short:"b" long:"background" description:"Create the build and exit, i.e. neither watch logs nor retrieve outputs."`
TaskConfig atc.PathFlag `short:"c" long:"config" required:"true" description:"The task config to execute"`
Privileged bool `short:"p" long:"privileged" description:"Run the task with full privileges"`
IncludeIgnored bool ` long:"include-ignored" description:"Including .gitignored paths. Disregards .gitignore entries and uploads everything"`
@ -85,6 +86,10 @@ func (command *ExecuteCommand) Execute(args []string) error {
return err
}
if len(outputs) > 0 && command.Background {
return fmt.Errorf("background execution cannot withstand outputs")
}
plan, err := executehelpers.CreateBuildPlan(
planFactory,
target,
@ -129,6 +134,11 @@ func (command *ExecuteCommand) Execute(args []string) error {
fmt.Printf("executing build %d at %s\n", build.ID, clientURL.ResolveReference(buildURL))
if command.Background {
os.Exit(0)
return nil
}
terminate := make(chan os.Signal, 1)
go abortOnSignal(client, terminate, build)

View File

@ -80,6 +80,11 @@ run:
Expect(execS).To(gbytes.Say("ARGS are SOME ARGS"))
})
It("works in background", func() {
execS := flyIn(tmp, "execute", "-c", "task.yml", "-i", "fixture=./fixture", "-i", "input-1=./input-1", "-i", "input-2=./input-2", "--background", "--", "SOME", "ARGS",)
Eventually(execS).Should(gbytes.Say("executing build"))
})
Describe("hijacking", func() {
It("executes an interactive command in a running task's container", func() {
err := os.WriteFile(