fix for new packaging type
fix tokio blocking code panic get top level dir from archive
This commit is contained in:
parent
ec64852762
commit
e9063cba61
@ -2,7 +2,7 @@ use anyhow::{anyhow, Result};
|
|||||||
use log::info;
|
use log::info;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
pub async fn deploy_enclave(
|
pub fn deploy_enclave(
|
||||||
enclave_path: &str,
|
enclave_path: &str,
|
||||||
container_name_uuid: String,
|
container_name_uuid: String,
|
||||||
port_map: Vec<(u16, u16)>,
|
port_map: Vec<(u16, u16)>,
|
||||||
@ -15,7 +15,7 @@ pub async fn deploy_enclave(
|
|||||||
|
|
||||||
info!("Deploying enclave: {:?}", enclave_path);
|
info!("Deploying enclave: {:?}", enclave_path);
|
||||||
let docker_deploy_str = format!(
|
let docker_deploy_str = format!(
|
||||||
r#"docker run -d --name {container_name_uuid} -v {enclave_path}/enclave_packager:/enclave_packager \
|
r#"docker run -d --name {container_name_uuid} -v {enclave_path}:/enclave_packager \
|
||||||
--device /dev/sgx/enclave --device /dev/sgx/provision {port_maping_string} noormohammedb/occlum-enclave:v1"#
|
--device /dev/sgx/enclave --device /dev/sgx/provision {port_maping_string} noormohammedb/occlum-enclave:v1"#
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -119,11 +119,10 @@ impl App {
|
|||||||
let mapped_ports = prepare_port_map(new_app_req.resource.port.clone()).await;
|
let mapped_ports = prepare_port_map(new_app_req.resource.port.clone()).await;
|
||||||
let app_name = format!("{APP_NAME_PREFIX}-{app_uuid}");
|
let app_name = format!("{APP_NAME_PREFIX}-{app_uuid}");
|
||||||
|
|
||||||
let unarchive_dir =
|
let package_path =
|
||||||
handle_package(package_url, app_uuid.clone(), host_config.delete_archive).await?;
|
handle_package(package_url, app_uuid.clone(), host_config.delete_archive).await?;
|
||||||
|
|
||||||
let exit_code =
|
let exit_code = deploy_enclave(&package_path, app_name.clone(), mapped_ports.clone())?;
|
||||||
deploy_enclave(&unarchive_dir, app_name.clone(), mapped_ports.clone()).await?;
|
|
||||||
|
|
||||||
if exit_code != 0 {
|
if exit_code != 0 {
|
||||||
// TODO: cleanup unarchive_dir
|
// TODO: cleanup unarchive_dir
|
||||||
@ -133,7 +132,7 @@ impl App {
|
|||||||
let app_instance = Self {
|
let app_instance = Self {
|
||||||
uuid: app_uuid,
|
uuid: app_uuid,
|
||||||
name: app_name,
|
name: app_name,
|
||||||
package_path: unarchive_dir,
|
package_path,
|
||||||
status: "running".to_string(),
|
status: "running".to_string(),
|
||||||
admin_pubkey: new_app_req.admin_pubkey,
|
admin_pubkey: new_app_req.admin_pubkey,
|
||||||
app_resource: new_app_req.resource,
|
app_resource: new_app_req.resource,
|
||||||
|
@ -13,7 +13,8 @@ pub const APP_NAME_PREFIX: &str = "dtpm";
|
|||||||
|
|
||||||
const DETEE_DIR_ENV_NAME: &str = "DETEE_DIR";
|
const DETEE_DIR_ENV_NAME: &str = "DETEE_DIR";
|
||||||
|
|
||||||
pub static IP_INFO: LazyLock<IPInfo> = LazyLock::new(|| get_ip_info().unwrap());
|
pub static IP_INFO: LazyLock<IPInfo> =
|
||||||
|
LazyLock::new(|| tokio::task::block_in_place(|| get_ip_info().unwrap()));
|
||||||
|
|
||||||
pub static USED_RESOURCES_PATH: LazyLock<String> = LazyLock::new(|| {
|
pub static USED_RESOURCES_PATH: LazyLock<String> = LazyLock::new(|| {
|
||||||
let home = home::home_dir().unwrap().to_string_lossy().into_owned();
|
let home = home::home_dir().unwrap().to_string_lossy().into_owned();
|
||||||
|
25
src/utils.rs
25
src/utils.rs
@ -35,15 +35,36 @@ pub async fn handle_package(
|
|||||||
return Err(anyhow!("Error: file not an archive: {er:?}"));
|
return Err(anyhow!("Error: file not an archive: {er:?}"));
|
||||||
};
|
};
|
||||||
|
|
||||||
let unarchive_dir = format!("{PACKAGE_DIR_PATH}/{}", container_uuid);
|
let unarchive_dir = format!("{PACKAGE_DIR_PATH}/{container_uuid}");
|
||||||
fs::create_dir_all(Path::new(&unarchive_dir)).await?;
|
fs::create_dir_all(Path::new(&unarchive_dir)).await?;
|
||||||
|
|
||||||
|
let top_level_directory = get_top_level_dir(file_path.to_string_lossy().to_string())
|
||||||
|
.ok_or(anyhow!("Error: failed get toplevel directory"))?;
|
||||||
|
|
||||||
archive.unpack(&unarchive_dir)?;
|
archive.unpack(&unarchive_dir)?;
|
||||||
|
|
||||||
if delete_archive {
|
if delete_archive {
|
||||||
let _ = fs::remove_file(file_path).await;
|
let _ = fs::remove_file(file_path).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(unarchive_dir)
|
Ok(format!("{unarchive_dir}/{top_level_directory}"))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_top_level_dir(file_path: String) -> Option<String> {
|
||||||
|
let file = std::fs::File::open(file_path).ok()?;
|
||||||
|
let reader = BufReader::new(file);
|
||||||
|
let mut archive = Archive::new(GzDecoder::new(reader));
|
||||||
|
|
||||||
|
archive.entries().ok()?.flatten().find_map(|entry| {
|
||||||
|
entry
|
||||||
|
.path()
|
||||||
|
.ok()?
|
||||||
|
.components()
|
||||||
|
.next()?
|
||||||
|
.as_os_str()
|
||||||
|
.to_str()
|
||||||
|
.map(String::from)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn download_file(url: &str, file_path: &Path) -> Result<(), Box<dyn std::error::Error>> {
|
pub async fn download_file(url: &str, file_path: &Path) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
Loading…
Reference in New Issue
Block a user