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
2 changes: 1 addition & 1 deletion crates/kiri/src/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub const COMMANDS: &[&str] = &[
/// `kiri update` is two commands. Alone or with `--check` it updates Kiri;
/// with anything else it is Docker's `update`, which always names a
/// container (`kiri update --memory 256m web`).
#[cfg(any(target_os = "macos", target_os = "linux", test))]
#[cfg(any(target_os = "macos", target_os = "linux", windows, test))]
pub fn is_container_update(args: &[String]) -> bool {
args.iter().any(|a| !matches!(a.as_str(), "--check" | "-h" | "--help"))
}
Expand Down
24 changes: 14 additions & 10 deletions crates/kiri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ mod ui;
#[cfg(unix)]
#[cfg_attr(not(target_os = "macos"), allow(dead_code))]
mod tools;
#[cfg(any(target_os = "macos", target_os = "linux"))]
#[cfg(any(target_os = "macos", target_os = "linux", windows))]
mod update;

const USAGE_LINES: &[&str] = &[
Expand All @@ -135,7 +135,7 @@ const USAGE_LINES: &[&str] = &[
" kiri scan [--json] [--history] <image> known vulnerabilities in an image, found by Grype",
#[cfg(target_os = "macos")]
" kiri update [--check] update Kiri (with a container: docker's update)",
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", windows))]
" kiri update --check check for a newer Kiri (with a container: docker's update)",
" kiri doctor [--json] whether Kiri works here, and what to run when a part doesn't",
" kiri diag logs [-f] [--ui|--engine|--cli] [--errors] [-n N]",
Expand Down Expand Up @@ -258,7 +258,7 @@ enum Command<'a> {
Import(&'a [String]),
#[cfg(target_os = "macos")]
Vm(&'a [String]),
#[cfg(any(target_os = "macos", target_os = "linux"))]
#[cfg(any(target_os = "macos", target_os = "linux", windows))]
Update(&'a [String]),
#[cfg(unix)]
Diag(&'a [String]),
Expand Down Expand Up @@ -332,7 +332,7 @@ impl<'a> Command<'a> {
Some("import") => Some(Command::Import(&args[1..])),
#[cfg(target_os = "macos")]
Some("vm") => Some(Command::Vm(&args[1..])),
#[cfg(any(target_os = "macos", target_os = "linux"))]
#[cfg(any(target_os = "macos", target_os = "linux", windows))]
Some("update") if !docker::is_container_update(&args[1..]) => Some(Command::Update(&args[1..])),
#[cfg(unix)]
Some("diag") => Some(Command::Diag(&args[1..])),
Expand Down Expand Up @@ -487,7 +487,7 @@ fn main() -> ExitCode {
Some(Command::Import(rest)) => import::run(rest),
#[cfg(target_os = "macos")]
Some(Command::Vm(rest)) => vm_cli::run(rest),
#[cfg(any(target_os = "macos", target_os = "linux"))]
#[cfg(any(target_os = "macos", target_os = "linux", windows))]
Some(Command::Update(rest)) => update::run(rest),
#[cfg(unix)]
Some(Command::Diag(rest)) => diag::run(rest),
Expand Down Expand Up @@ -647,14 +647,16 @@ mod tests {
}
#[cfg(windows)]
{
for win_cmd in ["setup", "build-with", "import"] {
for win_cmd in ["setup", "build-with", "import", "update"] {
assert!(cmds.contains(&win_cmd), "Windows help missing `{win_cmd}`:\n{help}");
}
assert!(help.contains("kiri update --check"), "Windows help missing `kiri update --check`:\n{help}");
assert!(!help.contains("kiri update [--check]"), "Windows help must not list macOS `kiri update [--check]`:\n{help}");
assert!(
help.contains("kiri import [desktop-linux] [--images] [--volumes] [--containers]"),
"Windows help missing `kiri import [desktop-linux] [--images] [--volumes] [--containers]`:\n{help}"
);
for unix_or_mac in ["daemon", "bridge", "ui", "update", "vm", "bench", "boot", "raw"] {
for unix_or_mac in ["daemon", "bridge", "ui", "vm", "bench", "boot", "raw"] {
assert!(!cmds.contains(&unix_or_mac), "Windows help must not list `{unix_or_mac}`:\n{help}");
}
}
Expand Down Expand Up @@ -729,7 +731,7 @@ mod tests {
assert_eq!(Command::parse(&["raw".to_owned()]), Some(Command::RawInvalid));
}

#[cfg(any(target_os = "macos", target_os = "linux"))]
#[cfg(any(target_os = "macos", target_os = "linux", windows))]
for args in [
vec!["update".to_owned()],
vec!["update".to_owned(), "--check".to_owned()],
Expand All @@ -751,7 +753,7 @@ mod tests {
for unix_cmd in ["bridge", "ui", "vm", "bench", "boot", "raw"] {
assert!(parse(&[unix_cmd]).is_none(), "`kiri {unix_cmd}` should not dispatch on Windows");
}
for win_cmd in ["setup", "build-with", "import"] {
for win_cmd in ["setup", "build-with", "import", "update"] {
assert!(parse(&[win_cmd]).is_some(), "`kiri {win_cmd}` must dispatch on Windows");
}
let daemon_args = ["daemon".to_owned()];
Expand Down Expand Up @@ -844,9 +846,11 @@ mod tests {
&["diag", "logs"],
&["diag", "report"],
];
#[cfg(any(target_os = "macos", target_os = "linux", windows))]
subcommands.push(&["update"]);
#[cfg(any(target_os = "macos", target_os = "linux"))]
{
subcommands.extend([&["ui"][..], &["update"]]);
subcommands.push(&["ui"]);
}
#[cfg(unix)]
{
Expand Down
30 changes: 26 additions & 4 deletions crates/kiri/src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,21 @@ use sha2::{Digest, Sha256};

/// Each Mac reads its own feed, so a release for one never reaches the other
/// (and check() refuses an app without code for this CPU anyway).
#[cfg(all(not(target_os = "linux"), not(target_arch = "x86_64")))]
#[cfg(all(target_os = "macos", not(target_arch = "x86_64")))]
const FEED: &str = "https://download.runkiri.com/latest-mac-arm64.json";
/// Intel Macs get the Intel app (`cargo xtask release --arch x86_64`).
#[cfg(all(not(target_os = "linux"), target_arch = "x86_64"))]
#[cfg(all(target_os = "macos", target_arch = "x86_64"))]
const FEED: &str = "https://download.runkiri.com/latest-mac-x86_64.json";
/// Linux reads only the version: its kiri is a .deb or .rpm installed from
/// runkiri.com, so nothing is downloaded from the feed.
#[cfg(target_os = "linux")]
const FEED: &str = "https://download.runkiri.com/latest.json";
/// Windows CLI checks the architecture's Windows release feed (`kiri-win`
/// performs background MSI updates from the window).
#[cfg(all(windows, not(target_arch = "aarch64")))]
const FEED: &str = "https://download.runkiri.com/latest-windows-x86_64.json";
#[cfg(all(windows, target_arch = "aarch64"))]
const FEED: &str = "https://download.runkiri.com/latest-windows-arm64.json";
/// The biggest download accepted (the app is about 60 MB packed).
#[cfg(target_os = "macos")]
const MAX_DOWNLOAD: u64 = 2 << 30;
Expand Down Expand Up @@ -114,6 +120,7 @@ fn latest_from(url: &str) -> io::Result<Release> {
let body = agent().get(url).call().map_err(io::Error::other)?.body_mut().with_config().limit(64 << 10).read_to_vec().map_err(io::Error::other)?;
serde_json::from_slice(&body).map_err(|e| io::Error::new(io::ErrorKind::InvalidData, format!("{url}: {e}")))
})();
#[cfg(unix)]
match &release {
Ok(r) => crate::diag::info!("update check", latest = r.version, current = env!("CARGO_PKG_VERSION")),
Err(e) => crate::diag::warn!("update check failed", error = e),
Expand Down Expand Up @@ -290,6 +297,7 @@ fn start_engine_with(
if alive() {
return Ok(());
}
#[cfg(unix)]
crate::diag::info!("starting the engine");
if start_agent().unwrap_or(false) {
for _ in 0..50 {
Expand All @@ -298,6 +306,7 @@ fn start_engine_with(
}
sleep(std::time::Duration::from_millis(50));
}
#[cfg(unix)]
crate::diag::warn!("LaunchAgent kickstart did not bring up engine; starting daemon directly");
}
spawn_daemon()?;
Expand Down Expand Up @@ -471,7 +480,7 @@ fn has_cpu(head: &[u8], want: u32) -> bool {

#[cfg(target_os = "macos")]
const USAGE: &str = "usage: kiri update [--check]";
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", windows))]
const USAGE: &str = "usage: kiri update --check";

pub fn run(args: &[String]) -> io::Result<()> {
Expand Down Expand Up @@ -501,6 +510,12 @@ fn run_release(args: &[String], release: &Release, current: &str, out: &mut dyn
writeln!(out, "download the new .deb or .rpm from https://runkiri.com/releases/ and install it as before")?;
Ok(())
}
#[cfg(windows)]
{
let _ = args;
writeln!(out, "update from Kiri's window, or download the new installer from https://runkiri.com/releases/")?;
Ok(())
}
#[cfg(target_os = "macos")]
{
if args.iter().any(|a| a == "--check") {
Expand Down Expand Up @@ -556,7 +571,7 @@ mod tests {
fn help_skips_release_lookup() {
#[cfg(target_os = "macos")]
assert_eq!(USAGE, "usage: kiri update [--check]");
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", windows))]
assert_eq!(USAGE, "usage: kiri update --check");

for dev in [false, true] {
Expand Down Expand Up @@ -684,6 +699,13 @@ mod tests {
run_with(&[], &url, env!("CARGO_PKG_VERSION"), &mut bare_out).unwrap();
assert_eq!(String::from_utf8(bare_out).unwrap(), text);
}
if cfg!(windows) {
assert!(text.contains("update from Kiri's window, or download the new installer from https://runkiri.com/releases/\n"), "got {text:?}");
let url = serve_feed("200 OK", r#"{"version":"99.0.0","url":"https://runkiri.com/download","sha256":""}"#);
let mut bare_out = Vec::new();
run_with(&[], &url, env!("CARGO_PKG_VERSION"), &mut bare_out).unwrap();
assert_eq!(String::from_utf8(bare_out).unwrap(), text);
}
}

#[test]
Expand Down
6 changes: 6 additions & 0 deletions docs/fix-registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ A log of every merged bug fix in Kiri, newest first, together with any later bug

## Fixes

### #984 Windows CLI: support `kiri update --check` against the Windows release feed (unreleased)
- Fixes: #984 (`kiri.exe update --check` fell through to `docker update --check` with `unknown flag: --check` on Windows)
- Caused: none known
- Caused by: -
- Check: `crates/kiri/src/update.rs`, `crates/kiri/src/main.rs`

### #190, #269, #399, #744 Release gate fixes: virtiofs deleted-file revalidation across `docker run --rm`, offline `kiri domains set/reset`, netns lock takeover after stuck container start, transient `429` manifest retries, WSL `statvfs` `f_bfree` usage, and WSL `kiri` context hash (unreleased)
- Fixes: #399 (back-to-back `docker run --rm -v` sees 1 s `ENOENT` recreating a host-deleted file), #744 (`kiri domains set` and `kiri domains reset` failed when the daemon was stopped), #190 (`statvfs_usage` used `f_bavail` instead of `f_bfree`, counting ~55 GB of ext4 reserved blocks on WSL's sparse `ext4.vhdx` as used), #269 (`wslsync.rs` hardcoded the wrong SHA-256 for Docker context `kiri`), `agent-dies-beside-stuck-start` (`claim_host_netns` failed when a dead agent's frozen child still held `@kiri-engine-netns`), `pulls-of-different-images-at-once-leave-a-sound-index` (`Client::manifest` did not retry HTTP `429` / transient registry errors)
- Caused: none known
Expand Down
2 changes: 1 addition & 1 deletion tests/regressions.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ dns-default-bridge-stub #330 on a Linux host whose /etc/resolv.conf names only 1
build-pinned-digest #288 a digest-pinned FROM image (@sha256:...) already pulled into Kiri's store was re-serialized instead of served with its upstream manifest and index bytes, failing BuildKit's digest check (#330)
build-host-network-dns #209 build steps under docker build and docker build --network=host (or a host-network builder) could not resolve names through a loopback stub resolver on the host (#330)
crates/kiri/src/main.rs #743 kiri --help listed commands not compiled for the current OS (such as macOS-only setup, import, bench and boot on Linux, or Linux-only bridge on macOS)
crates/kiri/src/update.rs #840 kiri update --help and kiri update -h entered the updater and tried the release feed (or failed the dev-build check) instead of printing OS-appropriate usage offline
crates/kiri/src/update.rs #840 kiri update --help and kiri update -h entered the updater and tried the release feed (or failed the dev-build check) instead of printing OS-appropriate usage offline, and on Windows kiri update --check fell through to docker update --check (#984)
vol-rm-force-in-use #773 docker volume rm --force (and DELETE /volumes/{name}?force=1) removed a volume still used by a container instead of returning 409 Conflict and keeping its data
vol-rm-force-missing #773 DELETE /volumes/{name}?force=1 (and docker volume rm -f) returned 404 Not Found for a missing volume instead of 204 No Content as Docker does
crates/kiri-image/src/reference.rs #746 Reference::parse and archive::load accepted quotes, backslashes, queries and fragments in image names, storing unparseable or hostile RepoTags from docker load
Expand Down
Loading