refactor: create container
return mapped ports and container id to client docker container name uuid for delete
This commit is contained in:
		
							parent
							
								
									c6bb7f5ab1
								
							
						
					
					
						commit
						ee31ee5e6b
					
				
							
								
								
									
										2
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										2
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							| @ -316,7 +316,7 @@ dependencies = [ | |||||||
| [[package]] | [[package]] | ||||||
| name = "detee-shared" | name = "detee-shared" | ||||||
| version = "0.1.0" | version = "0.1.0" | ||||||
| source = "git+ssh://git@gitea.detee.cloud/noormohammedb/detee-shared#3cb47a47e824edb4df8f2057f3d9dfa2a04f9e76" | source = "git+ssh://git@gitea.detee.cloud/noormohammedb/detee-shared#bb553f08af6178d1b0da57234311eaf2809ca648" | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "base64", |  "base64", | ||||||
|  "prost", |  "prost", | ||||||
|  | |||||||
							
								
								
									
										15
									
								
								src/data.rs
									
									
									
									
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										15
									
								
								src/data.rs
									
									
									
									
									
								
							| @ -28,26 +28,25 @@ impl DaemonState { | |||||||
| 
 | 
 | ||||||
|     pub async fn create_new_container( |     pub async fn create_new_container( | ||||||
|         &mut self, |         &mut self, | ||||||
|         ip: String, |  | ||||||
|         req_data: ContainerConfig, |         req_data: ContainerConfig, | ||||||
|         unarchive_dir: String, |         unarchive_dir: String, | ||||||
|     ) -> Result<(), Box<dyn std::error::Error>> { |     ) -> Result<Vec<(u16, u16)>, Box<dyn std::error::Error>> { | ||||||
|         let publishing_ports = req_data.resource.clone().unwrap().port; |         let publishing_ports = req_data.resource.clone().unwrap().port; | ||||||
| 
 |         let uuid = req_data.uuid.unwrap_or_default().uuid; | ||||||
|         let mapped_ports = deploy_enclave(&unarchive_dir, publishing_ports).await?; |         let mapped_ports = deploy_enclave(&unarchive_dir, uuid.clone(), publishing_ports).await?; | ||||||
| 
 | 
 | ||||||
|         let container = Container { |         let container = Container { | ||||||
|             uuid: req_data.uuid.unwrap_or_default().uuid, |             uuid, | ||||||
|             name: "".to_string(), |             name: "".to_string(), | ||||||
|             package_path: unarchive_dir, |             package_path: unarchive_dir, | ||||||
|             status: "running".to_string(), |             status: "running".to_string(), | ||||||
|             admin: ip, |             admin: req_data.admin_pubkey, | ||||||
|             container_resource: req_data.resource.unwrap(), |             container_resource: req_data.resource.unwrap(), | ||||||
|             mapped_ports, |             mapped_ports: mapped_ports.clone(), | ||||||
|         }; |         }; | ||||||
| 
 | 
 | ||||||
|         self.containers.push(container); |         self.containers.push(container); | ||||||
| 
 | 
 | ||||||
|         Ok(()) |         Ok(mapped_ports) | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										20
									
								
								src/grpc.rs
									
									
									
									
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										20
									
								
								src/grpc.rs
									
									
									
									
									
								
							| @ -52,7 +52,6 @@ impl DaemonServicePB for DaemonServer { | |||||||
|         &self, |         &self, | ||||||
|         request: tonic::Request<ContainerPB>, |         request: tonic::Request<ContainerPB>, | ||||||
|     ) -> Result<tonic::Response<NewContainerRes>, tonic::Status> { |     ) -> Result<tonic::Response<NewContainerRes>, tonic::Status> { | ||||||
|         let req_ip = request.remote_addr().unwrap().to_string(); |  | ||||||
|         let req_data = request.into_inner(); |         let req_data = request.into_inner(); | ||||||
| 
 | 
 | ||||||
|         if req_data.package_url.is_none() || req_data.resource.is_none() { |         if req_data.package_url.is_none() || req_data.resource.is_none() { | ||||||
| @ -64,19 +63,32 @@ impl DaemonServicePB for DaemonServer { | |||||||
| 
 | 
 | ||||||
|         let req_container = ContainerConfig::decode(&req_data.encode_to_vec()[..]).unwrap(); |         let req_container = ContainerConfig::decode(&req_data.encode_to_vec()[..]).unwrap(); | ||||||
| 
 | 
 | ||||||
|         self.data |         let mapped_ports = self | ||||||
|  |             .data | ||||||
|             .write() |             .write() | ||||||
|             .await |             .await | ||||||
|             .create_new_container(req_ip, req_container, unarchive_dir) |             .create_new_container(req_container, unarchive_dir) | ||||||
|             .await |             .await | ||||||
|             .map_err(|err| tonic::Status::internal(err.to_string()))?; |             .map_err(|err| tonic::Status::internal(err.to_string()))?; | ||||||
| 
 | 
 | ||||||
|  |         let mapped_ports = mapped_ports | ||||||
|  |             .into_iter() | ||||||
|  |             .map(|(host, container)| detee_shared::pb::shared::MappedPort { | ||||||
|  |                 host_port: host.into(), | ||||||
|  |                 container_port: container.into(), | ||||||
|  |             }) | ||||||
|  |             .collect(); | ||||||
|  | 
 | ||||||
|         return Ok(tonic::Response::new(NewContainerRes { |         return Ok(tonic::Response::new(NewContainerRes { | ||||||
|             container_id: None, |             container_id: Some(detee_shared::pb::shared::Uuid { | ||||||
|  |                 uuid: req_data.uuid.unwrap_or_default().uuid, | ||||||
|  |             }), | ||||||
|             status: "success".to_string(), |             status: "success".to_string(), | ||||||
|             ip_address: "".to_string(), |             ip_address: "".to_string(), | ||||||
|  |             mapped_ports, | ||||||
|         })); |         })); | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|     async fn inspect_container( |     async fn inspect_container( | ||||||
|         &self, |         &self, | ||||||
|         req: tonic::Request<detee_shared::pb::shared::Uuid>, |         req: tonic::Request<detee_shared::pb::shared::Uuid>, | ||||||
|  | |||||||
| @ -42,7 +42,7 @@ pub async fn handle_package(package_url: String) -> Result<String> { | |||||||
| 
 | 
 | ||||||
| pub async fn deploy_enclave( | pub async fn deploy_enclave( | ||||||
|     enclave_path: &str, |     enclave_path: &str, | ||||||
|     // enclave_name: String,
 |     container_name_uuid: String, | ||||||
|     publishing_ports: Vec<u32>, |     publishing_ports: Vec<u32>, | ||||||
|     // ...
 |     // ...
 | ||||||
| ) -> Result<Vec<(u16, u16)>, Box<dyn std::error::Error>> { | ) -> Result<Vec<(u16, u16)>, Box<dyn std::error::Error>> { | ||||||
| @ -56,8 +56,8 @@ pub async fn deploy_enclave( | |||||||
| 
 | 
 | ||||||
|     println!("Deploying enclave: {:?}", enclave_path); |     println!("Deploying enclave: {:?}", enclave_path); | ||||||
|     let docker_deploy_str = format!( |     let docker_deploy_str = format!( | ||||||
|         r#"docker run -v {enclave_path}/enclave_packager:/enclave_packager --device /dev/sgx/enclave \ |         r#"docker run --name dtpm-{container_name_uuid} -v {enclave_path}/enclave_packager:/enclave_packager \ | ||||||
|         --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"#
 | ||||||
|     ); |     ); | ||||||
| 
 | 
 | ||||||
|     println!("{}", &docker_deploy_str); |     println!("{}", &docker_deploy_str); | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user