func (command *ExecuteCommand) Execute(args []string) error { connection, err := rc.TargetConnection(Fly.Target) if err != nil { log.Fatalln(err) return nil } client := concourse.NewClient(connection) taskConfigFile := command.TaskConfig excludeIgnored := command.ExcludeIgnored atcRequester := deprecated.NewAtcRequester(connection.URL(), connection.HTTPClient()) taskConfig := config.LoadTaskConfig(string(taskConfigFile), args) inputs, err := executehelpers.DetermineInputs( client, taskConfig.Inputs, command.Inputs, command.InputsFrom, ) if err != nil { return err } outputs, err := executehelpers.DetermineOutputs( client, taskConfig.Outputs, command.Outputs, ) if err != nil { return err } build, err := executehelpers.CreateBuild( atcRequester, client, command.Privileged, inputs, outputs, taskConfig, command.Tags, Fly.Target, ) if err != nil { return err } fmt.Println("executing build", build.ID) terminate := make(chan os.Signal, 1) go abortOnSignal(client, terminate, build) signal.Notify(terminate, syscall.SIGINT, syscall.SIGTERM) inputChan := make(chan interface{}) go func() { for _, i := range inputs { if i.Path != "" { executehelpers.Upload(i, excludeIgnored, atcRequester) } } close(inputChan) }() var outputChans []chan (interface{}) if len(outputs) > 0 { for i, output := range outputs { outputChans = append(outputChans, make(chan interface{}, 1)) go func(o executehelpers.Output, outputChan chan<- interface{}) { if o.Path != "" { executehelpers.Download(o, atcRequester) } close(outputChan) }(output, outputChans[i]) } } eventSource, err := client.BuildEvents(fmt.Sprintf("%d", build.ID)) if err != nil { log.Println("failed to attach to stream:", err) os.Exit(1) } exitCode := eventstream.Render(os.Stdout, eventSource) eventSource.Close() <-inputChan if len(outputs) > 0 { for _, outputChan := range outputChans { <-outputChan } } os.Exit(exitCode) return nil }
"github.com/concourse/atc" "github.com/concourse/fly/commands/internal/deprecated" . "github.com/concourse/fly/commands/internal/executehelpers" "github.com/concourse/go-concourse/concourse/fakes" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("Builds", func() { var requester *deprecated.AtcRequester var fakeClient *fakes.FakeClient var config atc.TaskConfig BeforeEach(func() { requester = deprecated.NewAtcRequester("foo", &http.Client{}) fakeClient = new(fakes.FakeClient) config = atc.TaskConfig{ Platform: "shoes", Run: atc.TaskRunConfig{ Path: "./here", Args: []string{}, }, } }) Context("when tags are provided", func() { It("add the tags to the plan", func() { tags := []string{"tag", "tag2"} _, err := CreateBuild(requester, fakeClient, false, []Input{}, []Output{}, config, tags, "https://target.com")