From 6da6b104a00e6b219077a195a3036f00682e6eb2 Mon Sep 17 00:00:00 2001 From: Jonathan Giroux Date: Tue, 21 Nov 2023 13:00:45 +0100 Subject: [PATCH] feat(fly): add `background` option to `execute` command Signed-off-by: Jonathan Giroux --- fly/commands/execute.go | 10 ++++++++++ testflight/flying_test.go | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/fly/commands/execute.go b/fly/commands/execute.go index ca0bbe4387f..1b9add2f54b 100644 --- a/fly/commands/execute.go +++ b/fly/commands/execute.go @@ -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) diff --git a/testflight/flying_test.go b/testflight/flying_test.go index c3b01bd1db9..7f730800b70 100644 --- a/testflight/flying_test.go +++ b/testflight/flying_test.go @@ -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(