Skip to content

Commit

Permalink
Condense deploy output
Browse files Browse the repository at this point in the history
  • Loading branch information
adamspofford-dfinity committed Feb 7, 2025
1 parent fee3a32 commit 222486f
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 35 deletions.
10 changes: 9 additions & 1 deletion src/dfx-core/src/canister/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,22 @@ pub async fn build_wallet_canister(
.map_err(CanisterBuilderError::WalletCanisterCaller)
}

pub fn install_mode_to_prompt(mode: &InstallMode) -> &'static str {
pub fn install_mode_to_present_tense(mode: &InstallMode) -> &'static str {
match mode {
InstallMode::Install => "Installing",
InstallMode::Reinstall => "Reinstalling",
InstallMode::Upgrade { .. } => "Upgrading",
}
}

pub fn install_mode_to_past_tense(mode: &InstallMode) -> &'static str {
match mode {
InstallMode::Install => "Installed",
InstallMode::Reinstall => "Reinstalled",
InstallMode::Upgrade { .. } => "Upgraded",
}
}

pub async fn install_canister_wasm(
agent: &Agent,
canister_id: Principal,
Expand Down
4 changes: 2 additions & 2 deletions src/dfx/src/actors/pocketic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl Actor for PocketIc {
}

fn stopping(&mut self, _ctx: &mut Self::Context) -> Running {
warn!(self.logger, "Stopping PocketIC...");
debug!(self.logger, "Stopping PocketIC...");
if let Some(sender) = self.stop_sender.take() {
let _ = sender.send(());
}
Expand All @@ -168,7 +168,7 @@ impl Actor for PocketIc {
let _ = join.join();
}

warn!(self.logger, "Stopped.");
debug!(self.logger, "Stopped.");
Running::Stop
}
}
Expand Down
24 changes: 18 additions & 6 deletions src/dfx/src/commands/canister/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use crate::lib::root_key::fetch_root_key_if_needed;
use crate::util::blob_from_arguments;
use crate::util::clap::argument_from_cli::ArgumentFromCliLongOpt;
use crate::util::clap::install_mode::{InstallModeHint, InstallModeOpt};
use dfx_core::canister::{install_canister_wasm, install_mode_to_prompt};
use dfx_core::canister::{
install_canister_wasm, install_mode_to_past_tense, install_mode_to_present_tense,
};
use dfx_core::identity::CallSender;

use crate::lib::operations::canister::skip_remote_canister;
Expand Down Expand Up @@ -103,12 +105,15 @@ pub async fn exec(
)?;
let wasm_module = dfx_core::fs::read(wasm_path)?;
let mode = mode_hint.to_install_mode_with_wasm_path()?;
info!(
env.get_logger(),
"{} code for canister {}",
install_mode_to_prompt(&mode),
canister_id,
let spinner = env.new_spinner(
format!(
"{} code for canister {}",
install_mode_to_present_tense(&mode),
canister_id,
)
.into(),
);

install_canister_wasm(
env.get_agent(),
canister_id,
Expand All @@ -120,6 +125,13 @@ pub async fn exec(
opts.yes,
)
.await?;
spinner.finish_and_clear();
info!(
env.get_logger(),
"{} code for canister {}",
install_mode_to_past_tense(&mode),
canister_id
);
Ok(())
} else {
bail!("When installing a canister by its ID, you must specify `--wasm` option.")
Expand Down
2 changes: 1 addition & 1 deletion src/dfx/src/commands/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ fn display_urls(env: &dyn Environment) -> DfxResult {
info!(log, "URLs:");
let green = Style::new().green();
if !frontend_urls.is_empty() {
info!(log, " Frontend canister via browser");
info!(log, " Frontend canister via browser:");
for (name, (url1, url2)) in frontend_urls {
if let Some(url2) = url2 {
info!(log, " {}:", name);
Expand Down
28 changes: 16 additions & 12 deletions src/dfx/src/lib/builders/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ use candid::Principal as CanisterId;
use console::style;
use dfx_core::config::model::network_descriptor::NetworkDescriptor;
use fn_error_context::context;
use slog::{o, Logger};
use slog::{debug, info, o, Logger};
use std::fs;
use std::path::Path;
use std::process::{Command, Stdio};

/// Set of extras that can be specified in the dfx.json.
struct AssetsBuilderExtra {
Expand Down Expand Up @@ -106,7 +107,7 @@ impl CanisterBuilder for AssetsBuilder {

fn postbuild(
&self,
_: &dyn Environment,
env: &dyn Environment,
pool: &CanisterPool,
info: &CanisterInfo,
config: &BuildConfig,
Expand All @@ -126,6 +127,7 @@ impl CanisterBuilder for AssetsBuilder {
)?;

build_frontend(
env,
pool.get_logger(),
info.get_workspace_root(),
&config.network_name,
Expand Down Expand Up @@ -179,6 +181,7 @@ fn unpack_did(generate_output_dir: &Path) -> DfxResult<()> {

#[context("Failed to build frontend for network '{}'.", network_name)]
fn build_frontend(
env: &dyn Environment,
logger: &slog::Logger,
project_root: &Path,
network_name: &str,
Expand All @@ -192,20 +195,20 @@ fn build_frontend(

if custom_build_frontend {
for command in build {
slog::info!(
info!(
logger,
r#"{} '{}'"#,
style("Executing").green().bold(),
command
);

super::run_command(command, &vars, project_root)
.with_context(|| format!("Failed to run {}.", command))?;
.with_context(|| format!("Failed to run {command}.",))?;
}
} else if build_frontend {
// Frontend build.
slog::info!(logger, "Building frontend...");
let mut cmd = std::process::Command::new(program::NPM);
let spinner = env.new_spinner("Building frontend...".into());
let mut cmd = Command::new(program::NPM);

// Provide DFX_NETWORK at build time
cmd.env("DFX_NETWORK", network_name);
Expand All @@ -225,27 +228,28 @@ fn build_frontend(
}

cmd.current_dir(project_root)
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped());
slog::debug!(logger, "Running {:?}...", cmd);
.stdout(Stdio::piped())
.stderr(Stdio::piped());
debug!(logger, "Running {cmd:?}...");

let output = cmd
.output()
.with_context(|| format!("Error executing {:#?}", cmd))?;
.with_context(|| format!("Error executing {cmd:#?}"))?;
if !output.status.success() {
return Err(DfxError::new(BuildError::CommandError(
format!("{:?}", cmd),
format!("{cmd:?}",),
output.status,
String::from_utf8_lossy(&output.stdout).to_string(),
String::from_utf8_lossy(&output.stderr).to_string(),
)));
} else if !output.stderr.is_empty() {
// Cannot use eprintln, because it would interfere with the progress bar.
slog::debug!(
debug!(
logger,
"Frontend build succeed:\n{}",
String::from_utf8_lossy(&output.stderr)
);
spinner.finish_and_clear();
}
}
Ok(())
Expand Down
18 changes: 11 additions & 7 deletions src/dfx/src/lib/operations/canister/deploy_canisters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,13 @@ async fn register_canisters(
if canisters_to_create.is_empty() {
info!(env.get_logger(), "All canisters have already been created.");
} else if env.get_network_descriptor().is_playground() {
info!(env.get_logger(), "Reserving canisters in playground...");
let spinner = env.new_spinner("Reserving canisters in playground...".into());
for canister_name in &canisters_to_create {
reserve_canister_with_playground(env, canister_name).await?;
}
spinner.finish_and_clear();
} else {
info!(env.get_logger(), "Creating canisters...");
let spinner = env.new_spinner("Creating canisters...".into());
for canister_name in &canisters_to_create {
let config_interface = config.get_config();
let compute_allocation = config_interface
Expand Down Expand Up @@ -285,6 +286,7 @@ async fn register_canisters(
)
.await?;
}
spinner.finish_and_clear();
}
Ok(())
}
Expand All @@ -297,15 +299,17 @@ async fn build_canisters(
config: &Config,
env_file: Option<PathBuf>,
) -> DfxResult<CanisterPool> {
let log = env.get_logger();
info!(log, "Building canisters...");
let spinner = env.new_spinner("Building canisters...".into());
let build_mode_check = false;
let canister_pool = CanisterPool::load(env, build_mode_check, canisters_to_load)?;

let build_config = BuildConfig::from_config(config)?
.with_canisters_to_build(canisters_to_build.into())
.with_env_file(env_file);
canister_pool.build_or_fail(env, log, &build_config).await?;
canister_pool
.build_or_fail(env, env.get_logger(), &build_config)
.await?;
spinner.finish_and_clear();
Ok(canister_pool)
}

Expand All @@ -325,7 +329,7 @@ async fn install_canisters(
no_asset_upgrade: bool,
always_assist: bool,
) -> DfxResult {
info!(env.get_logger(), "Installing canisters...");
let spinner = env.new_spinner("Installing canisters...".into());

let mut canister_id_store = env.get_canister_id_store()?;

Expand All @@ -352,7 +356,7 @@ async fn install_canisters(
)
.await?;
}

spinner.finish_and_clear();
Ok(())
}

Expand Down
24 changes: 18 additions & 6 deletions src/dfx/src/lib/operations/canister/install_canister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ use anyhow::{anyhow, bail, Context};
use backoff::backoff::Backoff;
use backoff::ExponentialBackoff;
use candid::Principal;
use dfx_core::canister::{build_wallet_canister, install_canister_wasm, install_mode_to_prompt};
use dfx_core::canister::{
build_wallet_canister, install_canister_wasm, install_mode_to_past_tense,
install_mode_to_present_tense,
};
use dfx_core::cli::ask_for_consent;
use dfx_core::config::model::canister_id_store::CanisterIdStore;
use dfx_core::config::model::network_descriptor::NetworkDescriptor;
Expand Down Expand Up @@ -83,11 +86,13 @@ pub async fn install_canister(
installed_module_hash.is_some(),
wasm_memory_persistence_embedded,
);
let mode_str = install_mode_to_prompt(&mode);
let canister_name = canister_info.get_name();
info!(
log,
"{mode_str} code for canister {canister_name}, with canister ID {canister_id}",
let spinner = env.new_spinner(
format!(
"{mode_str} code for canister {canister_name}, with canister ID {canister_id}",
mode_str = install_mode_to_present_tense(&mode)
)
.into(),
);
if !skip_consent && matches!(mode, InstallMode::Reinstall | InstallMode::Upgrade { .. }) {
let candid = read_module_metadata(agent, canister_id, "candid:service").await;
Expand Down Expand Up @@ -143,7 +148,8 @@ pub async fn install_canister(
&& matches!(&installed_module_hash, Some(old_hash) if old_hash[..] == new_hash[..])
&& !upgrade_unchanged
{
println!(
info!(
log,
"Module hash {} is already installed.",
hex::encode(installed_module_hash.as_ref().unwrap())
);
Expand Down Expand Up @@ -279,6 +285,12 @@ The command line value will be used.",
env_file.or_else(|| config.as_ref()?.get_config().output_env_file.as_deref()),
)?;
}
spinner.finish_and_clear();
info!(
log,
"{mode_str} code for canister {canister_name}, with canister ID {canister_id}",
mode_str = install_mode_to_past_tense(&mode)
);

Ok(())
}
Expand Down

0 comments on commit 222486f

Please sign in to comment.