5 files changed
+78
-21
Cargo.toml
+1
@@ -31,6 +31,7 @@ smbcloud-utils = { version = "0.3.0", path = "smbcloud-utils" }
31
spinners = "4.1.0"
32
ssh2-config = "0.5"
33
thiserror = "1.0.29"
34
+toml = "0.8"
35
tokio = "1.44"
36
tracing = "0.1.35"
37
tracing-bunyan-formatter = "0.3.3"
smbcloud-cli/src/deploy/git.rs
+35
@@ -1 +1,36 @@
1
+use anyhow::{Result, anyhow};
2
+use console::style;
3
+use git2::{Remote, Repository};
4
+use spinners::Spinner;
5
6
+pub async fn remote_deployment_setup(repo: &Repository) -> Result<Remote> {
7
+ let mut spinner = Spinner::new(
8
+ spinners::Spinners::SimpleDotsScrolling,
9
+ style("Setting up remote deployment...")
10
+ .green()
11
+ .bold()
12
+ .to_string(),
13
+ );
14
+
15
+ let smbcloud = match repo.find_remote("smbcloud") {
16
+ Ok(remote) => remote,
17
+ Err(_) => {
18
+ spinner.stop_and_persist("😩", "Remote deployment is not setup. Will setup remote deployment.".to_owned());
19
+ // Present the user with a message to setup remote deployment
20
+ repo.remote("smbcloud", "deploy@api.smbcloud.xyz:git/foodandtravel")
21
+ .map_err(|e: git2::Error| {
22
+ spinner.stop_and_persist("😩", e.to_string());
23
+ anyhow!("Failed to setup remote deployment: {e}")
24
+ })?;
25
+ return Err(anyhow!(
26
+ "Remote deployment is not setup. Please run `git remote add smbcloud <url>`."
27
+ ));
28
+ }
29
+ };
30
+ // Simulate some work
31
+ tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
32
+
33
+ spinner.stop_and_persist("🚀", "Remote deployment setup complete.".to_owned());
34
+
35
+ Ok(smbcloud)
36
+}
smbcloud-cli/src/deploy/mod.rs
+11
-20
@@ -1,21 +1,25 @@
1
mod git;
2
+mod smb_config;
3
4
use std::{fs::File, io::BufReader};
4
-
5
use crate::cli::CommandResult;
6
use anyhow::Result;
7
use console::style;
8
+use git::remote_deployment_setup;
9
use git2::{Cred, PushOptions, RemoteCallbacks, Repository};
10
use git_url_parse::{GitUrl, Scheme};
11
+use smb_config::check_config;
12
+use smbcloud_networking::environment::Environment;
13
use spinners::Spinner;
14
use ssh2_config::{ParseRule, SshConfig};
15
13
-pub async fn process_deploy() -> Result<CommandResult> {
16
+pub async fn process_deploy(env: Environment) -> Result<CommandResult> {
17
+ check_config(env).await?;
18
println!("Deploying your app...");
19
let mut spinner = Spinner::new(
20
spinners::Spinners::SimpleDotsScrolling,
21
style("Deploying...").green().bold().to_string(),
18
- );
22
+ );
23
24
let repo = match Repository::open(".") {
25
Ok(repo) => repo,
@@ -41,18 +45,7 @@ pub async fn process_deploy() -> Result<CommandResult> {
45
});
46
}
47
};
44
- let mut origin = match repo.find_remote("origin") {
45
- Ok(remote) => remote,
46
- Err(_) => {
47
- spinner.stop_and_persist("😩", "No remote repository found.".to_owned());
48
- return Ok(CommandResult {
49
- spinner,
50
- symbol: "😩".to_owned(),
51
- msg: "No remote repository found. Add with `git remote add origin <url>` command."
52
- .to_owned(),
53
- });
54
- }
55
- };
48
+ let mut origin = remote_deployment_setup(&repo).await?;
49
let remote_url = match origin.url() {
50
Some(url) => url,
51
None => {
@@ -80,7 +73,7 @@ pub async fn process_deploy() -> Result<CommandResult> {
73
//println!("Parsed URL: {:#?}", parsed_url);
74
match parsed_url.scheme {
75
Scheme::Ssh => {
83
- println!("SSH URL: {:#?}", parsed_url);
76
+ // println!("SSH URL: {:#?}", parsed_url);
77
}
78
_ => {
79
// Only support ssh for now
@@ -144,7 +137,7 @@ pub async fn process_deploy() -> Result<CommandResult> {
137
// get identity_file
138
let identity_files = match host_config.identity_file {
139
Some(identity_files) => {
147
- println!("Identity file: {:#?}", identity_files);
140
+ //println!("Identity file: {:#?}", identity_files);
141
identity_files
142
}
143
None => {
@@ -183,7 +176,7 @@ pub async fn process_deploy() -> Result<CommandResult> {
176
match origin.push(&["refs/heads/main:refs/heads/main"], Some(&mut push_opts)) {
177
Ok(_) => {}
178
Err(e) => {
186
- println!("Failed to push to remote: {:#?}", e);
179
+ //println!("Failed to push to remote: {:#?}", e);
180
spinner.stop_and_persist("😩", e.to_string());
181
return Ok(CommandResult {
182
spinner,
@@ -193,8 +186,6 @@ pub async fn process_deploy() -> Result<CommandResult> {
186
}
187
};
188
196
- spinner.stop_and_persist("✅", "Your app has been deployed successfully.".to_owned());
197
-
189
Ok(CommandResult {
190
spinner,
191
symbol: "🚀".to_owned(),
smbcloud-cli/src/deploy/smb_config.rs
new
+30
@@ -0,0 +1,30 @@
1
+use console::style;
2
+use smbcloud_networking::{environment::Environment, get_smb_token};
3
+use spinners::Spinner;
4
+use anyhow::Result;
5
+use crate::cli::CommandResult;
6
+
7
+pub(crate) async fn check_config(env: Environment) -> Result<CommandResult> {
8
+ let mut spinner = Spinner::new(
9
+ spinners::Spinners::SimpleDotsScrolling,
10
+ style("Checking config...").green().bold().to_string(),
11
+ );
12
+
13
+ let token = match get_smb_token(env).await {
14
+ Ok(token) => token,
15
+ Err(e) => {
16
+ spinner.stop_and_persist("😩", e.to_string());
17
+ return Ok(CommandResult {
18
+ spinner,
19
+ symbol: "😩".to_owned(),
20
+ msg: "Failed to get SMB token.".to_owned(),
21
+ });
22
+ }
23
+ };
24
+
25
+ Ok(CommandResult {
26
+ spinner,
27
+ symbol: "✅".to_owned(),
28
+ msg: format!("SMB Token: {}", token),
29
+ })
30
+}
\ No newline at end of file
smbcloud-cli/src/main.rs
+1
-1
@@ -115,6 +115,6 @@ async fn run() -> Result<CommandResult> {
115
Commands::Init { name, description } => {
116
process_project_init(cli.environment, name, description).await
117
}
118
- Commands::Deploy {} => process_deploy().await,
118
+ Commands::Deploy {} => process_deploy(cli.environment).await,
119
}
120
}