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

feat: allow --no-follow and --raw on redeploy #1973

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
26 changes: 19 additions & 7 deletions cargo-shuttle/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,15 @@ pub enum DeploymentCommand {
Redeploy {
/// ID of deployment to redeploy
id: Option<String>,

#[command(flatten)]
tracking_args: DeploymentTrackingArgs,
jonaro00 marked this conversation as resolved.
Show resolved Hide resolved
},
/// Stop running deployment(s)
Stop,
Stop {
#[command(flatten)]
tracking_args: DeploymentTrackingArgs,
},
}

#[derive(Subcommand)]
Expand Down Expand Up @@ -308,23 +314,29 @@ pub struct DeployArgs {
/// WIP: Deploy this Docker image instead of building one
#[arg(long, short = 'i', hide = true)]
pub image: Option<String>,
/// Don't follow the deployment status, exit after the deployment begins
#[arg(long, visible_alias = "nf")]
pub no_follow: bool,
oddgrd marked this conversation as resolved.
Show resolved Hide resolved

/// Allow deployment with uncommitted files
#[arg(long, visible_alias = "ad")]
pub allow_dirty: bool,
/// Don't display timestamps and log origin tags
#[arg(long)]
pub raw: bool,
/// Output the deployment archive to a file instead of sending a deployment request
#[arg(long)]
pub output_archive: Option<PathBuf>,

#[command(flatten)]
pub tracking_args: DeploymentTrackingArgs,

#[command(flatten)]
pub secret_args: SecretsArgs,
}
#[derive(Args, Default)]
pub struct DeploymentTrackingArgs {
/// Don't follow the deployment status, exit after the operation begins
#[arg(long, visible_alias = "nf")]
pub no_follow: bool,
/// Don't display timestamps and log origin tags
#[arg(long)]
pub raw: bool,
}

#[derive(Args, Debug)]
pub struct RunArgs {
Expand Down
46 changes: 35 additions & 11 deletions cargo-shuttle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::path::{Path, PathBuf};
use std::sync::Arc;

use anyhow::{anyhow, bail, Context, Result};
use args::DeploymentTrackingArgs;
use chrono::Utc;
use clap::{parser::ValueSource, CommandFactory, FromArgMatches};
use crossterm::style::Stylize;
Expand Down Expand Up @@ -242,8 +243,10 @@ impl Shuttle {
self.deployments_list(page, limit, table).await
}
DeploymentCommand::Status { id } => self.deployment_get(id).await,
DeploymentCommand::Redeploy { id } => self.deployment_redeploy(id).await,
DeploymentCommand::Stop => self.stop().await,
DeploymentCommand::Redeploy { id, tracking_args } => {
self.deployment_redeploy(id, tracking_args).await
}
DeploymentCommand::Stop { tracking_args } => self.stop(tracking_args).await,
},
Command::Resource(cmd) => match cmd {
ResourceCommand::List {
Expand Down Expand Up @@ -844,11 +847,16 @@ impl Shuttle {
})
}

async fn stop(&self) -> Result<()> {
async fn stop(&self, tracking_args: DeploymentTrackingArgs) -> Result<()> {
let client = self.client.as_ref().unwrap();
let pid = self.ctx.project_id();
let res = client.stop_service(pid).await?;
println!("{res}");

if tracking_args.no_follow {
return Ok(());
}

wait_with_spinner(2000, |_, pb| async move {
let deployment = client.get_current_deployment(pid).await?;

Expand Down Expand Up @@ -983,7 +991,11 @@ impl Shuttle {
Ok(())
}

async fn deployment_redeploy(&self, deployment_id: Option<String>) -> Result<()> {
async fn deployment_redeploy(
&self,
deployment_id: Option<String>,
tracking_args: DeploymentTrackingArgs,
) -> Result<()> {
let client = self.client.as_ref().unwrap();

let pid = self.ctx.project_id();
Expand All @@ -1000,7 +1012,11 @@ impl Shuttle {
};
let deployment = client.redeploy(pid, &deployment_id).await?;

self.track_deployment_status_and_print_logs_on_fail(pid, &deployment.id, false)
if tracking_args.no_follow {
println!("{}", deployment.to_string_colored());
return Ok(());
}
self.track_deployment_status_and_print_logs_on_fail(pid, &deployment.id, tracking_args.raw)
.await?;

Ok(())
Expand Down Expand Up @@ -1398,13 +1414,17 @@ impl Shuttle {
.deploy(pid, DeploymentRequest::Image(deployment_req_image))
.await?;

if args.no_follow {
if args.tracking_args.no_follow {
println!("{}", deployment.to_string_colored());
return Ok(());
}

self.track_deployment_status_and_print_logs_on_fail(pid, &deployment.id, args.raw)
.await?;
self.track_deployment_status_and_print_logs_on_fail(
pid,
&deployment.id,
args.tracking_args.raw,
)
.await?;

return Ok(());
}
Expand Down Expand Up @@ -1507,13 +1527,17 @@ impl Shuttle {
.deploy(pid, DeploymentRequest::BuildArchive(deployment_req))
.await?;

if args.no_follow {
if args.tracking_args.no_follow {
println!("{}", deployment.to_string_colored());
return Ok(());
}

self.track_deployment_status_and_print_logs_on_fail(pid, &deployment.id, args.raw)
.await?;
self.track_deployment_status_and_print_logs_on_fail(
pid,
&deployment.id,
args.tracking_args.raw,
)
.await?;

Ok(())
}
Expand Down