@@ -2,9 +2,6 @@ use crate::docker;
2
2
use crate :: types:: { AgentCreationResult , CreateAgentParams } ;
3
3
use crate :: { AgentPortConfig , ServiceContext } ;
4
4
use blueprint_sdk:: logging;
5
- use dockworker:: ComposeConfig ;
6
- use phala_tee_deploy_rs:: PubkeyResponse ;
7
- use std:: collections:: HashMap ;
8
5
use std:: fs;
9
6
use std:: path:: { Path , PathBuf } ;
10
7
use uuid:: Uuid ;
@@ -59,21 +56,16 @@ pub async fn handle_create_agent(
59
56
logging:: warn!( "No agent_ports map available in context" ) ;
60
57
}
61
58
62
- // Create Docker Compose file
63
- let env_vars = HashMap :: new ( ) ; // No additional env vars at creation time
64
- let compose_path = docker:: write_docker_compose_file (
65
- & agent_dir,
66
- & agent_id,
67
- Some ( http_port) ,
68
- Some ( websocket_port) ,
69
- env_vars,
70
- ) ?;
59
+ let compose_path = docker:: write_docker_compose_file ( & agent_dir) ?;
71
60
72
61
// Prepare TEE config if enabled
73
- let pubkey_response = if params. deployment_config . tee_enabled {
74
- get_tee_public_key ( & agent_dir, context) . await ?
62
+ let ( tee_pubkey, tee_app_id) = if params. deployment_config . tee_enabled {
63
+ match get_tee_public_key ( & agent_dir, context) . await ? {
64
+ Some ( ( pubkey, app_id) ) => ( Some ( pubkey) , Some ( app_id) ) ,
65
+ None => ( None , None ) ,
66
+ }
75
67
} else {
76
- None
68
+ ( None , None )
77
69
} ;
78
70
79
71
// Return the result
@@ -84,7 +76,8 @@ pub async fn handle_create_agent(
84
76
agent_dir. join( "package.json" ) . to_string_lossy( ) . to_string( ) ,
85
77
compose_path. to_string_lossy( ) . to_string( ) ,
86
78
] ,
87
- pubkey_response,
79
+ tee_pubkey,
80
+ tee_app_id,
88
81
} ;
89
82
90
83
// Serialize the result
@@ -188,7 +181,7 @@ fn copy_dir_contents(src: &Path, dst: &Path) -> Result<(), String> {
188
181
async fn get_tee_public_key (
189
182
agent_dir : & Path ,
190
183
context : & ServiceContext ,
191
- ) -> Result < Option < PubkeyResponse > , String > {
184
+ ) -> Result < Option < ( String , String ) > , String > {
192
185
// Get API key directly from context
193
186
let tee_api_key = context
194
187
. phala_tee_api_key
@@ -218,24 +211,17 @@ async fn get_tee_public_key(
218
211
let docker_compose = fs:: read_to_string ( & docker_compose_path)
219
212
. map_err ( |e| format ! ( "Failed to read docker-compose.yml: {}" , e) ) ?;
220
213
221
- // Create VM configuration using TeeDeployer's native method
222
- logging:: info!(
223
- "Creating VM configuration from Docker Compose {:#?}" ,
224
- docker_compose
225
- ) ;
226
-
227
- // Parse docker-compose.yml to ComposeConfig using dockworker
228
- let compose_config: ComposeConfig = serde_yaml:: from_str ( & docker_compose)
229
- . map_err ( |e| format ! ( "Failed to parse docker-compose.yml: {}" , e) ) ?;
214
+ // Normalize the Docker Compose file to ensure consistent ordering
215
+ let docker_compose = docker:: normalize_docker_compose ( & docker_compose) ?;
230
216
231
- // Use TeeDeployer's built-in create_vm_config method
232
217
let app_name = format ! (
233
218
"coinbase-agent-{}" ,
234
219
agent_dir. file_name( ) . unwrap( ) . to_string_lossy( )
235
220
) ;
221
+
236
222
let vm_config = deployer
237
223
. create_vm_config (
238
- & compose_config ,
224
+ & docker_compose ,
239
225
& app_name,
240
226
Some ( 2 ) , // vcpu
241
227
Some ( 2048 ) , // memory in MB
@@ -244,20 +230,24 @@ async fn get_tee_public_key(
244
230
. map_err ( |e| format ! ( "Failed to create VM configuration: {}" , e) ) ?;
245
231
246
232
// Get the public key for this VM configuration
233
+ let vm_config_json = serde_json:: to_value ( vm_config)
234
+ . map_err ( |e| format ! ( "Failed to serialize VM configuration: {}" , e) ) ?;
247
235
logging:: info!(
248
- "Requesting encryption public key with config {:#?}" ,
249
- vm_config
236
+ "Requesting encryption public key with VM Config: {:#?}" ,
237
+ vm_config_json
250
238
) ;
251
- let vm_config_json = serde_json:: to_value ( & vm_config) . unwrap ( ) ;
252
239
let pubkey_response = deployer
253
240
. get_pubkey_for_config ( & vm_config_json)
254
241
. await
255
242
. map_err ( |e| format ! ( "Failed to get TEE public key: {}" , e) ) ?;
256
243
257
- logging:: info!( "Pubkey response: {:#?}" , pubkey_response) ;
244
+ // Extract the pubkey and salt from the response
245
+ let pubkey = pubkey_response. app_env_encrypt_pubkey ;
246
+ let salt = pubkey_response. app_id_salt ;
247
+
258
248
logging:: info!( "Successfully obtained TEE public key" ) ;
259
249
260
- Ok ( Some ( pubkey_response ) )
250
+ Ok ( Some ( ( pubkey , salt ) ) )
261
251
}
262
252
263
253
/// Creates a .env file with the necessary environment variables
0 commit comments