Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@ members = ["crates/*"]
default-members = [".", "crates/*"]

[workspace.package]
version = "4.1.2"
version = "4.2.0"
edition = "2024"
rust-version = "1.89"
license = "LicenseRef-EXA-SL-1.0"
repository = "https://github.com/execution-associates/isb"
homepage = "https://github.com/execution-associates/isb"

[workspace.dependencies]
isb-core = { path = "crates/isb-core", version = "=4.1.2" }
isb-server = { path = "crates/isb-server", version = "=4.1.2" }
isb-apps = { path = "crates/isb-apps", version = "=4.1.2" }
isb-daemon = { path = "crates/isb-daemon", version = "=4.1.2" }
isb-tui = { path = "crates/isb-tui", version = "=4.1.2" }
isb-egress = { path = "crates/isb-egress", version = "=4.1.2" }
isb-core = { path = "crates/isb-core", version = "=4.2.0" }
isb-server = { path = "crates/isb-server", version = "=4.2.0" }
isb-apps = { path = "crates/isb-apps", version = "=4.2.0" }
isb-daemon = { path = "crates/isb-daemon", version = "=4.2.0" }
isb-tui = { path = "crates/isb-tui", version = "=4.2.0" }
isb-egress = { path = "crates/isb-egress", version = "=4.2.0" }

serde = { version = "1", features = ["derive"] }
serde_json = "1"
Expand Down
6 changes: 5 additions & 1 deletion SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ isb ps # status of the file's sandboxes
isb port get NAME DEV # the port a published range picked
isb config # the file with every ${VAR} filled in
isb down # delete them (--volumes also deletes named volumes)
isb volume prune # list volumes whose sandbox is gone (-y deletes)
```

`isb up` blocks until every `command` exits (forever if none has one), Ctrl-C,
Expand Down Expand Up @@ -195,7 +196,10 @@ cannot exec or read secrets.
`sandbox_remove`. Remote callers' specs are refused privileged mode, raw
config, host bind mounts outside the bind roots and non-loopback ports.
`sandbox_settings` reads the org's defaults (`sandbox_expiry`,
`sandbox_idle`); org admins change them.
`sandbox_idle`, `sandbox_volume_ttl`); org admins change them. A volume a
sandbox created is deleted once that sandbox has been gone, with nothing
using the volume, for `sandbox_volume_ttl` (7d); `keep: true` on the
volume's definition exempts it.
- **Apps:** `project_create`, `app_create` (an image, or a git repository and
a builder), `app_env_set` (`.env` text; `KEY=${{secret.NAME}}` for
secrets), `app_deploy` (`wait: true`), `app_deployment_log`,
Expand Down
1 change: 1 addition & 0 deletions crates/isb-apps/src/volume_backup/incus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ mod tests {
"/1.0/instances/ws".into(),
"/1.0/profiles/default".into(),
],
created_at: String::new(),
};
assert_eq!(instances_using(&v), ["web-1", "ws"]);
}
Expand Down
4 changes: 3 additions & 1 deletion crates/isb-core/src/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,14 @@ impl HostFacts {
}
}

/// A named volume that must exist before the instance.
/// A named volume that must exist before the instance. `keep` is its definition's: never marked as a sandbox's.
#[derive(Debug, Clone, PartialEq, Serialize)]
pub struct EnsureVolume {
pub pool: String,
pub name: String,
pub config: Props,
pub external: bool,
pub keep: bool,
}

/// chown (and root-owned parents in the owner's home) and/or chmod a mount point.
Expand Down Expand Up @@ -751,6 +752,7 @@ pub fn resolve(
name: n.clone(),
config,
external: v.external || def.is_some_and(|d| d.external),
keep: def.is_some_and(|d| d.keep),
};
if !volumes
.iter()
Expand Down
4 changes: 4 additions & 0 deletions crates/isb-core/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ impl Server {
let a: SpecParams = params(p)?;
let c = self.client(&a.project);
let opts = EnsureOptions {
own_volumes: true,
wait_ready: a.wait_ready,
default_expiry: self.default_expiry(&c),
..Default::default()
Expand All @@ -196,6 +197,7 @@ impl Server {
let a: SpecParams = params(p)?;
let c = self.client(&a.project);
let opts = EnsureOptions {
own_volumes: true,
wait_ready: a.wait_ready,
diff: DiffOptions {
prune_devices: a.prune_devices,
Expand Down Expand Up @@ -370,6 +372,7 @@ impl Server {
let proj = compose::load(&a.load())?;
let c = self.client(&a.project);
let opts = EnsureOptions {
own_volumes: true,
wait_ready: a.wait_ready,
diff: DiffOptions {
prune_devices: a.prune_devices,
Expand Down Expand Up @@ -552,6 +555,7 @@ fn create_desired(
return Err(Error::AlreadyExists(d.name.clone()));
}
let plan = sandbox::plan_desired(c, d, opts.diff)?;
let plan = sandbox::own_volumes(c, d, plan, opts.own_volumes);
let stamped = sandbox::expiry::stamped(d, &plan, opts.default_expiry);
sandbox::apply(c, &stamped, &plan, report)?;
sandbox::expiry::report_created(&stamped, report);
Expand Down
28 changes: 4 additions & 24 deletions crates/isb-core/src/sandbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::idmap::SubIds;
use crate::lock::NameLock;
pub mod expiry;
pub mod images;
mod options;
mod prune;
mod update;

Expand All @@ -22,6 +23,7 @@ use crate::plan::{
VolumeDefs, split_addr,
};
use crate::spec::{ExecDefaults, PortSpec, ReadyCheck, SandboxSpec};
pub use options::{EnsureOptions, own_volumes};
pub use prune::{PruneItem, prune_missing_path};
#[doc(hidden)]
pub use update::update_instance;
Expand Down Expand Up @@ -127,30 +129,6 @@ pub struct ApplyReport {
pub restart_needed: Vec<String>,
}

/// Options for ensure / up.
#[derive(Debug, Clone, Copy)]
pub struct EnsureOptions {
pub diff: DiffOptions,
/// Run readiness checks after applying.
pub wait_ready: bool,
/// How long to wait for another isb holding this sandbox's lock.
pub lock_wait: Duration,
/// The lifetime of a sandbox whose spec gives no `expires` ([`expiry`]):
/// set by the CLI and `isb rpc`; `None` gives it no deadline.
pub default_expiry: Option<Duration>,
}

impl Default for EnsureOptions {
fn default() -> Self {
EnsureOptions {
diff: DiffOptions::default(),
wait_ready: true,
lock_wait: Duration::from_secs(900),
default_expiry: None,
}
}
}

fn inst_path(name: &str) -> String {
format!("/1.0/instances/{}", encode_segment(name))
}
Expand Down Expand Up @@ -861,6 +839,7 @@ pub fn ensure(
},
)?;
let plan = plan_desired(client, desired, opts.diff)?;
let plan = own_volumes(client, desired, plan, opts.own_volumes);
let stamped = expiry::stamped(desired, &plan, opts.default_expiry);
let mut out = apply(client, &stamped, &plan, report)?;
if out.created {
Expand Down Expand Up @@ -969,6 +948,7 @@ impl Sandbox {
return Err(Error::AlreadyExists(d.name.clone()));
}
let plan = plan_desired(client, &d, opts.diff)?;
let plan = own_volumes(client, &d, plan, opts.own_volumes);
let stamped = expiry::stamped(&d, &plan, opts.default_expiry);
apply(client, &stamped, &plan, report)?;
expiry::report_created(&stamped, report);
Expand Down
70 changes: 70 additions & 0 deletions crates/isb-core/src/sandbox/options.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//! The options of an ensure, and the mark on the volumes a plain sandbox
//! creates ([`crate::volume::KEY_SANDBOX`]).

use std::time::Duration;

use crate::client::Client;
use crate::plan::{Action, Desired, DiffOptions, SandboxPlan};

/// Options for ensure / up.
#[derive(Debug, Clone, Copy)]
pub struct EnsureOptions {
pub diff: DiffOptions,
/// Run readiness checks after applying.
pub wait_ready: bool,
/// How long to wait for another isb holding this sandbox's lock.
pub lock_wait: Duration,
/// The lifetime of a sandbox whose spec gives no `expires` ([`super::expiry`]):
/// set by the CLI and `isb rpc`; `None` gives it no deadline.
pub default_expiry: Option<Duration>,
/// Mark the volumes this call creates as this sandbox's
/// ([`crate::volume::KEY_SANDBOX`]), so they are cleaned up once it is
/// gone. For plain sandboxes only: a stack's or an app's volumes hold
/// data that outlives every instance.
pub own_volumes: bool,
}

impl Default for EnsureOptions {
fn default() -> Self {
EnsureOptions {
diff: DiffOptions::default(),
wait_ready: true,
lock_wait: Duration::from_secs(900),
default_expiry: None,
own_volumes: false,
}
}
}

/// `plan`, with each volume it creates marked as `desired`'s when `own`
/// ([`EnsureOptions::own_volumes`]). A `keep` volume is never marked, and an
/// external one is never created.
pub fn own_volumes(
client: &Client,
desired: &Desired,
mut plan: SandboxPlan,
own: bool,
) -> SandboxPlan {
if !own {
return plan;
}
let owner = format!("{}/{}", client.project_name(), desired.name);
for a in &mut plan.actions {
let Action::CreateVolume {
pool,
volume,
config,
} = a
else {
continue;
};
let keep = desired
.volumes
.iter()
.any(|v| (&v.pool, &v.name) == (&*pool, &*volume) && v.keep);
if !keep {
config.insert(crate::volume::KEY_SANDBOX.into(), owner.clone());
}
}
plan
}
Loading
Loading