Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo-shuttle: added beta deployment status #1740

Merged
merged 3 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cargo-shuttle/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub enum DeploymentCommand {
/// View status of a deployment
Status {
/// ID of deployment to get status for
id: Uuid,
id: String,
},
}

Expand Down
10 changes: 10 additions & 0 deletions cargo-shuttle/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,16 @@ impl ShuttleApiClient {
self.get(path).await
}

pub async fn deployment_status(
&self,
project: &str,
deployment_id: &str,
) -> Result<deployment::EcsResponse> {
let path = format!("/projects/{project}/deployments/{deployment_id}");

self.get(path).await
}

pub async fn get_deployment_details(
&self,
project: &str,
Expand Down
36 changes: 27 additions & 9 deletions cargo-shuttle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ impl Shuttle {
}
if matches!(
args.cmd,
Command::Deployment(..)
| Command::Resource(..)
Command::Resource(..)
| Command::Stop
| Command::Clean
| Command::Status
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -952,14 +956,28 @@ impl Shuttle {
Ok(CommandOutcome::Ok)
}

async fn deployment_get(&self, deployment_id: Uuid) -> Result<CommandOutcome> {
async fn deployment_get(&self, deployment_id: &str) -> Result<CommandOutcome> {
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)
}
Expand Down
2 changes: 2 additions & 0 deletions common/src/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pub enum EcsState {
#[strum(serialize = "in progress")]
InProgress,
Stopped,
Stopping,
Failed,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
12 changes: 9 additions & 3 deletions common/src/models/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down Expand Up @@ -124,7 +128,9 @@ impl EcsState {
match self {
EcsState::InProgress => "cyan",
EcsState::Running => "green",
EcsState::Stopped => "blue",
EcsState::Stopped => "dark_blue",
EcsState::Stopping => "blue",
EcsState::Failed => "red",
}
}
}
Expand Down