@smbcloud / cli / commits / d5dae96

fix deployment

Seto Elkahfi committed May 24, 2025 at 13:02 UTC d5dae967cf2e6ed242eca334f0dc58759bd69569
5 files changed +37 -115
crates/cli/src/deploy/config.rs
-5
@@ -7,8 +7,6 @@ use git2::{Cred, CredentialType, Error};
7 use spinners::Spinner;
8 use toml::Value;
9
10 -use super::remote_url::RemoteUrl;
11 -
10 pub(crate) async fn check_config() -> Result<Config> {
11 let mut spinner: Spinner = Spinner::new(
12 spinners::Spinners::SimpleDotsScrolling,
@@ -37,16 +35,13 @@ pub(crate) async fn check_config() -> Result<Config> {
35 .ok_or_else(|| anyhow::anyhow!(fail_message("Repo name not found in config file.")))?;
36
37 spinner.stop_and_persist(&succeed_symbol(), succeed_message("Valid config."));
40 - let remote_url = RemoteUrl::from(repo_name);
38
39 Ok(Config {
43 - remote_url,
40 name: repo_name.to_owned(),
41 })
42 }
43
44 pub struct Config {
49 - pub remote_url: RemoteUrl,
45 pub name: String,
46 }
47
crates/cli/src/deploy/git.rs
+32 -24
@@ -10,39 +10,47 @@ pub async fn remote_deployment_setup<'a>(
10 ) -> Result<Remote<'a>> {
11 let mut spinner = Spinner::new(
12 spinners::Spinners::SimpleDotsScrolling,
13 - style("Setting up remote deployment...")
13 + style("Checking remote deployment...")
14 .green()
15 .bold()
16 .to_string(),
17 );
18
19 - let smbcloud = match repo.find_remote("smbcloud") {
20 - Ok(remote) => remote,
19 + match repo.find_remote("smbcloud") {
20 + Ok(remote) => {
21 + spinner.stop_and_persist(
22 + &succeed_symbol(),
23 + succeed_message("Valid deployment setup."),
24 + );
25 + Ok(remote)
26 + }
27 Err(_) => {
28 spinner.stop_and_persist(
29 &fail_symbol(),
24 - fail_message("Remote deployment is not setup. Will setup remote deployment."),
30 + succeed_message("Remote deployment is not setup. Will setup remote deployment."),
31 + );
32 + let mut spinner = Spinner::new(
33 + spinners::Spinners::Hamburger,
34 + style("Creating remote deployment...")
35 + .green()
36 + .bold()
37 + .to_string(),
38 );
26 - // Present the user with a message to setup remote deployment
39 let remote_format = format!("{}.git", repo_name);
28 - repo.remote(
29 - "smbcloud",
30 - &format!("git@{}:{}", remote_format, remote_format),
31 - )
32 - .map_err(|e: git2::Error| {
33 - spinner.stop_and_persist(&fail_symbol(), e.to_string());
34 - anyhow!(fail_message("Failed to setup remote deployment: {e}"))
35 - })?;
36 - return Err(anyhow!(fail_message(
37 - "Remote deployment is not setup. Please run `git remote add smbcloud <url>`."
38 - )));
40 + let remote = repo
41 + .remote(
42 + "smbcloud",
43 + &format!("git@api.smbcloud.xyz:{}", remote_format),
44 + )
45 + .map_err(|e: git2::Error| {
46 + spinner.stop_and_persist(&fail_symbol(), e.to_string());
47 + anyhow!(fail_message("Failed to setup remote deployment: {e}"))
48 + })?;
49 + spinner.stop_and_persist(
50 + &succeed_symbol(),
51 + succeed_message("Valid deployment setup."),
52 + );
53 + Ok(remote)
54 }
40 - };
41 -
42 - spinner.stop_and_persist(
43 - &succeed_symbol(),
44 - succeed_message("Valid deployment setup."),
45 - );
46 -
47 - Ok(smbcloud)
55 + }
56 }
crates/cli/src/deploy/mod.rs
+2 -3
@@ -1,6 +1,5 @@
1 mod config;
2 mod git;
3 -mod remote_url;
3 mod remote_messages;
4
5 use crate::{
@@ -62,9 +61,9 @@ pub async fn process_deploy(env: Environment) -> Result<CommandResult> {
61 }
62 true // continue receiving.
63 });
65 - callbacks.push_update_reference(|x, y| match y {
64 + callbacks.push_update_reference(|_x, status_message| match status_message {
65 Some(e) => {
67 - println!("{}", e);
66 + println!("Deployment fail: {}", e);
67 Ok(())
68 }
69 None => Ok(()),
crates/cli/src/deploy/remote_messages.rs
+3 -3
@@ -1,7 +1,7 @@
1 pub fn build_next_app() -> String {
2 - "> next build".to_owned()
2 + "> next build".to_owned()
3 }
4
5 pub fn start_server(name: &str) -> String {
6 - format!("Start {}", name)
7 -}
\ No newline at end of file
6 + format!("Start {}", name)
7 +}
crates/cli/src/deploy/remote_url.rs deleted
-80
@@ -1,80 +0,0 @@
1 -use thiserror::Error;
2 -
3 -pub struct RemoteUrl {
4 - /// The git user. Should be git.
5 - pub user: String,
6 - /// The custom hostname ends with .git.
7 - pub host: String,
8 - /// The path name of the repo, also ends with .git.
9 - pub path: String,
10 -}
11 -
12 -impl RemoteUrl {
13 - pub fn from(repo_name: &str) -> Self {
14 - // Present the user with a message to setup remote deployment
15 - let remote_format = format!("{}.git", repo_name);
16 - RemoteUrl {
17 - host: "api.smbcloud.xyz".to_owned(),
18 - path: remote_format,
19 - user: "git".to_owned(),
20 - }
21 - }
22 -
23 - /// Returns a `Result<GitUrl>` after normalizing and parsing `url` for metadata
24 - pub fn parse(url: &str) -> Result<RemoteUrl, RemoteUrlParseError> {
25 - let segments = url.split(':').collect::<Vec<&str>>();
26 - // Should have two elements
27 - if segments.len() != 2 {
28 - return Err(RemoteUrlParseError::ParseError);
29 - }
30 - let path = match segments.last() {
31 - Some(path) => path.to_owned(),
32 - None => return Err(RemoteUrlParseError::MissingPath),
33 - };
34 - let (user, host) = match segments.first() {
35 - Some(user_host) => parse_user_host(user_host)?,
36 - None => return Err(RemoteUrlParseError::MissingUserHost),
37 - };
38 -
39 - if host != path {
40 - return Err(RemoteUrlParseError::ParseError);
41 - }
42 -
43 - Ok(RemoteUrl {
44 - host: host.to_owned(),
45 - user: user.to_owned(),
46 - path: path.to_owned(),
47 - })
48 - }
49 -}
50 -
51 -fn parse_user_host(s: &str) -> Result<(&str, &str), RemoteUrlParseError> {
52 - let segments = s.split("@").collect::<Vec<&str>>();
53 - // Should have two elements
54 - if segments.len() != 2 {
55 - return Err(RemoteUrlParseError::MissingUserHost);
56 - }
57 - let user = match segments.first() {
58 - Some(user) => user.to_owned(),
59 - None => return Err(RemoteUrlParseError::MissingUser),
60 - };
61 - let host = match segments.last() {
62 - Some(host) => host.to_owned(),
63 - None => return Err(RemoteUrlParseError::MissingHost),
64 - };
65 - Ok((user, host))
66 -}
67 -
68 -#[derive(Error, Debug, PartialEq, Eq)]
69 -pub enum RemoteUrlParseError {
70 - #[error("Git remote url format is invalid. It should be git@projectname.git:projectname.git")]
71 - ParseError,
72 - #[error("Path should be present.")]
73 - MissingPath,
74 - #[error("User and host should be present.")]
75 - MissingUserHost,
76 - #[error("Hostname should be present.")]
77 - MissingHost,
78 - #[error("User should be present.")]
79 - MissingUser,
80 -}