Skip to content

Commit d813b2f

Browse files
committed
Allow runner to mount special filesystem in the input root
This introduces a new runner decorator that can create mounts in the input root. This is useful for 'chroot' runners that have userland tools that require '/proc' or '/sys', which are created by the operating system. This is how to configure the runner: inputRootMounts: [{ mountpoint: 'proc', source: '/proc', filesystemType: 'proc', }, { mountpoint: 'sys', source: '/sys', filesystemType: 'sysfs', }],
1 parent 70efb72 commit d813b2f

File tree

8 files changed

+279
-31
lines changed

8 files changed

+279
-31
lines changed

.bazelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
# Required for @com_google_absl and remoteapis that use it.
12
build --host_cxxopt=-std=c++17
23
run --workspace_status_command="bash tools/workspace-status.sh"

cmd/bb_runner/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ func main() {
6868
buildDirectoryPath,
6969
commandCreator,
7070
configuration.SetTmpdirEnvironmentVariable)
71+
for _, mountinfo := range configuration.InputRootMounts {
72+
_ = mountinfo
73+
r = runner.NewMountingRunner(
74+
r,
75+
buildDirectory,
76+
mountinfo,
77+
)
78+
}
7179

7280
// Let bb_runner replace temporary directories with symbolic
7381
// links pointing to the temporary directory set up by

cmd/bb_scheduler/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func main() {
108108
}
109109
killOperationsAuthorizer, err := authorizerFactory.NewAuthorizerFromConfiguration(configuration.KillOperationsAuthorizer)
110110
if err != nil {
111-
return util.StatusWrap(err, "Failed to create kill operaitons authorizer")
111+
return util.StatusWrap(err, "Failed to create kill operations authorizer")
112112
}
113113

114114
platformQueueWithNoWorkersTimeout := configuration.PlatformQueueWithNoWorkersTimeout

pkg/filesystem/lazy_directory.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,21 @@ func (d *lazyDirectory) Apply(arg interface{}) error {
245245
defer underlying.Close()
246246
return underlying.Apply(arg)
247247
}
248+
249+
func (d *lazyDirectory) Mount(mountpoint path.Component, source string, fstype string) error {
250+
underlying, err := d.openUnderlying()
251+
if err != nil {
252+
return err
253+
}
254+
defer underlying.Close()
255+
return underlying.Mount(mountpoint, source, fstype)
256+
}
257+
258+
func (d *lazyDirectory) Unmount(mountpoint path.Component) error {
259+
underlying, err := d.openUnderlying()
260+
if err != nil {
261+
return err
262+
}
263+
defer underlying.Close()
264+
return underlying.Unmount(mountpoint)
265+
}

pkg/proto/configuration/bb_runner/bb_runner.pb.go

Lines changed: 128 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/proto/configuration/bb_runner/bb_runner.proto

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,23 @@ message ApplicationConfiguration {
131131
// https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/exec/local/XcodeLocalEnvProvider.java
132132
// https://www.smileykeith.com/2021/03/08/locking-xcode-in-bazel/
133133
map<string, string> apple_xcode_developer_directories = 14;
134+
135+
// Mount special filesystems in the input root.
136+
// This is useful when running with `chroot`.
137+
// some tools require access to special filesystems
138+
// that are created when the operating system boots.
139+
// An input root with a full userland implementation may need these.
140+
// Typical choices are:
141+
// {"proc", "/proc", "proc"}
142+
// {"sys", "/sys", "sysfs"}
143+
repeated mount_info input_root_mounts = 15;
144+
}
145+
146+
message mount_info {
147+
// Mount a filesystem in the input root, a relative path.
148+
string mountpoint = 1;
149+
// Source filesystem from the runner's operating system, absolute path.
150+
string source = 2;
151+
// Type of filesystem, see `mount`'s man page.
152+
string filesystem_type = 3;
134153
}

pkg/runner/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ go_library(
1111
"local_runner_rss_kibibytes.go",
1212
"local_runner_unix.go",
1313
"local_runner_windows.go",
14+
"mounting_runner.go",
1415
"path_existence_checking_runner.go",
1516
"temporary_directory_installing_runner.go",
1617
"temporary_directory_symlinking_runner.go",
@@ -19,6 +20,7 @@ go_library(
1920
visibility = ["//visibility:public"],
2021
deps = [
2122
"//pkg/cleaner",
23+
"//pkg/proto/configuration/bb_runner",
2224
"//pkg/proto/runner",
2325
"//pkg/proto/tmp_installer",
2426
"@com_github_buildbarn_bb_storage//pkg/filesystem",

0 commit comments

Comments
 (0)