2017-11-27 22:24:29 +00:00
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
2018-07-04 09:18:00 +00:00
|
|
|
"fmt"
|
2019-07-12 17:22:25 +00:00
|
|
|
"log"
|
2017-11-27 22:24:29 +00:00
|
|
|
"os"
|
2017-11-30 22:50:03 +00:00
|
|
|
|
2018-07-04 09:18:00 +00:00
|
|
|
"github.com/pkg/errors"
|
2018-07-20 10:18:51 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2017-11-27 22:24:29 +00:00
|
|
|
)
|
|
|
|
|
2019-03-22 06:49:08 +00:00
|
|
|
func InitOCIWorker() {
|
|
|
|
Register(&oci{})
|
2018-07-04 09:18:00 +00:00
|
|
|
|
2019-10-18 07:36:14 +00:00
|
|
|
// the rootless uid is defined in Dockerfile
|
2018-07-04 09:18:00 +00:00
|
|
|
if s := os.Getenv("BUILDKIT_INTEGRATION_ROOTLESS_IDPAIR"); s != "" {
|
|
|
|
var uid, gid int
|
|
|
|
if _, err := fmt.Sscanf(s, "%d:%d", &uid, &gid); err != nil {
|
2018-07-20 10:18:51 +00:00
|
|
|
logrus.Fatalf("unexpected BUILDKIT_INTEGRATION_ROOTLESS_IDPAIR: %q", s)
|
|
|
|
}
|
|
|
|
if rootlessSupported(uid) {
|
2019-03-22 06:49:08 +00:00
|
|
|
Register(&oci{uid: uid, gid: gid})
|
2018-07-04 09:18:00 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-11 00:08:07 +00:00
|
|
|
|
2020-09-03 05:40:57 +00:00
|
|
|
if s := os.Getenv("BUILDKIT_INTEGRATION_SNAPSHOTTER"); s != "" {
|
|
|
|
Register(&oci{snapshotter: s})
|
|
|
|
}
|
2017-11-27 22:24:29 +00:00
|
|
|
}
|
|
|
|
|
2017-12-15 07:00:13 +00:00
|
|
|
type oci struct {
|
2020-09-03 05:40:57 +00:00
|
|
|
uid int
|
|
|
|
gid int
|
|
|
|
snapshotter string
|
2017-11-27 22:24:29 +00:00
|
|
|
}
|
|
|
|
|
2017-12-15 07:00:13 +00:00
|
|
|
func (s *oci) Name() string {
|
2018-07-04 09:18:00 +00:00
|
|
|
if s.uid != 0 {
|
|
|
|
return "oci-rootless"
|
|
|
|
}
|
2020-09-03 05:40:57 +00:00
|
|
|
if s.snapshotter != "" {
|
|
|
|
return fmt.Sprintf("oci-snapshotter-%s", s.snapshotter)
|
|
|
|
}
|
2017-12-15 07:00:13 +00:00
|
|
|
return "oci"
|
2017-11-27 22:24:29 +00:00
|
|
|
}
|
|
|
|
|
2019-08-23 21:21:34 +00:00
|
|
|
func (s *oci) New(cfg *BackendConfig) (Backend, func() error, error) {
|
2017-12-18 07:33:02 +00:00
|
|
|
if err := lookupBinary("buildkitd"); err != nil {
|
2017-11-27 22:24:29 +00:00
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
if err := requireRoot(); err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
Initialise workers' label maps before assigning.
Otherwise:
panic: assignment to entry in nil map
goroutine 1 [running]:
main.applyOCIFlags(0xc4200e71e0, 0xc420400000, 0x0, 0x0)
/go/src/github.com/moby/buildkit/cmd/buildkitd/main_oci_worker.go:97 +0x1ac
main.ociWorkerInitializer(0xc4200e71e0, 0xc4204104e0, 0xc420400000, 0x43409b, 0x12, 0xc42026b0f8, 0x4337fc, 0xc420000180)
/go/src/github.com/moby/buildkit/cmd/buildkitd/main_oci_worker.go:118 +0x50
main.newWorkerController(0xc4200e71e0, 0xc4204104e0, 0xc420400000, 0xc420422000, 0xe5dc54, 0x11)
/go/src/github.com/moby/buildkit/cmd/buildkitd/main.go:520 +0x324
main.newController(0xc4200e71e0, 0xc420400000, 0x1c0, 0x0, 0x0)
/go/src/github.com/moby/buildkit/cmd/buildkitd/main.go:489 +0xdc
main.main.func3(0xc4200e71e0, 0x0, 0x0)
/go/src/github.com/moby/buildkit/cmd/buildkitd/main.go:203 +0x3dd
github.com/moby/buildkit/vendor/github.com/urfave/cli.HandleAction(0xcdd420, 0xe93e98, 0xc4200e71e0, 0xc4200e71e0, 0xc42026b888)
/go/src/github.com/moby/buildkit/vendor/github.com/urfave/cli/app.go:502 +0xc8
github.com/moby/buildkit/vendor/github.com/urfave/cli.(*App).Run(0xc4201b6540, 0xc4200300a0, 0xa, 0xa, 0x0, 0x0)
/go/src/github.com/moby/buildkit/vendor/github.com/urfave/cli/app.go:268 +0x60c
main.main()
/go/src/github.com/moby/buildkit/cmd/buildkitd/main.go:238 +0xc64
Also add some random labels to the integration sandbox (which I have confirmed
is enough to trigger this issue before the fix).
Signed-off-by: Ian Campbell <ijc@docker.com>
2018-09-03 10:31:03 +00:00
|
|
|
// Include use of --oci-worker-labels to trigger https://github.com/moby/buildkit/pull/603
|
2019-03-11 04:04:50 +00:00
|
|
|
buildkitdArgs := []string{"buildkitd", "--oci-worker=true", "--containerd-worker=false", "--oci-worker-gc=false", "--oci-worker-labels=org.mobyproject.buildkit.worker.sandbox=true"}
|
2018-09-11 00:08:07 +00:00
|
|
|
|
2020-09-03 05:40:57 +00:00
|
|
|
if s.snapshotter != "" {
|
|
|
|
buildkitdArgs = append(buildkitdArgs,
|
|
|
|
fmt.Sprintf("--oci-worker-snapshotter=%s", s.snapshotter))
|
|
|
|
}
|
|
|
|
|
2018-07-04 09:18:00 +00:00
|
|
|
if s.uid != 0 {
|
|
|
|
if s.gid == 0 {
|
|
|
|
return nil, nil, errors.Errorf("unsupported id pair: uid=%d, gid=%d", s.uid, s.gid)
|
|
|
|
}
|
|
|
|
// TODO: make sure the user exists and subuid/subgid are configured.
|
2020-07-18 02:21:50 +00:00
|
|
|
buildkitdArgs = append([]string{"sudo", "-u", fmt.Sprintf("#%d", s.uid), "-i", "--", "exec", "rootlesskit"}, buildkitdArgs...)
|
2018-07-04 09:18:00 +00:00
|
|
|
}
|
2019-08-23 21:21:34 +00:00
|
|
|
|
2021-04-09 06:34:45 +00:00
|
|
|
buildkitdSock, stop, err := runBuildkitd(cfg, buildkitdArgs, cfg.Logs, s.uid, s.gid, nil)
|
2017-11-27 22:24:29 +00:00
|
|
|
if err != nil {
|
2019-08-23 21:21:34 +00:00
|
|
|
printLogs(cfg.Logs, log.Println)
|
2017-11-27 22:24:29 +00:00
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
2019-08-23 21:21:34 +00:00
|
|
|
return backend{
|
2020-09-03 05:40:57 +00:00
|
|
|
address: buildkitdSock,
|
|
|
|
rootless: s.uid != 0,
|
|
|
|
snapshotter: s.snapshotter,
|
2019-08-23 21:21:34 +00:00
|
|
|
}, stop, nil
|
2017-11-27 22:24:29 +00:00
|
|
|
}
|