diff --git a/crates/client/src/release.rs b/crates/client/src/release.rs index 91149bd..0373e79 100644 --- a/crates/client/src/release.rs +++ b/crates/client/src/release.rs @@ -71,6 +71,7 @@ const LINUX_PACKAGES: &str = "ca-certificates curl git build-essential pkg-confi const ARCHIVE: &str = "dist/source.tgz"; const VM: &str = "yumush-win"; const VM_DIR: &str = "vm/yumush-win"; +const SSH_WAIT: Duration = Duration::from_secs(3 * 60 * 60); const VM_IMAGE: &str = "docker.io/dockurr/windows"; const VM_AUDIO: &str = "ARGUMENTS=-audiodev none,id=snd0 -device ich9-intel-hda,id=hda1 -device hda-duplex,bus=hda1.0,audiodev=snd0 -device ich9-intel-hda,id=hda2 -device hda-duplex,bus=hda2.0,audiodev=snd0"; const INSTALL: &str = include_str!("release/install.bat"); @@ -347,7 +348,7 @@ fn start_linux(job: Job, source: &Path, cx: &Cx) -> Result<(), String> { )?; let rust = host_rust()?; let script = format!( - "command -v clang >/dev/null || {{ apt-get update; apt-get install -y --no-install-recommends {LINUX_PACKAGES}; }} + "[ -f /etc/yumush-ready ] || {{ apt-get update; apt-get install -y --no-install-recommends {LINUX_PACKAGES}; touch /etc/yumush-ready; }} [ -x /root/.cargo/bin/rustup ] || curl -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --default-toolchain none rustup toolchain install {rust} --profile minimal rustup default {rust} @@ -541,7 +542,7 @@ exit $LASTEXITCODE } fn wait_ssh(job: Job, key: &Path, cx: &Cx) -> Result<(), String> { - let deadline = Instant::now() + Duration::from_secs(600); + let deadline = Instant::now() + SSH_WAIT; while !ssh_ok(key) { if cx.cancelled() { return Err("cancelled".into()); @@ -549,12 +550,36 @@ fn wait_ssh(job: Job, key: &Path, cx: &Cx) -> Result<(), String> { if Instant::now() >= deadline { return Err("ssh timeout".into()); } - cx.send(Event::Line(job, "waiting for ssh".into())); + cx.send(Event::Line(job, vm_status())); thread::sleep(Duration::from_secs(5)); } Ok(()) } +fn vm_status() -> String { + let Ok(out) = podman().args(["logs", "--tail", "5", VM]).output() else { + return "waiting for ssh".into(); + }; + let text = String::from_utf8_lossy(&out.stdout) + String::from_utf8_lossy(&out.stderr); + text.lines() + .map(plain) + .rfind(|line| !line.is_empty()) + .unwrap_or_else(|| "waiting for ssh".into()) +} + +fn plain(line: &str) -> String { + let mut out = String::new(); + let mut chars = line.chars(); + while let Some(c) = chars.next() { + if c == '\u{1b}' { + chars.by_ref().find(|c| c.is_ascii_alphabetic()); + } else if c != '❯' { + out.push(c); + } + } + out.trim().trim_end_matches("...").to_string() +} + fn opts(key: &Path, port_flag: &str) -> Vec { let mut args = vec!["-i".to_string(), key.display().to_string()]; for option in [