Skip to content

Commit

Permalink
Merge pull request #8856 from KoltesDigital/master
Browse files Browse the repository at this point in the history
`fly`: add `background` option to `execute` command
  • Loading branch information
taylorsilva committed Apr 2, 2024
2 parents 313c177 + 6da6b10 commit 2a7bb08
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions fly/commands/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions testflight/flying_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 2a7bb08

Please sign in to comment.