Merge pull request #6059 from Pix4D/fly_execute_tags

Fly execute: pass worker tags to input.
This commit is contained in:
Zoe Tian 2020-09-22 09:29:32 -04:00 committed by GitHub
commit 94f6dd2cd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 28 additions and 17 deletions

View File

@ -23,6 +23,7 @@ func (s *Server) CreateArtifact(team db.Team) http.Handler {
workerSpec := worker.WorkerSpec{ workerSpec := worker.WorkerSpec{
TeamID: team.ID(), TeamID: team.ID(),
Platform: r.FormValue("platform"), Platform: r.FormValue("platform"),
Tags: r.Form["tags"],
} }
volumeSpec := worker.VolumeSpec{ volumeSpec := worker.VolumeSpec{

View File

@ -66,6 +66,7 @@ func (command *ExecuteCommand) Execute(args []string) error {
command.InputsFrom, command.InputsFrom,
command.IncludeIgnored, command.IncludeIgnored,
taskConfig.Platform, taskConfig.Platform,
command.Tags,
) )
if err != nil { if err != nil {
return err return err

View File

@ -31,6 +31,7 @@ func DetermineInputs(
inputsFrom flaghelpers.JobFlag, inputsFrom flaghelpers.JobFlag,
includeIgnored bool, includeIgnored bool,
platform string, platform string,
tags []string,
) ([]Input, map[string]string, *atc.ImageResource, atc.VersionedResourceTypes, error) { ) ([]Input, map[string]string, *atc.ImageResource, atc.VersionedResourceTypes, error) {
inputMappings := ConvertInputMappings(userInputMappings) inputMappings := ConvertInputMappings(userInputMappings)
@ -74,7 +75,7 @@ func DetermineInputs(
} }
} }
inputsFromLocal, err := GenerateLocalInputs(fact, team, localInputMappings, includeIgnored, platform) inputsFromLocal, err := GenerateLocalInputs(fact, team, localInputMappings, includeIgnored, platform, tags)
if err != nil { if err != nil {
return nil, nil, nil, nil, err return nil, nil, nil, nil, err
} }
@ -158,6 +159,7 @@ func GenerateLocalInputs(
inputMappings []flaghelpers.InputPairFlag, inputMappings []flaghelpers.InputPairFlag,
includeIgnored bool, includeIgnored bool,
platform string, platform string,
tags []string,
) (map[string]Input, error) { ) (map[string]Input, error) {
inputs := map[string]Input{} inputs := map[string]Input{}
@ -170,7 +172,7 @@ func GenerateLocalInputs(
path := mapping.Path path := mapping.Path
prog.Go("uploading "+name, func(bar *mpb.Bar) error { prog.Go("uploading "+name, func(bar *mpb.Bar) error {
artifact, err := Upload(bar, team, path, includeIgnored, platform) artifact, err := Upload(bar, team, path, includeIgnored, platform, tags)
if err != nil { if err != nil {
return err return err
} }

View File

@ -12,7 +12,7 @@ import (
"github.com/vbauerster/mpb/v4" "github.com/vbauerster/mpb/v4"
) )
func Upload(bar *mpb.Bar, team concourse.Team, path string, includeIgnored bool, platform string) (atc.WorkerArtifact, error) { func Upload(bar *mpb.Bar, team concourse.Team, path string, includeIgnored bool, platform string, tags []string) (atc.WorkerArtifact, error) {
files := getFiles(path, includeIgnored) files := getFiles(path, includeIgnored)
archiveStream, archiveWriter := io.Pipe() archiveStream, archiveWriter := io.Pipe()
@ -21,7 +21,7 @@ func Upload(bar *mpb.Bar, team concourse.Team, path string, includeIgnored bool,
archiveWriter.CloseWithError(tgzfs.Compress(archiveWriter, path, files...)) archiveWriter.CloseWithError(tgzfs.Compress(archiveWriter, path, files...))
}() }()
return team.CreateArtifact(bar.ProxyReader(archiveStream), platform) return team.CreateArtifact(bar.ProxyReader(archiveStream), platform, tags)
} }
func getFiles(dir string, includeIgnored bool) []string { func getFiles(dir string, includeIgnored bool) []string {

View File

@ -11,7 +11,7 @@ import (
"github.com/tedsuo/rata" "github.com/tedsuo/rata"
) )
func (team *team) CreateArtifact(src io.Reader, platform string) (atc.WorkerArtifact, error) { func (team *team) CreateArtifact(src io.Reader, platform string, tags []string) (atc.WorkerArtifact, error) {
var artifact atc.WorkerArtifact var artifact atc.WorkerArtifact
params := rata.Params{ params := rata.Params{
@ -22,7 +22,7 @@ func (team *team) CreateArtifact(src io.Reader, platform string) (atc.WorkerArti
Header: http.Header{"Content-Type": {"application/octet-stream"}}, Header: http.Header{"Content-Type": {"application/octet-stream"}},
RequestName: atc.CreateArtifact, RequestName: atc.CreateArtifact,
Params: params, Params: params,
Query: url.Values{"platform": {platform}}, Query: url.Values{"platform": {platform}, "tags": tags},
Body: src, Body: src,
}, &internal.Response{ }, &internal.Response{
Result: &artifact, Result: &artifact,

View File

@ -27,7 +27,7 @@ var _ = Describe("ArtifactRepository", func() {
}) })
It("errors", func() { It("errors", func() {
_, err := team.CreateArtifact(bytes.NewBufferString("some-contents"), "some-platform") _, err := team.CreateArtifact(bytes.NewBufferString("some-contents"), "some-platform", []string{"some-tags"})
Expect(err).To(HaveOccurred()) Expect(err).To(HaveOccurred())
}) })
}) })
@ -45,7 +45,7 @@ var _ = Describe("ArtifactRepository", func() {
}) })
It("returns json", func() { It("returns json", func() {
artifact, err := team.CreateArtifact(bytes.NewBufferString("some-contents"), "some-platform") artifact, err := team.CreateArtifact(bytes.NewBufferString("some-contents"), "some-platform", []string{"some-tags"})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(artifact.ID).To(Equal(17)) Expect(artifact.ID).To(Equal(17))
}) })

View File

@ -148,11 +148,12 @@ type FakeTeam struct {
result1 int64 result1 int64
result2 error result2 error
} }
CreateArtifactStub func(io.Reader, string) (atc.WorkerArtifact, error) CreateArtifactStub func(io.Reader, string, []string) (atc.WorkerArtifact, error)
createArtifactMutex sync.RWMutex createArtifactMutex sync.RWMutex
createArtifactArgsForCall []struct { createArtifactArgsForCall []struct {
arg1 io.Reader arg1 io.Reader
arg2 string arg2 string
arg3 []string
} }
createArtifactReturns struct { createArtifactReturns struct {
result1 atc.WorkerArtifact result1 atc.WorkerArtifact
@ -1334,17 +1335,23 @@ func (fake *FakeTeam) ClearTaskCacheReturnsOnCall(i int, result1 int64, result2
}{result1, result2} }{result1, result2}
} }
func (fake *FakeTeam) CreateArtifact(arg1 io.Reader, arg2 string) (atc.WorkerArtifact, error) { func (fake *FakeTeam) CreateArtifact(arg1 io.Reader, arg2 string, arg3 []string) (atc.WorkerArtifact, error) {
var arg3Copy []string
if arg3 != nil {
arg3Copy = make([]string, len(arg3))
copy(arg3Copy, arg3)
}
fake.createArtifactMutex.Lock() fake.createArtifactMutex.Lock()
ret, specificReturn := fake.createArtifactReturnsOnCall[len(fake.createArtifactArgsForCall)] ret, specificReturn := fake.createArtifactReturnsOnCall[len(fake.createArtifactArgsForCall)]
fake.createArtifactArgsForCall = append(fake.createArtifactArgsForCall, struct { fake.createArtifactArgsForCall = append(fake.createArtifactArgsForCall, struct {
arg1 io.Reader arg1 io.Reader
arg2 string arg2 string
}{arg1, arg2}) arg3 []string
fake.recordInvocation("CreateArtifact", []interface{}{arg1, arg2}) }{arg1, arg2, arg3Copy})
fake.recordInvocation("CreateArtifact", []interface{}{arg1, arg2, arg3Copy})
fake.createArtifactMutex.Unlock() fake.createArtifactMutex.Unlock()
if fake.CreateArtifactStub != nil { if fake.CreateArtifactStub != nil {
return fake.CreateArtifactStub(arg1, arg2) return fake.CreateArtifactStub(arg1, arg2, arg3)
} }
if specificReturn { if specificReturn {
return ret.result1, ret.result2 return ret.result1, ret.result2
@ -1359,17 +1366,17 @@ func (fake *FakeTeam) CreateArtifactCallCount() int {
return len(fake.createArtifactArgsForCall) return len(fake.createArtifactArgsForCall)
} }
func (fake *FakeTeam) CreateArtifactCalls(stub func(io.Reader, string) (atc.WorkerArtifact, error)) { func (fake *FakeTeam) CreateArtifactCalls(stub func(io.Reader, string, []string) (atc.WorkerArtifact, error)) {
fake.createArtifactMutex.Lock() fake.createArtifactMutex.Lock()
defer fake.createArtifactMutex.Unlock() defer fake.createArtifactMutex.Unlock()
fake.CreateArtifactStub = stub fake.CreateArtifactStub = stub
} }
func (fake *FakeTeam) CreateArtifactArgsForCall(i int) (io.Reader, string) { func (fake *FakeTeam) CreateArtifactArgsForCall(i int) (io.Reader, string, []string) {
fake.createArtifactMutex.RLock() fake.createArtifactMutex.RLock()
defer fake.createArtifactMutex.RUnlock() defer fake.createArtifactMutex.RUnlock()
argsForCall := fake.createArtifactArgsForCall[i] argsForCall := fake.createArtifactArgsForCall[i]
return argsForCall.arg1, argsForCall.arg2 return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3
} }
func (fake *FakeTeam) CreateArtifactReturns(result1 atc.WorkerArtifact, result2 error) { func (fake *FakeTeam) CreateArtifactReturns(result1 atc.WorkerArtifact, result2 error) {

View File

@ -71,7 +71,7 @@ type Team interface {
Builds(page Page) ([]atc.Build, Pagination, error) Builds(page Page) ([]atc.Build, Pagination, error)
OrderingPipelines(pipelineNames []string) error OrderingPipelines(pipelineNames []string) error
CreateArtifact(io.Reader, string) (atc.WorkerArtifact, error) CreateArtifact(io.Reader, string, []string) (atc.WorkerArtifact, error)
GetArtifact(int) (io.ReadCloser, error) GetArtifact(int) (io.ReadCloser, error)
} }