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

CLI: Try to fetch owner from app_id if necessary while deploying #4965

Merged
merged 3 commits into from
Jul 30, 2024
Merged
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
34 changes: 31 additions & 3 deletions lib/cli/src/commands/app/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ impl CmdAppDeploy {
client: &WasmerClient,
app: &serde_yaml::Value,
app_config_path: &PathBuf,
maybe_edge_app: Option<&DeployApp>,
) -> anyhow::Result<(String, String)> {
let r_ret = serde_yaml::to_string(&app)?;

Expand All @@ -180,6 +181,11 @@ impl CmdAppDeploy {
return Ok((owner.clone(), r_ret));
}

if let Some(edge_app) = maybe_edge_app {
let new_raw_config = format!("{r_ret}\nowner: {}\n", edge_app.owner.global_name);
return Ok((edge_app.owner.global_name.clone(), new_raw_config));
};

if self.non_interactive {
// if not interactive we can't prompt the user to choose the owner of the app.
anyhow::bail!("No owner specified: use --owner XXX");
Expand All @@ -192,7 +198,7 @@ impl CmdAppDeploy {
Some(&user),
)?;

let new_raw_config = format!("owner: {owner}\n{r_ret}");
let new_raw_config = format!("{r_ret}\nowner: {owner}\n");

std::fs::write(app_config_path, &new_raw_config)
.with_context(|| format!("Could not write file: '{}'", app_config_path.display()))?;
Expand Down Expand Up @@ -272,13 +278,32 @@ impl AsyncCliCommand for CmdAppDeploy {

// We want to allow the user to specify the app name interactively.
let app_yaml: serde_yaml::Value = serde_yaml::from_str(&config_str)?;
let (owner, mut config_str) = self.get_owner(&client, &app_yaml, &app_config_path).await?;
let maybe_edge_app = if let Some(app_id) = app_yaml.get("app_id").and_then(|s| s.as_str()) {
wasmer_api::query::get_app_by_id(&client, app_id.to_owned())
.await
.ok()
} else {
None
};

let (owner, mut config_str) = self
.get_owner(
&client,
&app_yaml,
&app_config_path,
maybe_edge_app.as_ref(),
)
.await?;

// We want to allow the user to specify the app name interactively.
let app_yaml: serde_yaml::Value = serde_yaml::from_str(&config_str)?;

if app_yaml.get("name").is_none() && self.app_name.is_some() {
config_str = format!("{}\nname: {}", config_str, self.app_name.as_ref().unwrap());
config_str = format!("{config_str}name: {}", self.app_name.as_ref().unwrap());
} else if app_yaml.get("name").is_none() && maybe_edge_app.is_some() {
let edge_app = maybe_edge_app.as_ref().unwrap();
config_str = format!("{config_str}name: {}", edge_app.name);
println!("config_str: {config_str}");
} else if app_yaml.get("name").is_none() {
if !self.non_interactive {
let default_name = std::env::current_dir().ok().and_then(|dir| {
Expand Down Expand Up @@ -319,6 +344,9 @@ impl AsyncCliCommand for CmdAppDeploy {
}

let original_app_config: AppConfigV1 = AppConfigV1::parse_yaml(&config_str)?;
std::fs::write(&app_config_path, config_str)
.with_context(|| format!("Could not write file: '{}'", app_config_path.display()))?;

let mut app_config = original_app_config.clone();

app_config.owner = Some(owner.clone());
Expand Down
Loading