From 57713412506b0c9eb6c85e11e2a95949e89b4b7f Mon Sep 17 00:00:00 2001 From: Iulian Barbu Date: Mon, 15 Apr 2024 21:41:07 +0300 Subject: [PATCH 1/3] common: add failed deployment state --- common/src/deployment.rs | 1 + common/src/models/deployment.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/common/src/deployment.rs b/common/src/deployment.rs index 49934e22d..aaa91069b 100644 --- a/common/src/deployment.rs +++ b/common/src/deployment.rs @@ -28,6 +28,7 @@ pub enum EcsState { #[strum(serialize = "in progress")] InProgress, Stopped, + Failed, } #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/common/src/models/deployment.rs b/common/src/models/deployment.rs index 475d4e37f..dbc43dfd7 100644 --- a/common/src/models/deployment.rs +++ b/common/src/models/deployment.rs @@ -125,6 +125,7 @@ impl EcsState { EcsState::InProgress => "cyan", EcsState::Running => "green", EcsState::Stopped => "blue", + EcsState::Failed => "red", } } } From b8c5b84a60fee1e800092240021a7aa5ded83139 Mon Sep 17 00:00:00 2001 From: Iulian Barbu Date: Tue, 16 Apr 2024 13:34:08 +0300 Subject: [PATCH 2/3] cargo-shuttle: add stopping ecs state --- common/src/deployment.rs | 1 + common/src/models/deployment.rs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/common/src/deployment.rs b/common/src/deployment.rs index aaa91069b..fdfae7a6d 100644 --- a/common/src/deployment.rs +++ b/common/src/deployment.rs @@ -28,6 +28,7 @@ pub enum EcsState { #[strum(serialize = "in progress")] InProgress, Stopped, + Stopping, Failed, } diff --git a/common/src/models/deployment.rs b/common/src/models/deployment.rs index dbc43dfd7..fd76828e4 100644 --- a/common/src/models/deployment.rs +++ b/common/src/models/deployment.rs @@ -124,7 +124,8 @@ impl EcsState { match self { EcsState::InProgress => "cyan", EcsState::Running => "green", - EcsState::Stopped => "blue", + EcsState::Stopped => "dark_blue", + EcsState::Stopping => "blue", EcsState::Failed => "red", } } From ec571087455fc652a60e4f0c64fad7ffca243821 Mon Sep 17 00:00:00 2001 From: Iulian Barbu Date: Tue, 16 Apr 2024 15:45:03 +0300 Subject: [PATCH 3/3] cargo-shuttle: add the beta deployment status cmd handler --- cargo-shuttle/src/args.rs | 2 +- cargo-shuttle/src/client.rs | 10 +++++++++ cargo-shuttle/src/lib.rs | 36 ++++++++++++++++++++++++--------- common/src/models/deployment.rs | 8 ++++++-- 4 files changed, 44 insertions(+), 12 deletions(-) diff --git a/cargo-shuttle/src/args.rs b/cargo-shuttle/src/args.rs index 60b31e89f..b62f26355 100644 --- a/cargo-shuttle/src/args.rs +++ b/cargo-shuttle/src/args.rs @@ -167,7 +167,7 @@ pub enum DeploymentCommand { /// View status of a deployment Status { /// ID of deployment to get status for - id: Uuid, + id: String, }, } diff --git a/cargo-shuttle/src/client.rs b/cargo-shuttle/src/client.rs index e10486e81..355a50257 100644 --- a/cargo-shuttle/src/client.rs +++ b/cargo-shuttle/src/client.rs @@ -246,6 +246,16 @@ impl ShuttleApiClient { self.get(path).await } + pub async fn deployment_status( + &self, + project: &str, + deployment_id: &str, + ) -> Result { + let path = format!("/projects/{project}/deployments/{deployment_id}"); + + self.get(path).await + } + pub async fn get_deployment_details( &self, project: &str, diff --git a/cargo-shuttle/src/lib.rs b/cargo-shuttle/src/lib.rs index e4adddbb7..94d1cd6d2 100644 --- a/cargo-shuttle/src/lib.rs +++ b/cargo-shuttle/src/lib.rs @@ -132,8 +132,7 @@ impl Shuttle { } if matches!( args.cmd, - Command::Deployment(..) - | Command::Resource(..) + Command::Resource(..) | Command::Stop | Command::Clean | Command::Status @@ -221,9 +220,14 @@ impl Shuttle { Command::Status => self.status().await, Command::Logs(logs_args) => self.logs(logs_args).await, Command::Deployment(DeploymentCommand::List { page, limit, raw }) => { + if self.beta { + unimplemented!(); + } self.deployments_list(page, limit, raw).await } - Command::Deployment(DeploymentCommand::Status { id }) => self.deployment_get(id).await, + Command::Deployment(DeploymentCommand::Status { id }) => { + self.deployment_get(id.as_str()).await + } Command::Resource(ResourceCommand::List { raw, show_secrets }) => { self.resources_list(raw, show_secrets).await } @@ -952,14 +956,28 @@ impl Shuttle { Ok(CommandOutcome::Ok) } - async fn deployment_get(&self, deployment_id: Uuid) -> Result { + async fn deployment_get(&self, deployment_id: &str) -> Result { let client = self.client.as_ref().unwrap(); - let deployment = client - .get_deployment_details(self.ctx.project_name(), &deployment_id) - .await - .map_err(suggestions::deployment::get_deployment_status_failure)?; - println!("{deployment}"); + if self.beta { + let deployment = client + .deployment_status(self.ctx.project_name(), deployment_id) + .await + .map_err(suggestions::deployment::get_deployment_status_failure)?; + deployment.colored_println(); + } else { + let deployment = client + .get_deployment_details( + self.ctx.project_name(), + &Uuid::from_str(deployment_id).map_err(|err| { + anyhow!("Provided deployment id is not a valid UUID: {err}") + })?, + ) + .await + .map_err(suggestions::deployment::get_deployment_status_failure)?; + + println!("{deployment}"); + } Ok(CommandOutcome::Ok) } diff --git a/common/src/models/deployment.rs b/common/src/models/deployment.rs index fd76828e4..6ece4d74f 100644 --- a/common/src/models/deployment.rs +++ b/common/src/models/deployment.rs @@ -90,8 +90,12 @@ impl EcsResponse { ); let state_with_uri = match self.running_id { - None => format!("{latest_state} ({})", self.uri), - Some(_) => latest_state, + None if EcsState::Running == self.latest_deployment_state + || EcsState::InProgress == self.latest_deployment_state => + { + format!("{latest_state} ({})", self.uri) + } + _ => latest_state, }; println!(