mirror of
https://github.com/faas-rs/faasd-in-rust.git
synced 2025-06-08 15:56:48 +00:00
fix(spec):生成spec的时候补充cwd信息 (#75)
This commit is contained in:
parent
e2a95d4fed
commit
c4176723f3
@ -454,9 +454,7 @@ impl ContainerdManager {
|
|||||||
|
|
||||||
fn get_spec(cid: &str, ns: &str, image_name: &str) -> Result<Option<Any>, ContainerdError> {
|
fn get_spec(cid: &str, ns: &str, image_name: &str) -> Result<Option<Any>, ContainerdError> {
|
||||||
let config = ImageManager::get_runtime_config(image_name).unwrap();
|
let config = ImageManager::get_runtime_config(image_name).unwrap();
|
||||||
let env = config.env;
|
let spec_path = generate_spec(cid, ns, &config).map_err(|e| {
|
||||||
let args = config.args;
|
|
||||||
let spec_path = generate_spec(cid, ns, args, env).map_err(|e| {
|
|
||||||
log::error!("Failed to generate spec: {}", e);
|
log::error!("Failed to generate spec: {}", e);
|
||||||
ContainerdError::GenerateSpecError(e.to_string())
|
ContainerdError::GenerateSpecError(e.to_string())
|
||||||
})?;
|
})?;
|
||||||
|
@ -28,11 +28,17 @@ pub struct ImageRuntimeConfig {
|
|||||||
pub env: Vec<String>,
|
pub env: Vec<String>,
|
||||||
pub args: Vec<String>,
|
pub args: Vec<String>,
|
||||||
pub ports: Vec<String>,
|
pub ports: Vec<String>,
|
||||||
|
pub cwd: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ImageRuntimeConfig {
|
impl ImageRuntimeConfig {
|
||||||
pub fn new(env: Vec<String>, args: Vec<String>, ports: Vec<String>) -> Self {
|
pub fn new(env: Vec<String>, args: Vec<String>, ports: Vec<String>, cwd: String) -> Self {
|
||||||
ImageRuntimeConfig { env, args, ports }
|
ImageRuntimeConfig {
|
||||||
|
env,
|
||||||
|
args,
|
||||||
|
ports,
|
||||||
|
cwd,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -387,7 +393,11 @@ impl ImageManager {
|
|||||||
.exposed_ports()
|
.exposed_ports()
|
||||||
.clone()
|
.clone()
|
||||||
.expect("Failed to get exposed ports");
|
.expect("Failed to get exposed ports");
|
||||||
Ok(ImageRuntimeConfig::new(env, args, ports))
|
let cwd = config
|
||||||
|
.working_dir()
|
||||||
|
.clone()
|
||||||
|
.expect("Failed to get working dir");
|
||||||
|
Ok(ImageRuntimeConfig::new(env, args, ports, cwd))
|
||||||
} else {
|
} else {
|
||||||
Err(ImageError::ImageConfigurationNotFound(format!(
|
Err(ImageError::ImageConfigurationNotFound(format!(
|
||||||
"Image configuration is empty for image {}",
|
"Image configuration is empty for image {}",
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
|
||||||
|
use crate::image_manager::ImageRuntimeConfig;
|
||||||
|
|
||||||
// 定义版本的常量
|
// 定义版本的常量
|
||||||
const VERSION_MAJOR: u32 = 1;
|
const VERSION_MAJOR: u32 = 1;
|
||||||
const VERSION_MINOR: u32 = 1;
|
const VERSION_MINOR: u32 = 1;
|
||||||
@ -319,16 +321,16 @@ fn get_netns(ns: &str, cid: &str) -> String {
|
|||||||
pub fn generate_spec(
|
pub fn generate_spec(
|
||||||
id: &str,
|
id: &str,
|
||||||
ns: &str,
|
ns: &str,
|
||||||
args: Vec<String>,
|
runtime_config: &ImageRuntimeConfig,
|
||||||
env: Vec<String>,
|
|
||||||
) -> Result<String, std::io::Error> {
|
) -> Result<String, std::io::Error> {
|
||||||
let namespace = match ns {
|
let namespace = match ns {
|
||||||
"" => DEFAULT_NAMESPACE,
|
"" => DEFAULT_NAMESPACE,
|
||||||
_ => ns,
|
_ => ns,
|
||||||
};
|
};
|
||||||
let mut spec = populate_default_unix_spec(id, ns);
|
let mut spec = populate_default_unix_spec(id, ns);
|
||||||
spec.process.args = args;
|
spec.process.args = runtime_config.args.clone();
|
||||||
spec.process.env = env;
|
spec.process.env = runtime_config.env.clone();
|
||||||
|
spec.process.cwd = runtime_config.cwd.clone();
|
||||||
let dir_path = format!("{}/{}", PATH_TO_SPEC_PREFIX, namespace);
|
let dir_path = format!("{}/{}", PATH_TO_SPEC_PREFIX, namespace);
|
||||||
let path = format!("{}/{}.json", dir_path, id);
|
let path = format!("{}/{}.json", dir_path, id);
|
||||||
std::fs::create_dir_all(&dir_path)?;
|
std::fs::create_dir_all(&dir_path)?;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user