From a9dcf63f453651afc6db89a7f8cb8cc7d450606c Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Fri, 20 Jul 2018 19:18:51 +0900 Subject: [PATCH] integration: skip rootless if unsupported Signed-off-by: Akihiro Suda --- util/testutil/integration/oci.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/util/testutil/integration/oci.go b/util/testutil/integration/oci.go index 34604911..03fdb181 100644 --- a/util/testutil/integration/oci.go +++ b/util/testutil/integration/oci.go @@ -14,6 +14,7 @@ import ( "github.com/google/shlex" "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) func init() { @@ -23,9 +24,11 @@ func init() { if s := os.Getenv("BUILDKIT_INTEGRATION_ROOTLESS_IDPAIR"); s != "" { var uid, gid int if _, err := fmt.Sscanf(s, "%d:%d", &uid, &gid); err != nil { - panic(errors.Errorf("unexpected BUILDKIT_INTEGRATION_ROOTLESS_IDPAIR: %q", s)) + logrus.Fatalf("unexpected BUILDKIT_INTEGRATION_ROOTLESS_IDPAIR: %q", s) + } + if rootlessSupported(uid) { + register(&oci{uid: uid, gid: gid}) } - register(&oci{uid: uid, gid: gid}) } } @@ -155,3 +158,13 @@ func runBuildkitd(args []string, logs map[string]*bytes.Buffer, uid, gid int) (a return } + +func rootlessSupported(uid int) bool { + cmd := exec.Command("sudo", "-u", fmt.Sprintf("#%d", uid), "-i", "--", "unshare", "-U", "true") + b, err := cmd.CombinedOutput() + if err != nil { + logrus.Warnf("rootless mode is not supported on this host: %v (%s)", err, string(b)) + return false + } + return true +}