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

Miscellaneous nitpicks for publish (and deploy) #4660

Merged
merged 3 commits into from
May 9, 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
43 changes: 23 additions & 20 deletions lib/cli/src/commands/app/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ impl CmdAppDeploy {
api: self.api.clone(),
};

publish_cmd.publish(client, &manifest_path, &manifest).await
publish_cmd
.publish(client, &manifest_path, &manifest, true)
.await
}

async fn get_owner(
Expand Down Expand Up @@ -450,7 +452,18 @@ impl AsyncCliCommand for CmdAppDeploy {
}
};

let (_app, app_version) = deploy_app_verbose(&client, opts).await?;
let owner = &opts.owner.clone().or_else(|| opts.app.owner.clone());
let app = &opts.app;

let pretty_name = if let Some(owner) = &owner {
format!("{} ({})", app.name.bold(), owner.bold())
} else {
app.name.bold().to_string()
};

eprintln!("\nDeploying app {} to Wasmer Edge...\n", pretty_name);

let app_version = deploy_app(&client, opts.clone()).await?;

let mut new_app_config = app_config_from_api(&app_version)?;

Expand All @@ -468,7 +481,7 @@ impl AsyncCliCommand for CmdAppDeploy {
// settings without requring new CLI versions, so instead of just
// serializing the new config, we merge it with the old one.
let new_merged = crate::utils::merge_yaml_values(
&app_config.to_yaml_value()?,
&app_config.clone().to_yaml_value()?,
&new_app_config.to_yaml_value()?,
);
let new_config_raw = serde_yaml::to_string(&new_merged)?;
Expand All @@ -477,6 +490,8 @@ impl AsyncCliCommand for CmdAppDeploy {
})?;
}

wait_app(&client, opts.clone(), app_version.clone()).await?;

if self.fmt.format == crate::utils::render::ItemFormat::Json {
println!("{}", serde_json::to_string_pretty(&app_version)?);
}
Expand All @@ -485,7 +500,7 @@ impl AsyncCliCommand for CmdAppDeploy {
}
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct DeployAppOpts<'a> {
pub app: &'a AppConfigV1,
// Original raw yaml config.
Expand Down Expand Up @@ -539,25 +554,13 @@ pub enum WaitMode {
}

/// Same as [Self::deploy], but also prints verbose information.
pub async fn deploy_app_verbose(
pub async fn wait_app(
client: &WasmerClient,
opts: DeployAppOpts<'_>,
version: DeployAppVersion,
) -> Result<(DeployApp, DeployAppVersion), anyhow::Error> {
let owner = &opts.owner.clone().or_else(|| opts.app.owner.clone());
let app = &opts.app;

let pretty_name = if let Some(owner) = &owner {
format!("{} ({})", app.name.bold(), owner.bold())
} else {
app.name.bold().to_string()
};

let make_default = opts.make_default;

eprintln!("\nDeploying app {} to Wasmer Edge...\n", pretty_name);

let wait = opts.wait;
let version = deploy_app(client, opts).await?;
let make_default = opts.make_default;

let app_id = version
.app
Expand Down Expand Up @@ -623,7 +626,7 @@ pub async fn deploy_app_verbose(

if header == version.id.inner() {
eprintln!("\nNew version is now reachable at {check_url}");
eprintln!(" Deployment complete");
eprintln!("{} Deployment complete", "✔".green().bold());
break;
}

Expand Down
87 changes: 1 addition & 86 deletions lib/cli/src/commands/package/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,102 +5,17 @@ use crate::{
};
use colored::Colorize;
use dialoguer::Confirm;
use semver::VersionReq;
use std::{
collections::BTreeMap,
path::{Path, PathBuf},
str::FromStr,
};
use wasmer_api::WasmerClient;
use wasmer_config::package::{Manifest, NamedPackageIdent, PackageHash, PackageIdent};
use wasmer_config::package::{Manifest, PackageHash};
use webc::wasmer_package::Package;

pub mod macros;
pub mod wait;

// We have PackageId and PackageIdent.. Brace yourselves, here we have their intertransmutunion,
// the PackageSpecifier.
#[derive(Debug, Clone, PartialEq, Eq)]
pub(super) enum PackageSpecifier {
Hash {
namespace: String,
hash: PackageHash,
},
Named {
namespace: String,
name: String,
tag: Tag,
},
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub(super) enum Tag {
Version(semver::Version), // <-- This is the reason..
Hash(PackageHash),
}

impl From<PackageSpecifier> for PackageIdent {
fn from(value: PackageSpecifier) -> Self {
match value {
PackageSpecifier::Hash { hash, .. } => PackageIdent::Hash(hash),
PackageSpecifier::Named {
namespace,
name,
tag,
} => match tag {
Tag::Version(v) => PackageIdent::Named(NamedPackageIdent {
registry: None,
namespace: Some(namespace),
name,
tag: Some(wasmer_config::package::Tag::VersionReq(
VersionReq::parse(&v.to_string()).unwrap(),
)),
}),
Tag::Hash(h) => PackageIdent::Named(NamedPackageIdent {
registry: None,
namespace: Some(namespace),
name,
tag: Some(wasmer_config::package::Tag::Named(h.to_string())),
}),
},
}
}
}

pub(super) fn into_specifier(
manifest: &Manifest,
hash: &PackageHash,
namespace: String,
) -> anyhow::Result<PackageSpecifier> {
Ok(match &manifest.package {
None => PackageSpecifier::Hash {
namespace,
hash: hash.clone(),
},
Some(n) => match &n.name {
Some(name) => {
let named = NamedPackageIdent::from_str(name)?;
match &n.version {
Some(v) => PackageSpecifier::Named {
namespace,
name: named.name.clone(),
tag: Tag::Version(v.clone()),
},
None => PackageSpecifier::Named {
namespace,
name: named.name.clone(),
tag: Tag::Hash(hash.clone()),
},
}
}
None => PackageSpecifier::Hash {
namespace,
hash: hash.clone(),
},
},
})
}

pub(super) fn on_error(e: anyhow::Error) -> anyhow::Error {
#[cfg(feature = "telemetry")]
sentry::integrations::anyhow::capture_anyhow(&e);
Expand Down
4 changes: 3 additions & 1 deletion lib/cli/src/commands/package/common/wait.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use super::macros::spinner_ok;
use colored::Colorize;
use futures_util::StreamExt;
use indicatif::ProgressBar;
use wasmer_api::WasmerClient;
Expand Down Expand Up @@ -144,6 +146,6 @@ pub async fn wait_package(
}
}

pb.finish_and_clear();
spinner_ok!(pb, "Package is available in the registry");
Ok(())
}
7 changes: 5 additions & 2 deletions lib/cli/src/commands/package/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ impl PackagePublish {
client: &WasmerClient,
manifest_path: &Path,
manifest: &Manifest,
allow_unnamed: bool,
) -> anyhow::Result<PackageIdent> {
let (package_namespace, package_hash) = {
let push_cmd = PackagePush {
Expand Down Expand Up @@ -119,7 +120,7 @@ impl PackagePublish {
package_path: self.package_path.clone(),
package_hash,
}
.tag(client, manifest)
.tag(client, manifest, manifest_path, true, allow_unnamed)
.await
}
}
Expand All @@ -142,7 +143,9 @@ impl AsyncCliCommand for PackagePublish {
let (manifest_path, manifest) = get_manifest(&self.package_path)?;
tracing::info!("Got manifest at path {}", manifest_path.display());

let ident = self.publish(&client, &manifest_path, &manifest).await?;
let ident = self
.publish(&client, &manifest_path, &manifest, false)
.await?;

if !self.quiet && !self.non_interactive {
eprintln!(
Expand Down
7 changes: 5 additions & 2 deletions lib/cli/src/commands/package/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,11 @@ impl PackagePush {
}

let user = wasmer_api::query::current_user_with_namespaces(client, None).await?;
let owner =
crate::utils::prompts::prompt_for_namespace("Choose a namespace", None, Some(&user))?;
let owner = crate::utils::prompts::prompt_for_namespace(
"Choose a namespace to push the package to",
None,
Some(&user),
)?;

Ok(owner.clone())
}
Expand Down
Loading
Loading