Skip to content

Commit

Permalink
Compute tags in parallel
Browse files Browse the repository at this point in the history
Signed-off-by: David Gageot <[email protected]>
  • Loading branch information
dgageot committed Mar 19, 2019
1 parent 7b1b8fa commit 9f2bceb
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions pkg/skaffold/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,34 +293,53 @@ func (r *SkaffoldRunner) Run(ctx context.Context, out io.Writer, artifacts []*la
return nil
}

type tagErr struct {
tag string
err error
}

// imageTags generates tags for a list of artifacts
func (r *SkaffoldRunner) imageTags(ctx context.Context, out io.Writer, artifacts []*latest.Artifact) (tag.ImageTags, error) {
start := time.Now()
color.Default.Fprintln(out, "Generating tags...")

tags := make(tag.ImageTags, len(artifacts))
tagErrs := make([]chan tagErr, len(artifacts))

for i := range artifacts {
tagErrs[i] = make(chan tagErr, 1)

i := i
go func() {
tag, err := r.Tagger.GenerateFullyQualifiedImageName(artifacts[i].Workspace, artifacts[i].ImageName)
tagErrs[i] <- tagErr{tag: tag, err: err}
}()
}

imageTags := make(tag.ImageTags, len(artifacts))

for i, artifact := range artifacts {
imageName := artifact.ImageName
color.Default.Fprintf(out, " - %s -> ", imageName)

for _, artifact := range artifacts {
select {
case <-ctx.Done():
return nil, context.Canceled
default:
imageName := artifact.ImageName
color.Default.Fprintf(out, " - %s -> ", imageName)

tag, err := r.Tagger.GenerateFullyQualifiedImageName(artifact.Workspace, imageName)
case t := <-tagErrs[i]:
tag := t.tag
err := t.err
if err != nil {
return nil, errors.Wrapf(err, "generating tag for %s", imageName)
}

fmt.Fprintln(out, tag)

tags[imageName] = tag
imageTags[imageName] = tag
}
}

color.Default.Fprintln(out, "Tags generated in", time.Since(start))
return tags, nil
return imageTags, nil
}

// BuildAndTest builds artifacts and runs tests on built artifacts
Expand Down

0 comments on commit 9f2bceb

Please sign in to comment.