Compare commits
No commits in common. "6a1e70c484fea168d05d193d6408bfa9d798b8bb" and "8a8ead17cb199e74761dfff71203ffb4c9826c36" have entirely different histories.
6a1e70c484
...
8a8ead17cb
45
examples/containers/nerdctl_install.rhai
Normal file
45
examples/containers/nerdctl_install.rhai
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
fn nerdctl_download(){
|
||||||
|
let name="nerdctl";
|
||||||
|
let url="https://github.com/containerd/nerdctl/releases/download/v2.1.2/nerdctl-2.1.2-linux-amd64.tar.gz";
|
||||||
|
download(url,`/tmp/${name}`,10000);
|
||||||
|
copy_bin(`/tmp/${name}/*`);
|
||||||
|
delete(`/tmp/${name}`);
|
||||||
|
|
||||||
|
let name="containerd";
|
||||||
|
let url="https://github.com/containerd/containerd/releases/download/v2.1.2/containerd-2.1.2-linux-amd64.tar.gz";
|
||||||
|
download(url,`/tmp/${name}`,20000);
|
||||||
|
copy_bin(`/tmp/${name}/bin/*`);
|
||||||
|
delete(`/tmp/${name}`);
|
||||||
|
|
||||||
|
run("apt-get -y install buildah runc");
|
||||||
|
|
||||||
|
// let url="https://github.com/threefoldtech/rfs/releases/download/v2.0.6/rfs";
|
||||||
|
// download_file(url,`/tmp/rfs`,10000);
|
||||||
|
// chmod_exec("/tmp/rfs");
|
||||||
|
// mv(`/tmp/rfs`,"/root/hero/bin/");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ipfs_download(){
|
||||||
|
let name="ipfs";
|
||||||
|
let url="https://github.com/ipfs/kubo/releases/download/v0.34.1/kubo_v0.34.1_linux-amd64.tar.gz";
|
||||||
|
download(url,`/tmp/${name}`,20);
|
||||||
|
copy(`/tmp/${name}/kubo/ipfs`,"/root/hero/bin/ipfs");
|
||||||
|
// delete(`/tmp/${name}`);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
let d=download(`https://git.threefold.info/herocode/sal/raw/branch/main/examples/containers/nerdctl_install.rhai`,`/tmp/nerdctl_install.rhai`,0);
|
||||||
|
|
||||||
|
print(`Repo path: ${d}`);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// nerdctl_download();
|
||||||
|
// ipfs_download();
|
||||||
|
|
||||||
|
"done"
|
@ -19,7 +19,9 @@ fn zinit(){
|
|||||||
download_file(url,`/tmp/${name}`,5000);
|
download_file(url,`/tmp/${name}`,5000);
|
||||||
copy_bin(`/tmp/${name}`);
|
copy_bin(`/tmp/${name}`);
|
||||||
delete(`/tmp/${name}`);
|
delete(`/tmp/${name}`);
|
||||||
screen_new("zinit", "zinit init");
|
|
||||||
|
let name="containerd";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
platform_check_linux_x86();
|
platform_check_linux_x86();
|
||||||
|
@ -14,9 +14,7 @@ fn nerdctl_download(){
|
|||||||
copy_bin(`/tmp/${name}/bin/*`);
|
copy_bin(`/tmp/${name}/bin/*`);
|
||||||
delete(`/tmp/${name}`);
|
delete(`/tmp/${name}`);
|
||||||
|
|
||||||
package_install("buildah");
|
run("apt-get -y install buildah runc");
|
||||||
package_install("runc");
|
|
||||||
|
|
||||||
|
|
||||||
// let url="https://github.com/threefoldtech/rfs/releases/download/v2.0.6/rfs";
|
// let url="https://github.com/threefoldtech/rfs/releases/download/v2.0.6/rfs";
|
||||||
// download_file(url,`/tmp/rfs`,10000);
|
// download_file(url,`/tmp/rfs`,10000);
|
||||||
|
@ -12,10 +12,8 @@
|
|||||||
|
|
||||||
mod run;
|
mod run;
|
||||||
mod mgmt;
|
mod mgmt;
|
||||||
mod screen;
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
pub use run::*;
|
pub use run::*;
|
||||||
pub use mgmt::*;
|
pub use mgmt::*;
|
||||||
pub use screen::{new as new_screen, kill as kill_screen};
|
|
@ -1,48 +0,0 @@
|
|||||||
use crate::process::run_command;
|
|
||||||
use anyhow::Result;
|
|
||||||
use std::fs;
|
|
||||||
|
|
||||||
/// Executes a command in a new screen session.
|
|
||||||
///
|
|
||||||
/// # Arguments
|
|
||||||
///
|
|
||||||
/// * `name` - The name of the screen session.
|
|
||||||
/// * `cmd` - The command to execute.
|
|
||||||
///
|
|
||||||
/// # Returns
|
|
||||||
///
|
|
||||||
/// * `Result<()>` - Ok if the command was executed successfully, otherwise an error.
|
|
||||||
pub fn new(name: &str, cmd: &str) -> Result<()> {
|
|
||||||
let script_path = format!("/tmp/cmd_{}.sh", name);
|
|
||||||
let mut script_content = String::new();
|
|
||||||
|
|
||||||
if !cmd.starts_with("#!") {
|
|
||||||
script_content.push_str("#!/bin/bash\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
script_content.push_str("set -e\n");
|
|
||||||
script_content.push_str(cmd);
|
|
||||||
|
|
||||||
fs::write(&script_path, script_content)?;
|
|
||||||
fs::set_permissions(&script_path, std::os::unix::fs::PermissionsExt::from_mode(0o755))?;
|
|
||||||
|
|
||||||
let screen_cmd = format!("screen -d -m -S {} {}", name, script_path);
|
|
||||||
run_command(&screen_cmd)?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Kills a screen session.
|
|
||||||
///
|
|
||||||
/// # Arguments
|
|
||||||
///
|
|
||||||
/// * `name` - The name of the screen session to kill.
|
|
||||||
///
|
|
||||||
/// # Returns
|
|
||||||
///
|
|
||||||
/// * `Result<()>` - Ok if the session was killed successfully, otherwise an error.
|
|
||||||
pub fn kill(name: &str) -> Result<()> {
|
|
||||||
let cmd = format!("screen -S {} -X quit", name);
|
|
||||||
run_command(&cmd)?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
@ -14,7 +14,6 @@ mod postgresclient;
|
|||||||
mod process;
|
mod process;
|
||||||
mod redisclient;
|
mod redisclient;
|
||||||
mod rfs;
|
mod rfs;
|
||||||
mod screen;
|
|
||||||
mod vault;
|
mod vault;
|
||||||
mod text;
|
mod text;
|
||||||
mod zinit;
|
mod zinit;
|
||||||
@ -186,9 +185,6 @@ pub fn register(engine: &mut Engine) -> Result<(), Box<rhai::EvalAltResult>> {
|
|||||||
|
|
||||||
// Register Platform module functions
|
// Register Platform module functions
|
||||||
platform::register(engine);
|
platform::register(engine);
|
||||||
|
|
||||||
// Register Screen module functions
|
|
||||||
screen::register(engine);
|
|
||||||
|
|
||||||
// Register utility functions
|
// Register utility functions
|
||||||
engine.register_fn("is_def_fn", |_name: &str| -> bool {
|
engine.register_fn("is_def_fn", |_name: &str| -> bool {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
//!
|
//!
|
||||||
//! This module provides Rhai wrappers for the functions in the Process module.
|
//! This module provides Rhai wrappers for the functions in the Process module.
|
||||||
|
|
||||||
use crate::process::{self, CommandResult, ProcessError, ProcessInfo, RunError };
|
use crate::process::{self, CommandResult, ProcessError, ProcessInfo, RunError};
|
||||||
use rhai::{Array, Dynamic, Engine, EvalAltResult, Map};
|
use rhai::{Array, Dynamic, Engine, EvalAltResult, Map};
|
||||||
use std::clone::Clone;
|
use std::clone::Clone;
|
||||||
|
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
use crate::process::{new_screen, kill_screen};
|
|
||||||
use rhai::{Engine, Module, EvalAltResult};
|
|
||||||
|
|
||||||
fn screen_error_to_rhai_error<T>(result: anyhow::Result<T>) -> Result<T, Box<EvalAltResult>> {
|
|
||||||
result.map_err(|e| {
|
|
||||||
Box::new(EvalAltResult::ErrorRuntime(
|
|
||||||
format!("Screen error: {}", e).into(),
|
|
||||||
rhai::Position::NONE,
|
|
||||||
))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn register(engine: &mut Engine) {
|
|
||||||
engine.register_fn("screen_new", |name: &str, cmd: &str| {
|
|
||||||
screen_error_to_rhai_error(new_screen(name, cmd))
|
|
||||||
});
|
|
||||||
|
|
||||||
engine.register_fn("screen_kill", |name: &str| {
|
|
||||||
screen_error_to_rhai_error(kill_screen(name))
|
|
||||||
});
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user