Merge pull request #524 from AkihiroSuda/skip-rootless-if-unsupported
integration: skip rootless if unsupporteddocker-18.09
commit
962feb48e3
|
@ -14,6 +14,7 @@ import (
|
||||||
|
|
||||||
"github.com/google/shlex"
|
"github.com/google/shlex"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -23,9 +24,11 @@ func init() {
|
||||||
if s := os.Getenv("BUILDKIT_INTEGRATION_ROOTLESS_IDPAIR"); s != "" {
|
if s := os.Getenv("BUILDKIT_INTEGRATION_ROOTLESS_IDPAIR"); s != "" {
|
||||||
var uid, gid int
|
var uid, gid int
|
||||||
if _, err := fmt.Sscanf(s, "%d:%d", &uid, &gid); err != nil {
|
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
|
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