-
Notifications
You must be signed in to change notification settings - Fork 849
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): Implement app deployment commands
* list * get * logs
- Loading branch information
Showing
6 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//! Get deployments for an app. | ||
use crate::{ | ||
commands::AsyncCliCommand, config::WasmerEnv, opts::ItemFormatOpts, utils::render::ItemFormat, | ||
}; | ||
|
||
/// Get the volumes of an app. | ||
#[derive(clap::Parser, Debug)] | ||
pub struct CmdAppDeploymentGet { | ||
#[clap(flatten)] | ||
fmt: ItemFormatOpts, | ||
|
||
#[clap(flatten)] | ||
env: WasmerEnv, | ||
|
||
/// ID of the deployment. | ||
id: String, | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl AsyncCliCommand for CmdAppDeploymentGet { | ||
type Output = (); | ||
|
||
async fn run_async(mut self) -> Result<(), anyhow::Error> { | ||
let client = self.env.client()?; | ||
let item = wasmer_api::query::app_deployment(&client, self.id).await?; | ||
|
||
// The below is a bit hacky - the default is YAML, but this is not a good | ||
// default for deployments, so we switch to table. | ||
if self.fmt.format == ItemFormat::Yaml { | ||
self.fmt.format = ItemFormat::Table; | ||
} | ||
|
||
println!("{}", self.fmt.format.render(&item)); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//! List volumes tied to an edge app. | ||
use super::super::util::AppIdentOpts; | ||
use crate::{commands::AsyncCliCommand, config::WasmerEnv, opts::ListFormatOpts}; | ||
|
||
/// List the volumes of an app. | ||
#[derive(clap::Parser, Debug)] | ||
pub struct CmdAppDeploymentList { | ||
#[clap(flatten)] | ||
fmt: ListFormatOpts, | ||
|
||
#[clap(flatten)] | ||
env: WasmerEnv, | ||
|
||
#[clap(flatten)] | ||
ident: AppIdentOpts, | ||
|
||
#[clap(long)] | ||
offset: Option<u32>, | ||
|
||
#[clap(long)] | ||
limit: Option<u32>, | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl AsyncCliCommand for CmdAppDeploymentList { | ||
type Output = (); | ||
|
||
async fn run_async(self) -> Result<(), anyhow::Error> { | ||
let client = self.env.client()?; | ||
|
||
let (_ident, app) = self.ident.load_app(&client).await?; | ||
let vars = wasmer_api::types::GetAppDeploymentsVariables { | ||
after: None, | ||
first: self.limit.map(|x| x as i32), | ||
name: app.name.clone(), | ||
offset: self.offset.map(|x| x as i32), | ||
owner: app.owner.global_name, | ||
}; | ||
let items = wasmer_api::query::app_deployments(&client, vars).await?; | ||
|
||
if items.is_empty() { | ||
eprintln!("App {} has no deployments!", app.name); | ||
} else { | ||
println!("{}", self.fmt.format.render(&items)); | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//! Get logs for an app deployment. | ||
use std::io::Write; | ||
|
||
use anyhow::Context; | ||
use futures::stream::TryStreamExt; | ||
|
||
use crate::{commands::AsyncCliCommand, config::WasmerEnv, opts::ItemFormatOpts}; | ||
|
||
/// Get logs for an app deployment. | ||
#[derive(clap::Parser, Debug)] | ||
pub struct CmdAppDeploymentLogs { | ||
#[clap(flatten)] | ||
fmt: ItemFormatOpts, | ||
|
||
#[clap(flatten)] | ||
env: WasmerEnv, | ||
|
||
/// ID of the deployment. | ||
id: String, | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl AsyncCliCommand for CmdAppDeploymentLogs { | ||
type Output = (); | ||
|
||
async fn run_async(mut self) -> Result<(), anyhow::Error> { | ||
let client = self.env.client()?; | ||
let item = wasmer_api::query::app_deployment(&client, self.id).await?; | ||
|
||
let url = item | ||
.log_url | ||
.context("This deployment does not have logs available")?; | ||
|
||
let mut writer = std::io::BufWriter::new(std::io::stdout()); | ||
|
||
let mut stream = reqwest::Client::new() | ||
.get(url) | ||
.send() | ||
.await? | ||
.error_for_status()? | ||
.bytes_stream(); | ||
|
||
while let Some(chunk) = stream.try_next().await? { | ||
writer.write_all(&chunk)?; | ||
writer.flush()?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use crate::commands::AsyncCliCommand; | ||
|
||
pub mod get; | ||
pub mod list; | ||
pub mod logs; | ||
|
||
/// App volume management. | ||
#[derive(Debug, clap::Parser)] | ||
pub enum CmdAppDeployment { | ||
List(list::CmdAppDeploymentList), | ||
Get(get::CmdAppDeploymentGet), | ||
Logs(logs::CmdAppDeploymentLogs), | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl AsyncCliCommand for CmdAppDeployment { | ||
type Output = (); | ||
|
||
async fn run_async(self) -> Result<Self::Output, anyhow::Error> { | ||
match self { | ||
Self::List(c) => c.run_async().await, | ||
Self::Get(c) => c.run_async().await, | ||
Self::Logs(c) => c.run_async().await, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters