Skip to content

Commit

Permalink
chore/nanocld: event based actions (#813)
Browse files Browse the repository at this point in the history
* chore/nanocld: taskmanager
  • Loading branch information
leon3s authored Jan 27, 2024
1 parent 824b32d commit 448da10
Show file tree
Hide file tree
Showing 77 changed files with 1,305 additions and 2,404 deletions.
2 changes: 0 additions & 2 deletions .config/nextest.toml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ target/
test_local/
.vagrant/
tests/ubuntu-22.04-minimal-cloudimg-amd64.img
lcov.info
36 changes: 29 additions & 7 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"editor.rulers": [
80
],
"editor.rulers": [80],
"editor.tabSize": 2,
"editor.detectIndentation": false,
"editor.trimAutoWhitespace": true,
Expand All @@ -12,8 +10,32 @@
"rust-analyzer.checkOnSave": true,
"rust-analyzer.check.command": "clippy",
"rust-analyzer.cargo.noDefaultFeatures": true,
"rust-analyzer.cargo.features": [
"dev",
"test"
],
"rust-analyzer.cargo.features": ["dev", "test"],
"cSpell.words": [
"aarch",
"canonicalize",
"certbot",
"chrono",
"cpus",
"crond",
"curr",
"dialoguer",
"dotenv",
"dotenvy",
"errno",
"iface",
"Insertable",
"keygen",
"metrs",
"Metrsd",
"nanocl",
"Nanocld",
"ncproxy",
"nstore",
"ntex",
"qcow",
"schemars",
"statefile",
"utoipa"
]
}
10 changes: 6 additions & 4 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ args = [
"--no-default-features",
"--features",
"test",
"-j",
"--output-path",
"./lcov.info",
"--lcov",
"--",
"--test-threads",
"1",
]

Expand All @@ -163,9 +167,7 @@ args = [
"--no-default-features",
"--features",
"test",
"--output-path",
"./lcov.info",
"--lcov",
"--html",
"--",
"--test-threads",
"1",
Expand Down
4 changes: 0 additions & 4 deletions bin/nanocl/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ pub fn generate_man_pages() -> Result<()> {
name: "nanocl-cargo",
command: CargoArg::command(),
},
ManPage {
name: "nanocl-cargo-image",
command: CargoImageArg::command(),
},
ManPage {
name: "nanocl-cargo-run",
command: CargoRunOpts::command(),
Expand Down
31 changes: 13 additions & 18 deletions bin/nanocl/src/commands/cargo.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
use std::process;
use std::collections::HashMap;

use nanocld_client::stubs::generic::{GenericFilter, GenericListNspQuery};
use ntex::rt;
use futures::channel::mpsc;
use futures::{StreamExt, SinkExt};
use futures::stream::FuturesUnordered;
use bollard_next::exec::{CreateExecOptions, StartExecOptions};

use nanocl_error::io::{FromIo, IoResult};
use nanocld_client::stubs::process::{OutputKind, ProcessLogQuery};
use nanocld_client::stubs::cargo::{
CargoDeleteQuery, CargoStatsQuery, CargoSummary,
use nanocld_client::{
stubs::process::{OutputKind, ProcessLogQuery},
stubs::generic::{GenericFilter, GenericListNspQuery},
stubs::cargo::{CargoDeleteQuery, CargoStatsQuery, CargoSummary},
};

use crate::utils;
use crate::config::CliConfig;
use crate::models::{
CargoArg, CargoCreateOpts, CargoCommand, CargoRemoveOpts, CargoRow,
CargoStartOpts, CargoStopOpts, CargoPatchOpts, CargoInspectOpts,
CargoExecOpts, CargoHistoryOpts, CargoRevertOpts, CargoLogsOpts,
CargoRunOpts, CargoRestartOpts, CargoStatsOpts, CargoStatsRow,
use crate::{
utils,
config::CliConfig,
models::{
CargoArg, CargoCreateOpts, CargoCommand, CargoRemoveOpts, CargoRow,
CargoStartOpts, CargoStopOpts, CargoPatchOpts, CargoInspectOpts,
CargoExecOpts, CargoHistoryOpts, CargoRevertOpts, CargoLogsOpts,
CargoRunOpts, CargoRestartOpts, CargoStatsOpts, CargoStatsRow,
},
};

use super::GenericList;
use super::cargo_image::{exec_cargo_image, exec_cargo_image_pull};

impl GenericList for CargoArg {
type Item = CargoRow;
Expand Down Expand Up @@ -328,10 +329,6 @@ async fn exec_cargo_run(
opts: &CargoRunOpts,
) -> IoResult<()> {
let client = &cli_conf.client;
// Image is not existing so we donwload it
if client.inspect_cargo_image(&opts.image).await.is_err() {
exec_cargo_image_pull(client, &opts.image).await?;
}
let cargo = client
.create_cargo(&opts.clone().into(), args.namespace.as_deref())
.await?;
Expand All @@ -343,14 +340,12 @@ async fn exec_cargo_run(

/// Function that execute when running `nanocl cargo`
pub async fn exec_cargo(cli_conf: &CliConfig, args: &CargoArg) -> IoResult<()> {
let client = &cli_conf.client;
match &args.command {
CargoCommand::List(opts) => {
CargoArg::exec_ls(&cli_conf.client, args, opts).await
}
CargoCommand::Create(opts) => exec_cargo_create(cli_conf, args, opts).await,
CargoCommand::Remove(opts) => exec_cargo_rm(cli_conf, args, opts).await,
CargoCommand::Image(opts) => exec_cargo_image(client, opts).await,
CargoCommand::Start(opts) => exec_cargo_start(cli_conf, args, opts).await,
CargoCommand::Stop(opts) => exec_cargo_stop(cli_conf, args, opts).await,
CargoCommand::Patch(opts) => exec_cargo_patch(cli_conf, args, opts).await,
Expand Down
209 changes: 0 additions & 209 deletions bin/nanocl/src/commands/cargo_image.rs

This file was deleted.

2 changes: 1 addition & 1 deletion bin/nanocl/src/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
/// 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::interupted("Unable to get $HOME env variable", &err.to_string())
IoError::interrupted("Unable to get $HOME env variable", &err.to_string())
})?;
let detected_host = utils::docker::detect_docker_host()?;
let (docker_host, is_docker_desktop) = match &args.docker_host {
Expand Down
Loading

0 comments on commit 448da10

Please sign in to comment.