From 74813d0e52e99f684a4103972e4fd934883ffd88 Mon Sep 17 00:00:00 2001 From: W-Mark Kubacki Date: Sun, 5 Mar 2017 18:50:16 +0100 Subject: [PATCH] builder: try own copy of tar if the one on the path fails Enables dgr to work on hosts that don't have any tar. (See also #217.) --- aci-builder/bin-run/builder.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/aci-builder/bin-run/builder.go b/aci-builder/bin-run/builder.go index 1a549473..68749d84 100644 --- a/aci-builder/bin-run/builder.go +++ b/aci-builder/bin-run/builder.go @@ -164,8 +164,22 @@ func (b *Builder) tarAci() error { logs.WithF(b.fields).Debug("Calling tar to collect all files") if err := common.ExecCmd("tar", params...); err != nil { - logs.WithFields(b.fields).WithField("params", params).Error("Parameters to 'tar' within the builder") - return errs.WithEF(err, b.fields, "Failed to tar aci") + // In case the host's tar is too old, try the builder's if it exists. + stage1Tar := rktcommon.Stage1RootfsPath(b.pod.Root) + var buildersTar string + for _, t := range []string{"/dgr/usr/bin/tar", "/bin/tar", "/usr/bin/tar"} { + buildersTar = filepath.Join(stage1Tar, t) + if _, err := os.Stat(buildersTar); err == nil { + break + } + } + + if err2 := common.ExecCmd(buildersTar, params...); err2 != nil { + // If that failed, output the original error nevertheless. + logs.WithFields(b.fields).WithField("params", params).Error("Parameters to 'tar' within the builder") + return errs.WithEF(err, b.fields, "Failed to tar aci") + } + logs.WithF(b.fields).Debug("Had to resort to 'tar' from the builder to create the aci file") } // common.ExecCmd sometimes silently fails, hence the redundant check. if _, err := os.Stat(destination); os.IsNotExist(err) {