| 962 | } |
| 963 | |
| 964 | pub(crate) fn prepare_work_dir( |
| 965 | &self, |
| 966 | id: &str, |
| 967 | req: &VmConfiguration, |
| 968 | app_id: &str, |
| 969 | ) -> Result<VmWorkDir> { |
| 970 | let work_dir = self.work_dir(id); |
| 971 | let shared_dir = work_dir.join("shared"); |
| 972 | fs::create_dir_all(&shared_dir).context("Failed to create shared directory")?; |
| 973 | fs::write(shared_dir.join(APP_COMPOSE), &req.compose_file) |
| 974 | .context("Failed to write compose file")?; |
| 975 | if !req.encrypted_env.is_empty() { |
| 976 | fs::write(shared_dir.join(ENCRYPTED_ENV), &req.encrypted_env) |
| 977 | .context("Failed to write encrypted env")?; |
| 978 | } |
| 979 | if !req.user_config.is_empty() { |
| 980 | fs::write(shared_dir.join(USER_CONFIG), &req.user_config) |
| 981 | .context("Failed to write user config")?; |
| 982 | } |
| 983 | if !app_id.is_empty() { |
| 984 | let instance_info = json!({ |
| 985 | "app_id": app_id, |
| 986 | }); |
| 987 | fs::write( |
| 988 | shared_dir.join(INSTANCE_INFO), |
| 989 | serde_json::to_string(&instance_info)?, |
| 990 | ) |
| 991 | .context("Failed to write vm config")?; |
| 992 | } |
| 993 | Ok(work_dir) |
| 994 | } |
| 995 | |
| 996 | pub(crate) fn sync_dynamic_config(&self, id: &str) -> Result<()> { |
| 997 | let work_dir = self.work_dir(id); |