Skip to main content

smbcloud_model/
deploy_config.rs

1use {
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)]
11pub 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    /// Runtime supervisor for `nextjs-ssr` apps: `"pm2"` (default) or
39    /// `"systemd"`. When `systemd`, deploys restart via a git-owned
40    /// `systemctl --user restart <pm2_app>.service` instead of `pm2`.
41    #[serde(default)]
42    pub process_manager: Option<String>,
43    #[serde(default)]
44    pub port: Option<u16>,
45    #[serde(default)]
46    pub shared_lib_path: Option<String>,
47    #[serde(default)]
48    pub project_id: Option<i32>,
49    #[serde(default)]
50    pub deploy_repo_id: Option<i64>,
51    #[serde(default)]
52    pub repository: Option<String>,
53}
54
55#[cfg(test)]
56mod tests {
57    use super::*;
58
59    #[test]
60    fn deserializes_full_deploy_config() {
61        let json = r#"{
62            "id": "80b309e8-c39a-45b6-9121-e616fde3cd42",
63            "name": "onde-cloud",
64            "runner": 0,
65            "deployment_method": 1,
66            "source_path": ".",
67            "kind": "rust",
68            "remote_path": "apps/rest-api/onde-cloud",
69            "output_path": null,
70            "build_command": null,
71            "install_command": null,
72            "binary_name": "onde-cloud",
73            "build_target": "x86_64-unknown-linux-gnu",
74            "package_manager": null,
75            "pm2_app": null,
76            "port": 8090,
77            "shared_lib_path": null,
78            "project_id": 50,
79            "deploy_repo_id": 18,
80            "repository": "test"
81        }"#;
82
83        let config: DeployConfig = serde_json::from_str(json).expect("should deserialize");
84        assert_eq!(config.id, "80b309e8-c39a-45b6-9121-e616fde3cd42");
85        assert_eq!(config.kind.as_deref(), Some("rust"));
86        assert_eq!(
87            config.remote_path.as_deref(),
88            Some("apps/rest-api/onde-cloud")
89        );
90        assert_eq!(config.binary_name.as_deref(), Some("onde-cloud"));
91        assert_eq!(
92            config.build_target.as_deref(),
93            Some("x86_64-unknown-linux-gnu")
94        );
95        assert_eq!(config.port, Some(8090));
96        assert_eq!(config.runner, Runner::NodeJs);
97    }
98
99    #[test]
100    fn deserializes_minimal_deploy_config() {
101        let json = r#"{
102            "id": "abc-123",
103            "name": "my-app",
104            "runner": 4,
105            "deployment_method": 0
106        }"#;
107
108        let config: DeployConfig = serde_json::from_str(json).expect("should deserialize");
109        assert_eq!(config.id, "abc-123");
110        assert_eq!(config.runner, Runner::Rust);
111        assert!(config.kind.is_none());
112        assert!(config.remote_path.is_none());
113        assert!(config.port.is_none());
114    }
115}