fix: Log kaniko errors that happen during the tar phase
@@ -102,12 +102,14 @@ func (b *Builder) copyKanikoBuildContext(ctx context.Context, workspace string,
return fmt.Errorf("waiting for pod to initialize: %w", err)
}
+ errs := make(chan error, 1)
buildCtx, buildCtxWriter := io.Pipe()
go func() {
err := docker.CreateDockerTarContext(ctx, buildCtxWriter, docker.NewBuildConfig(
workspace, artifactName, artifact.DockerfilePath, artifact.BuildArgs), b.cfg)
if err != nil {
buildCtxWriter.CloseWithError(fmt.Errorf("creating docker context: %w", err))
+ errs <- err
return
}
buildCtxWriter.Close()
@@ -117,7 +119,12 @@ func (b *Builder) copyKanikoBuildContext(ctx context.Context, workspace string,
// In case of an error, print the command's output. (The `err` itself is useless: exit status 1).
var out bytes.Buffer
if err := b.kubectlcli.Run(ctx, buildCtx, &out, "exec", "-i", podName, "-c", initContainer, "-n", b.Namespace, "--", "tar", "-xf", "-", "-C", kaniko.DefaultEmptyDirMountPath); err != nil {
- return fmt.Errorf("uploading build context: %s", out.String())
+ errRun := fmt.Errorf("uploading build context: %s", out.String())
+ errTar := <-errs
+ if errTar != nil {
+ errRun = fmt.Errorf("%v\ntar errors: %w", errRun, errTar)
+ }
+ return errRun
}
// Generate a file to successfully terminate the init container.
