microsandbox-rb 0.5.8 → 0.5.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +125 -0
- data/Cargo.lock +90 -45
- data/DESIGN.md +32 -19
- data/README.md +108 -36
- data/ext/microsandbox/Cargo.toml +4 -4
- data/ext/microsandbox/extconf.rb +6 -2
- data/ext/microsandbox/src/agent.rs +166 -0
- data/ext/microsandbox/src/backend.rs +170 -0
- data/ext/microsandbox/src/conv.rs +19 -1
- data/ext/microsandbox/src/error.rs +6 -0
- data/ext/microsandbox/src/image.rs +7 -7
- data/ext/microsandbox/src/lib.rs +31 -4
- data/ext/microsandbox/src/sandbox.rs +666 -61
- data/ext/microsandbox/src/ssh.rs +317 -0
- data/ext/microsandbox/src/volume.rs +6 -1
- data/lib/microsandbox/agent.rb +181 -0
- data/lib/microsandbox/errors.rb +6 -0
- data/lib/microsandbox/exec_handle.rb +14 -11
- data/lib/microsandbox/fs.rb +7 -7
- data/lib/microsandbox/image.rb +1 -1
- data/lib/microsandbox/network.rb +300 -0
- data/lib/microsandbox/patch.rb +98 -0
- data/lib/microsandbox/sandbox.rb +285 -77
- data/lib/microsandbox/snapshot.rb +2 -2
- data/lib/microsandbox/ssh.rb +247 -0
- data/lib/microsandbox/version.rb +2 -2
- data/lib/microsandbox/volume.rb +3 -3
- data/lib/microsandbox.rb +65 -0
- data/sig/microsandbox.rbs +164 -14
- metadata +8 -1
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
use magnus::{function, prelude::*, Error, RArray, RHash, RModule, Ruby};
|
|
9
9
|
use microsandbox::image::{Image, ImageDetail, ImageHandle, ImagePruneReport};
|
|
10
10
|
|
|
11
|
-
use crate::
|
|
12
|
-
use crate::runtime::
|
|
11
|
+
use crate::backend::with_local_backend;
|
|
12
|
+
use crate::runtime::ruby;
|
|
13
13
|
|
|
14
14
|
fn handle_to_hash(h: &ImageHandle) -> RHash {
|
|
15
15
|
let hash = ruby().hash_new();
|
|
@@ -76,12 +76,12 @@ fn report_to_hash(report: ImagePruneReport) -> RHash {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
fn get(reference: String) -> Result<RHash, Error> {
|
|
79
|
-
let handle =
|
|
79
|
+
let handle = with_local_backend(async |local| Image::get(local, &reference).await)?;
|
|
80
80
|
Ok(handle_to_hash(&handle))
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
fn list() -> Result<RArray, Error> {
|
|
84
|
-
let handles =
|
|
84
|
+
let handles = with_local_backend(async |local| Image::list(local).await)?;
|
|
85
85
|
let arr = ruby().ary_new();
|
|
86
86
|
for h in handles.iter() {
|
|
87
87
|
arr.push(handle_to_hash(h))?;
|
|
@@ -90,16 +90,16 @@ fn list() -> Result<RArray, Error> {
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
fn inspect(reference: String) -> Result<RHash, Error> {
|
|
93
|
-
let detail =
|
|
93
|
+
let detail = with_local_backend(async |local| Image::inspect(local, &reference).await)?;
|
|
94
94
|
Ok(detail_to_hash(detail))
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
fn remove(reference: String, force: bool) -> Result<(), Error> {
|
|
98
|
-
|
|
98
|
+
with_local_backend(async |local| Image::remove(local, &reference, force).await)
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
fn prune() -> Result<RHash, Error> {
|
|
102
|
-
let report =
|
|
102
|
+
let report = with_local_backend(async |local| Image::prune(local).await)?;
|
|
103
103
|
Ok(report_to_hash(report))
|
|
104
104
|
}
|
|
105
105
|
|
data/ext/microsandbox/src/lib.rs
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
//! Everything here lives under `Microsandbox::Native`; the ergonomic, idiomatic
|
|
9
9
|
//! surface is the pure-Ruby layer in `lib/microsandbox/`.
|
|
10
10
|
|
|
11
|
+
mod agent;
|
|
12
|
+
mod backend;
|
|
11
13
|
mod conv;
|
|
12
14
|
mod error;
|
|
13
15
|
mod exec;
|
|
@@ -15,6 +17,7 @@ mod image;
|
|
|
15
17
|
mod runtime;
|
|
16
18
|
mod sandbox;
|
|
17
19
|
mod snapshot;
|
|
20
|
+
mod ssh;
|
|
18
21
|
mod stream;
|
|
19
22
|
mod volume;
|
|
20
23
|
|
|
@@ -29,8 +32,9 @@ fn version() -> String {
|
|
|
29
32
|
/// Ruby Hash. Mirrors the official `all_sandbox_metrics` / `allSandboxMetrics`
|
|
30
33
|
/// helpers (Python/Node/Go).
|
|
31
34
|
fn all_sandbox_metrics() -> Result<RHash, Error> {
|
|
32
|
-
let map =
|
|
33
|
-
|
|
35
|
+
let map = backend::with_local_backend(async |local| {
|
|
36
|
+
microsandbox::sandbox::all_sandbox_metrics(local).await
|
|
37
|
+
})?;
|
|
34
38
|
let hash = runtime::ruby().hash_new();
|
|
35
39
|
for (name, metrics) in &map {
|
|
36
40
|
hash.aset(name.as_str(), sandbox::metrics_to_hash(metrics))?;
|
|
@@ -53,9 +57,25 @@ fn set_runtime_msb_path(path: String) {
|
|
|
53
57
|
microsandbox::config::set_sdk_msb_path(path);
|
|
54
58
|
}
|
|
55
59
|
|
|
56
|
-
///
|
|
60
|
+
/// Override the resolved `libkrunfw` path (SDK tier of the resolver). Set-once
|
|
61
|
+
/// per process; the `MSB_LIBKRUNFW_PATH` env var still takes precedence. Mirrors
|
|
62
|
+
/// `set_runtime_msb_path` for the libkrunfw shared library.
|
|
63
|
+
fn set_runtime_libkrunfw_path(path: String) {
|
|
64
|
+
microsandbox::config::set_sdk_libkrunfw_path(path);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/// The currently-resolved `msb` runtime path. Synchronous (filesystem probes,
|
|
68
|
+
/// no async) — runs on the Ruby thread; resolves the path from the local
|
|
69
|
+
/// backend's config.
|
|
57
70
|
fn resolved_msb_path() -> Result<String, Error> {
|
|
58
|
-
let
|
|
71
|
+
let backend = microsandbox::default_backend();
|
|
72
|
+
let local = backend.as_local().ok_or_else(|| {
|
|
73
|
+
error::to_ruby(microsandbox::MicrosandboxError::Unsupported {
|
|
74
|
+
feature: "resolved_msb_path requires a local backend".into(),
|
|
75
|
+
available_when: "with the local backend".into(),
|
|
76
|
+
})
|
|
77
|
+
})?;
|
|
78
|
+
let path = microsandbox::config::resolve_msb_path(local.config()).map_err(error::to_ruby)?;
|
|
59
79
|
Ok(path.to_string_lossy().into_owned())
|
|
60
80
|
}
|
|
61
81
|
|
|
@@ -70,15 +90,22 @@ fn init(ruby: &Ruby) -> Result<(), Error> {
|
|
|
70
90
|
native.define_singleton_method("install", function!(install, 0))?;
|
|
71
91
|
native.define_singleton_method("installed?", function!(is_installed, 0))?;
|
|
72
92
|
native.define_singleton_method("set_runtime_msb_path", function!(set_runtime_msb_path, 1))?;
|
|
93
|
+
native.define_singleton_method(
|
|
94
|
+
"set_runtime_libkrunfw_path",
|
|
95
|
+
function!(set_runtime_libkrunfw_path, 1),
|
|
96
|
+
)?;
|
|
73
97
|
native.define_singleton_method("resolved_msb_path", function!(resolved_msb_path, 0))?;
|
|
74
98
|
native.define_singleton_method("all_sandbox_metrics", function!(all_sandbox_metrics, 0))?;
|
|
75
99
|
|
|
100
|
+
backend::define(ruby, &native)?;
|
|
76
101
|
sandbox::define(ruby, &native)?;
|
|
77
102
|
exec::define(ruby, &native)?;
|
|
78
103
|
stream::define(ruby, &native)?;
|
|
79
104
|
snapshot::define(ruby, &native)?;
|
|
80
105
|
image::define(ruby, &native)?;
|
|
81
106
|
volume::define(ruby, &native)?;
|
|
107
|
+
agent::define(ruby, &native)?;
|
|
108
|
+
ssh::define(ruby, &native)?;
|
|
82
109
|
|
|
83
110
|
Ok(())
|
|
84
111
|
}
|