Skip to content

Commit

Permalink
Merge pull request #475 from dgageot/fix-416
Browse files Browse the repository at this point in the history
Improve docker load output in bazel build
  • Loading branch information
r2d4 authored Apr 27, 2018
2 parents 2ed4b03 + bbbde9f commit 182a36c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 5 additions & 3 deletions pkg/skaffold/build/bazel.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1alpha2"
"github.com/pkg/errors"
)
Expand All @@ -43,21 +43,23 @@ func (l *LocalBuilder) buildBazel(ctx context.Context, out io.Writer, a *v1alpha
tarPath := strings.TrimPrefix(a.BazelArtifact.BuildTarget, "//:")
//TODO(r2d4): strip off trailing .tar, even worse
imageTag := strings.TrimSuffix(tarPath, ".tar")

imageTar, err := os.Open(filepath.Join(a.Workspace, "bazel-bin", tarPath))
if err != nil {
return "", errors.Wrap(err, "opening image tarball")
}
defer imageTar.Close()

resp, err := l.api.ImageLoad(ctx, imageTar, false)
if err != nil {
return "", errors.Wrap(err, "loading image into docker daemon")
}
defer resp.Body.Close()
respStr, err := ioutil.ReadAll(resp.Body)

err = docker.StreamDockerMessages(out, resp.Body)
if err != nil {
return "", errors.Wrap(err, "reading from image load response")
}
out.Write(respStr)

return fmt.Sprintf("bazel:%s", imageTag), nil
}
6 changes: 3 additions & 3 deletions pkg/skaffold/docker/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ func RunBuild(ctx context.Context, cli DockerAPIClient, opts *BuildOptions) erro
return errors.Wrap(err, "docker build")
}
defer resp.Body.Close()
return streamDockerMessages(opts.BuildBuf, resp.Body)
return StreamDockerMessages(opts.BuildBuf, resp.Body)
}

// TODO(@r2d4): Make this output much better, this is the bare minimum
func streamDockerMessages(dst io.Writer, src io.Reader) error {
func StreamDockerMessages(dst io.Writer, src io.Reader) error {
fd, _ := term.GetFdInfo(dst)
return jsonmessage.DisplayJSONMessagesStream(src, dst, fd, false, nil)
}
Expand All @@ -99,7 +99,7 @@ func RunPush(ctx context.Context, cli DockerAPIClient, ref string, out io.Writer
return errors.Wrap(err, "pushing image to repository")
}
defer rc.Close()
return streamDockerMessages(out, rc)
return StreamDockerMessages(out, rc)
}

func AddTag(src, target string) error {
Expand Down

0 comments on commit 182a36c

Please sign in to comment.