Skip to content

Commit

Permalink
Merge branch 'nightly' into release/nightly/bin/nproxy/1.26.0-n0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
leon3s authored Oct 22, 2024
2 parents 815890c + 0c94f63 commit b03a5ff
Show file tree
Hide file tree
Showing 14 changed files with 146 additions and 59 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

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

11 changes: 8 additions & 3 deletions bin/nanocl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ chrono = { version = "0.4", default-features = false, features = [
"clock",
] }
dialoguer = "0.11"
termios = "0.3"
liquid = { version = "0.26", features = ["stdlib"] }
regex = "1.10"
nanocld_client = { version = "0.16", features = ["tokio", "openssl"] }
Expand All @@ -66,13 +65,19 @@ nanocl_error = { version = "0.5", features = [
"bollard",
"serde_yaml",
] }
nanocl_utils = { version = "0.7", features = ["unix"] }
ctrlc = "3.4"
toml = "0.8"
ring = "0.17"
nix = { version = "0.29", features = ["user"] }
dotenvy = "0.15"
openssl = "0.10"
async-recursion = "1.1"
url = "2.5"
colored = "2.1.0"

[target.'cfg(not(target_os = "windows"))'.dependencies]
nix = { version = "0.29", features = ["user"] }
nanocl_utils = { version = "0.7", features = ["unix"] }
termios = "0.3"

[target.'cfg(target_os = "windows")'.dependencies]
nanocl_utils = { version = "0.7" }
1 change: 1 addition & 0 deletions bin/nanocl/src/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::{

/// This function is called when running `nanocl install`
/// It will install nanocl system containers
///
pub async fn exec_install(args: &InstallOpts) -> IoResult<()> {
let home_dir = std::env::var("HOME").map_err(|err| {
IoError::interrupted("Unable to get $HOME env variable", &err.to_string())
Expand Down
4 changes: 4 additions & 0 deletions bin/nanocl/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod context;
mod event;
mod generic;
mod info;
#[cfg(not(target_os = "windows"))]
mod install;
mod job;
mod metric;
Expand All @@ -13,6 +14,7 @@ mod process;
mod resource;
mod secret;
mod state;
#[cfg(not(target_os = "windows"))]
mod uninstall;
mod version;
mod vm;
Expand All @@ -25,6 +27,7 @@ pub use cargo::exec_cargo;
pub use context::exec_context;
pub use event::exec_event;
pub use info::exec_info;
#[cfg(not(target_os = "windows"))]
pub use install::exec_install;
pub use job::exec_job;
pub use metric::exec_metric;
Expand All @@ -34,6 +37,7 @@ pub use process::exec_process;
pub use resource::exec_resource;
pub use secret::exec_secret;
pub use state::exec_state;
#[cfg(not(target_os = "windows"))]
pub use uninstall::exec_uninstall;
pub use version::exec_version;
pub use vm::exec_vm;
26 changes: 23 additions & 3 deletions bin/nanocl/src/commands/vm.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#[cfg(not(target_os = "windows"))]
use std::os::fd::AsRawFd;
use std::{
io::{Read, Write},
os::fd::AsRawFd,
thread,
time::Duration,
};
Expand All @@ -10,6 +11,7 @@ use futures::{
{SinkExt, StreamExt},
};
use ntex::{rt, time, util::Bytes, ws};
#[cfg(not(target_os = "windows"))]
use termios::{tcsetattr, Termios, ECHO, ICANON, TCSANOW};

use nanocl_error::io::{FromIo, IoResult};
Expand Down Expand Up @@ -112,7 +114,14 @@ pub async fn exec_vm_run(
.await?;
waiter.await??;
if options.attach {
exec_vm_attach(cli_conf, args, &options.name).await?;
#[cfg(not(target_os = "windows"))]
{
exec_vm_attach(cli_conf, args, &options.name).await?;
}
#[cfg(target_os = "windows")]
{
println!("Attach is not supported on windows yet");
}
}
Ok(())
}
Expand All @@ -138,6 +147,7 @@ pub async fn exec_vm_patch(

/// Function executed when running `nanocl vm attach`
/// It will attach to a virtual machine console
#[cfg(not(target_os = "windows"))]
pub async fn exec_vm_attach(
cli_conf: &CliConfig,
args: &VmArg,
Expand Down Expand Up @@ -259,6 +269,16 @@ pub async fn exec_vm(cli_conf: &CliConfig, args: &VmArg) -> IoResult<()> {
}
VmCommand::Run(options) => exec_vm_run(cli_conf, args, options).await,
VmCommand::Patch(options) => exec_vm_patch(cli_conf, args, options).await,
VmCommand::Attach { name } => exec_vm_attach(cli_conf, args, name).await,
VmCommand::Attach { name } => {
#[cfg(not(target_os = "windows"))]
{
exec_vm_attach(cli_conf, args, name).await
}
#[cfg(target_os = "windows")]
{
println!("Attach is not supported on windows yet");
Ok(())
}
}
}
}
24 changes: 22 additions & 2 deletions bin/nanocl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,28 @@ async fn execute_arg(cli_args: &Cli) -> IoResult<()> {
Command::Version => commands::exec_version(&cli_conf).await,
Command::Vm(args) => commands::exec_vm(&cli_conf, args).await,
Command::Ps(args) => commands::exec_process(&cli_conf, args).await,
Command::Install(args) => commands::exec_install(args).await,
Command::Uninstall(args) => commands::exec_uninstall(args).await,
Command::Install(args) => {
#[cfg(not(target_os = "windows"))]
{
commands::exec_install(args).await
}
#[cfg(target_os = "windows")]
{
println!("Install is not supported on windows yet");
Ok(())
}
}
Command::Uninstall(args) => {
#[cfg(not(target_os = "windows"))]
{
commands::exec_uninstall(args).await
}
#[cfg(target_os = "windows")]
{
println!("Uninstall is not supported on windows yet");
Ok(())
}
}
Command::Node(args) => commands::exec_node(&cli_conf, args).await,
Command::Context(args) => commands::exec_context(&cli_conf, args).await,
Command::Info => commands::exec_info(&cli_conf).await,
Expand Down
34 changes: 22 additions & 12 deletions bin/nanocl/src/utils/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,30 @@ pub async fn install_image(
pub fn connect(docker_host: &str) -> IoResult<Docker> {
let docker = match &docker_host {
docker_host if docker_host.starts_with("unix://") => {
let path = docker_host.trim_start_matches("unix://");
if !std::path::Path::new(&path).exists() {
return Err(IoError::not_found(
"Unix socket file can't be found at",
path,
#[cfg(not(target_os = "windows"))]
{
let path = docker_host.trim_start_matches("unix://");
if !std::path::Path::new(&path).exists() {
return Err(IoError::not_found(
"Unix socket file can't be found at",
path,
));
}
Docker::connect_with_unix(path, 120, API_DEFAULT_VERSION).map_err(
|err| {
err.map_err_context(|| {
format!("Unable to connect to docker at {path}")
})
},
)?
}
#[cfg(target_os = "windows")]
{
return Err(IoError::invalid_data(
"Url",
"Unix socket file is not supported on windows",
));
}
Docker::connect_with_unix(path, 120, API_DEFAULT_VERSION).map_err(
|err| {
err.map_err_context(|| {
format!("Unable to connect to docker at {path}")
})
},
)?
}
docker_host
if docker_host.starts_with("http://")
Expand Down
2 changes: 1 addition & 1 deletion bin/nanocld/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ chrono = { version = "0.4", default-features = false, features = [
"clock",
"serde",
] }
jsonschema = { version = "0.23", default-features = false }
jsonschema = { version = "0.24", default-features = false }
nanocld_client = { version = "0.16", features = ["tokio"] }
metrsd_client = "0.5"
nanocl_stubs = { version = "0.16", features = ["serde", "clap"] }
Expand Down
5 changes: 2 additions & 3 deletions bin/nanocld/src/utils/container/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ pub async fn create(
) -> IoResult<Vec<Process>> {
let data = serde_json::to_string(&cargo)?;
let new_data = super::generic::inject_data(&data, state).await?;
let cargo = serde_json::from_str::<Cargo>(&new_data)?;
let cargo = &serde_json::from_str::<Cargo>(&new_data)?;
super::image::download(
&cargo.spec.container.image.clone().unwrap_or_default(),
cargo.spec.image_pull_secret.clone(),
cargo.spec.image_pull_policy.clone().unwrap_or_default(),
&cargo,
cargo,
state,
)
.await?;
Expand All @@ -157,7 +157,6 @@ pub async fn create(
.collect::<Vec<usize>>()
.into_iter()
.map(move |current| {
let cargo = cargo.clone();
let secret_envs = secret_envs.clone();
async move {
let ordinal_index = if current > 0 {
Expand Down
14 changes: 11 additions & 3 deletions bin/nanocld/src/utils/container/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::{

/// Internal utils to emit an event when the state of a process kind changes
/// Eg: (job, cargo, vm)
///
pub async fn emit(
kind_key: &str,
kind: &ProcessKind,
Expand Down Expand Up @@ -50,6 +51,7 @@ pub async fn emit(

/// Count the status for the given instances
/// Return a tuple with the total, failed, success and running instances
///
pub fn count_status(instances: &[Process]) -> (usize, usize, usize, usize) {
let mut instance_failed = 0;
let mut instance_success = 0;
Expand Down Expand Up @@ -93,6 +95,7 @@ pub fn count_status(instances: &[Process]) -> (usize, usize, usize, usize) {
/// Emit a starting event to the system for the related process object (job, cargo, vm)
/// This will update the status of the process and emit a event
/// So the system start to start the group of processes in the background
///
pub async fn emit_starting(
kind_key: &str,
kind: &ProcessKind,
Expand Down Expand Up @@ -121,6 +124,7 @@ pub async fn emit_starting(
/// Emit a stopping event to the system for the related process object (job, cargo, vm)
/// This will update the status of the process and emit a event
/// So the system start to stop the group of processes in the background
///
pub async fn emit_stopping(
kind_key: &str,
kind: &ProcessKind,
Expand All @@ -144,9 +148,13 @@ pub async fn emit_stopping(
Ok(())
}

/// Inject data into the payload
/// Inject internal data into the payload
/// eg: $$INTERNAL_GATEWAY
pub async fn inject_data(data: &str, state: &SystemState) -> IoResult<String> {
///
pub async fn inject_data(
payload: &str,
state: &SystemState,
) -> IoResult<String> {
let network_gateway = state
.inner
.docker_api
Expand All @@ -167,6 +175,6 @@ pub async fn inject_data(data: &str, state: &SystemState) -> IoResult<String> {
));
};
let gateway_addr = network.gateway.clone().unwrap_or_default();
let new_data = data.replace("$$INTERNAL_GATEWAY", &gateway_addr);
let new_data = payload.replace("$$INTERNAL_GATEWAY", &gateway_addr);
Ok(new_data)
}
4 changes: 3 additions & 1 deletion crates/nanocl_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ serde_json = { version = "1.0", optional = true }
futures = { version = "0.3", optional = true }
utoipa = { version = "4.2", features = ["yaml"], optional = true }
utoipa-swagger-ui = { version = "7.0", optional = true }
libc = { version = "0.2", optional = true }
clap = { version = "4.5", features = ["derive", "cargo"], optional = true }
clap_mangen = { version = "0.2", optional = true }
nanocl_error = { version = "0.5", optional = true }

[target.'cfg(not(target_os = "windows"))'.dependencies]
libc = { version = "0.2", optional = true }
1 change: 1 addition & 0 deletions crates/nanocl_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod ntex;
#[cfg(feature = "logger")]
pub mod logger;

#[cfg(not(target_os = "windows"))]
#[cfg(feature = "unix")]
pub mod unix;

Expand Down
26 changes: 15 additions & 11 deletions crates/nanocld_client/src/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,22 @@ impl NanocldClient {
}

fn gen_client(&self) -> IoResult<http::client::Client> {
#[allow(unused_mut)]
let mut client = http::client::Client::build();
if let Some(unix_socket) = &self.unix_socket {
let unix_socket = unix_socket.clone();
client = client.connector(
http::client::Connector::default()
.connector(ntex::service::fn_service(move |_| {
let unix_socket = unix_socket.clone();
async { Ok::<_, _>(rt::unix_connect(unix_socket).await?) }
}))
.timeout(ntex::time::Millis::from_secs(100))
.finish(),
);
#[cfg(not(target_os = "windows"))]
{
if let Some(unix_socket) = &self.unix_socket {
let unix_socket = unix_socket.clone();
client = client.connector(
http::client::Connector::default()
.connector(ntex::service::fn_service(move |_| {
let unix_socket = unix_socket.clone();
async { Ok::<_, _>(rt::unix_connect(unix_socket).await?) }
}))
.timeout(ntex::time::Millis::from_secs(100))
.finish(),
);
}
}
#[cfg(feature = "openssl")]
{
Expand Down
Loading

0 comments on commit b03a5ff

Please sign in to comment.