feature/smbcloud-deploy
claude/smbcloud-github-app-k9641p
development
feature/apps
feature/build-release
feature/ci-docs
feature/ci-ruby-gems
feature/cicd
feature/completion
feature/dist-nuget
feature/fix-ci-sdk-pypi-rubygem
feature/fix-clippy-on-stable-channel
feature/fix-deployment-script
feature/github-email
feature/gresiq-v1
feature/project-new-structure
feature/rsync-deploy
feature/ruby-runner
feature/sdk-npm
feature/sdk-workflows
feature/smbcloud-cli-release-npm
feature/smbcloud-deploy
feature/wasm
main
release/v0.7.4
| 1 | use { |
| 2 | crate::{project::DeploymentMethod, runner::Runner}, |
| 3 | serde::{Deserialize, Serialize}, |
| 4 | }; |
| 5 | |
| 6 | /// Server-side deploy configuration returned by the API. |
| 7 | /// |
| 8 | /// The CLI fetches this from `GET /v1/frontend_apps/{id}/deploy_config` |
| 9 | /// and merges the populated fields into the local `.smb/config.toml`. |
| 10 | #[derive(Debug, Serialize, Deserialize, Clone)] |
| 11 | pub struct DeployConfig { |
| 12 | pub id: String, |
| 13 | pub name: String, |
| 14 | pub runner: Runner, |
| 15 | pub deployment_method: DeploymentMethod, |
| 16 | #[serde(default)] |
| 17 | pub source_path: Option<String>, |
| 18 | #[serde(default)] |
| 19 | pub kind: Option<String>, |
| 20 | #[serde(default)] |
| 21 | pub remote_path: Option<String>, |
| 22 | #[serde(default)] |
| 23 | pub output_path: Option<String>, |
| 24 | #[serde(default)] |
| 25 | pub build_command: Option<String>, |
| 26 | #[serde(default)] |
| 27 | pub install_command: Option<String>, |
| 28 | #[serde(default)] |
| 29 | pub binary_name: Option<String>, |
| 30 | #[serde(default)] |
| 31 | pub build_target: Option<String>, |
| 32 | #[serde(default)] |
| 33 | pub package_manager: Option<String>, |
| 34 | #[serde(default)] |
| 35 | pub pm2_app: Option<String>, |
| 36 | #[serde(default)] |
| 37 | pub pm2_env: Option<std::collections::HashMap<String, serde_json::Value>>, |
| 38 | #[serde(default)] |
| 39 | pub port: Option<u16>, |
| 40 | #[serde(default)] |
| 41 | pub shared_lib_path: Option<String>, |
| 42 | #[serde(default)] |
| 43 | pub project_id: Option<i32>, |
| 44 | #[serde(default)] |
| 45 | pub deploy_repo_id: Option<i64>, |
| 46 | #[serde(default)] |
| 47 | pub repository: Option<String>, |
| 48 | } |
| 49 | |
| 50 | #[cfg(test)] |
| 51 | mod tests { |
| 52 | use super::*; |
| 53 | |
| 54 | #[test] |
| 55 | fn deserializes_full_deploy_config() { |
| 56 | let json = r#"{ |
| 57 | "id": "80b309e8-c39a-45b6-9121-e616fde3cd42", |
| 58 | "name": "onde-cloud", |
| 59 | "runner": 0, |
| 60 | "deployment_method": 1, |
| 61 | "source_path": ".", |
| 62 | "kind": "rust", |
| 63 | "remote_path": "apps/rest-api/onde-cloud", |
| 64 | "output_path": null, |
| 65 | "build_command": null, |
| 66 | "install_command": null, |
| 67 | "binary_name": "onde-cloud", |
| 68 | "build_target": "x86_64-unknown-linux-gnu", |
| 69 | "package_manager": null, |
| 70 | "pm2_app": null, |
| 71 | "port": 8090, |
| 72 | "shared_lib_path": null, |
| 73 | "project_id": 50, |
| 74 | "deploy_repo_id": 18, |
| 75 | "repository": "test" |
| 76 | }"#; |
| 77 | |
| 78 | let config: DeployConfig = serde_json::from_str(json).expect("should deserialize"); |
| 79 | assert_eq!(config.id, "80b309e8-c39a-45b6-9121-e616fde3cd42"); |
| 80 | assert_eq!(config.kind.as_deref(), Some("rust")); |
| 81 | assert_eq!( |
| 82 | config.remote_path.as_deref(), |
| 83 | Some("apps/rest-api/onde-cloud") |
| 84 | ); |
| 85 | assert_eq!(config.binary_name.as_deref(), Some("onde-cloud")); |
| 86 | assert_eq!( |
| 87 | config.build_target.as_deref(), |
| 88 | Some("x86_64-unknown-linux-gnu") |
| 89 | ); |
| 90 | assert_eq!(config.port, Some(8090)); |
| 91 | assert_eq!(config.runner, Runner::NodeJs); |
| 92 | } |
| 93 | |
| 94 | #[test] |
| 95 | fn deserializes_minimal_deploy_config() { |
| 96 | let json = r#"{ |
| 97 | "id": "abc-123", |
| 98 | "name": "my-app", |
| 99 | "runner": 4, |
| 100 | "deployment_method": 0 |
| 101 | }"#; |
| 102 | |
| 103 | let config: DeployConfig = serde_json::from_str(json).expect("should deserialize"); |
| 104 | assert_eq!(config.id, "abc-123"); |
| 105 | assert_eq!(config.runner, Runner::Rust); |
| 106 | assert!(config.kind.is_none()); |
| 107 | assert!(config.remote_path.is_none()); |
| 108 | assert!(config.port.is_none()); |
| 109 | } |
| 110 | } |