mirror of
https://codeberg.org/icewind/haze.git
synced 2026-06-03 17:14:08 +02:00
exec fixes
This commit is contained in:
parent
1baabacf87
commit
ec6df26bf7
3 changed files with 21 additions and 14 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -65,7 +65,7 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bollard"
|
name = "bollard"
|
||||||
version = "0.10.1"
|
version = "0.10.1"
|
||||||
source = "git+https://github.com/icewind1991/bollard?branch=exec-input#31651016742357aa632944b05bb032cd0ce7d8ed"
|
source = "git+https://github.com/icewind1991/bollard?branch=marged#f220f0cc1f4e8637ed6402074597fa84c6212d85"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64",
|
"base64",
|
||||||
"bollard-stubs",
|
"bollard-stubs",
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ authors = ["Robin Appelman <robin@icewind.nl>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bollard = { version = "0.10", git = "https://github.com/icewind1991/bollard", branch = "exec-input" }
|
bollard = { version = "0.10", git = "https://github.com/icewind1991/bollard", branch = "marged" }
|
||||||
color-eyre = "0.5"
|
color-eyre = "0.5"
|
||||||
maplit = "1"
|
maplit = "1"
|
||||||
camino = { version = "1", features = ["serde1"] }
|
camino = { version = "1", features = ["serde1"] }
|
||||||
|
|
|
||||||
31
src/exec.rs
31
src/exec.rs
|
|
@ -1,13 +1,13 @@
|
||||||
use bollard::container::LogsOptions;
|
use bollard::container::LogsOptions;
|
||||||
use bollard::exec::{CreateExecOptions, StartExecResults};
|
use bollard::exec::{CreateExecOptions, ResizeExecOptions, StartExecResults};
|
||||||
use bollard::Docker;
|
use bollard::Docker;
|
||||||
use color_eyre::{eyre::WrapErr, Result};
|
use color_eyre::{eyre::WrapErr, Result};
|
||||||
use futures_util::StreamExt;
|
use futures_util::StreamExt;
|
||||||
use std::io::{stdout, Read, Write};
|
use std::io::{stdout, Read, Write};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use termion::async_stdin;
|
|
||||||
use termion::raw::IntoRawMode;
|
use termion::raw::IntoRawMode;
|
||||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
use termion::{async_stdin, terminal_size};
|
||||||
|
use tokio::io::AsyncWriteExt;
|
||||||
use tokio::task::spawn;
|
use tokio::task::spawn;
|
||||||
use tokio::time::sleep;
|
use tokio::time::sleep;
|
||||||
|
|
||||||
|
|
@ -18,6 +18,7 @@ pub async fn exec_tty<S1: AsRef<str>, S2: Into<String>>(
|
||||||
cmd: Vec<S2>,
|
cmd: Vec<S2>,
|
||||||
env: Vec<&str>,
|
env: Vec<&str>,
|
||||||
) -> Result<i64> {
|
) -> Result<i64> {
|
||||||
|
let tty_size = terminal_size()?;
|
||||||
let cmd = cmd.into_iter().map(S2::into).collect();
|
let cmd = cmd.into_iter().map(S2::into).collect();
|
||||||
let env = env.into_iter().map(String::from).collect();
|
let env = env.into_iter().map(String::from).collect();
|
||||||
let config = CreateExecOptions {
|
let config = CreateExecOptions {
|
||||||
|
|
@ -34,14 +35,24 @@ pub async fn exec_tty<S1: AsRef<str>, S2: Into<String>>(
|
||||||
.create_exec(container.as_ref(), config)
|
.create_exec(container.as_ref(), config)
|
||||||
.await
|
.await
|
||||||
.wrap_err("Failed to setup exec")?;
|
.wrap_err("Failed to setup exec")?;
|
||||||
if let StartExecResults::AttachedTTY {
|
if let StartExecResults::Attached {
|
||||||
mut output,
|
mut output,
|
||||||
mut input,
|
mut input,
|
||||||
} = docker
|
} = docker
|
||||||
.start_exec(&message.id, None, true)
|
.start_exec(&message.id, None)
|
||||||
.await
|
.await
|
||||||
.wrap_err("Failed to start exec")?
|
.wrap_err("Failed to start exec")?
|
||||||
{
|
{
|
||||||
|
docker
|
||||||
|
.resize_exec(
|
||||||
|
&message.id,
|
||||||
|
ResizeExecOptions {
|
||||||
|
height: tty_size.1,
|
||||||
|
width: tty_size.0,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
// pipe stdin into the docker exec stream input
|
// pipe stdin into the docker exec stream input
|
||||||
spawn(async move {
|
spawn(async move {
|
||||||
let mut stdin = async_stdin().bytes();
|
let mut stdin = async_stdin().bytes();
|
||||||
|
|
@ -59,12 +70,8 @@ pub async fn exec_tty<S1: AsRef<str>, S2: Into<String>>(
|
||||||
let mut stdout = stdout.lock().into_raw_mode()?;
|
let mut stdout = stdout.lock().into_raw_mode()?;
|
||||||
|
|
||||||
// pipe docker exec output into stdout
|
// pipe docker exec output into stdout
|
||||||
let mut buff = [0; 128];
|
while let Some(Ok(output)) = output.next().await {
|
||||||
while let Ok(read) = output.read(&mut buff).await {
|
stdout.write(output.into_bytes().as_ref())?;
|
||||||
if read == 0 {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
stdout.write(&buff[0..read])?;
|
|
||||||
stdout.flush()?;
|
stdout.flush()?;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -101,7 +108,7 @@ pub async fn exec<S1: AsRef<str>, S2: Into<String>>(
|
||||||
.await
|
.await
|
||||||
.wrap_err("Failed to setup exec")?;
|
.wrap_err("Failed to setup exec")?;
|
||||||
if let StartExecResults::Attached { mut output, .. } = docker
|
if let StartExecResults::Attached { mut output, .. } = docker
|
||||||
.start_exec(&message.id, None, false)
|
.start_exec(&message.id, None)
|
||||||
.await
|
.await
|
||||||
.wrap_err("Failed to start exec")?
|
.wrap_err("Failed to start exec")?
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue