From 02a8d4f044609ae9ae0dc828e4cef3c760f67ad9 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Mon, 18 Mar 2019 15:24:33 +0100 Subject: [PATCH] Compute tags in parallel Signed-off-by: David Gageot --- pkg/skaffold/runner/runner.go | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/pkg/skaffold/runner/runner.go b/pkg/skaffold/runner/runner.go index 11d187222b0..962e5c94627 100644 --- a/pkg/skaffold/runner/runner.go +++ b/pkg/skaffold/runner/runner.go @@ -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