integration: skip rootless if unsupported
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>docker-18.09
parent
97b3652136
commit
a9dcf63f45
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue