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

chore: update dfx deploy output #4104

Merged
merged 10 commits into from
Feb 11, 2025
4 changes: 2 additions & 2 deletions e2e/tests-dfx/deploy.bash
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ teardown() {
(
cd src
assert_command dfx deploy
assert_match "Installing code for"
assert_match "Installed code for"
)

assert_command dfx canister call hello_backend greet '("Banzai")'
assert_eq '("Hello, Banzai!")'

assert_command dfx deploy
assert_not_match "Installing code for"
assert_not_match "Installed code for"
assert_match "is already installed"
}

Expand Down
4 changes: 2 additions & 2 deletions e2e/tests-dfx/install.bash
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ teardown() {

assert_command dfx canister install --all

assert_match "Installing code for canister e2e_project_backend"
assert_match "Installed code for canister e2e_project_backend"
}

@test "install succeeds with network name" {
Expand All @@ -52,7 +52,7 @@ teardown() {

assert_command dfx canister install --all --network local

assert_match "Installing code for canister e2e_project_backend"
assert_match "Installed code for canister e2e_project_backend"
}

@test "install fails with network name that is not in dfx.json" {
Expand Down
18 changes: 9 additions & 9 deletions e2e/tests-dfx/mode_reinstall.bash
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ teardown() {
assert_command dfx canister install --mode=reinstall hello_backend

assert_match "YOU WILL LOSE ALL DATA IN THE CANISTER"
assert_match "Reinstalling code for canister hello_backend"
assert_match "Reinstalled code for canister hello_backend"
)
}

Expand All @@ -54,7 +54,7 @@ teardown() {

assert_match "YOU WILL LOSE ALL DATA IN THE CANISTER"

assert_not_match "Installing code for canister"
assert_not_match "Installed code for canister"
assert_contains "Refusing to install canister without approval"
assert_contains "User declined consent"
)
Expand All @@ -77,7 +77,7 @@ teardown() {
assert_command dfx deploy --mode=reinstall hello_backend

assert_match "YOU WILL LOSE ALL DATA IN THE CANISTER"
assert_match "Reinstalling code for canister hello_backend"
assert_match "Reinstalled code for canister hello_backend"
)
}

Expand All @@ -90,7 +90,7 @@ teardown() {

assert_match "YOU WILL LOSE ALL DATA IN THE CANISTER"

assert_not_match "Installing code for canister"
assert_not_match "Installed code for canister"
assert_contains "Refusing to install canister without approval"
assert_contains "User declined consent"
)
Expand Down Expand Up @@ -123,7 +123,7 @@ teardown() {
assert_match "You are about to reinstall the hello_frontend canister."
assert_not_match "You are about to reinstall the hello_backend canister."
assert_match "YOU WILL LOSE ALL DATA IN THE CANISTER"
assert_match "Reinstalling code for canister hello_frontend,"
assert_match "Reinstalled code for canister hello_frontend,"
)

# the hello_backend canister should not have been upgraded (which would reset the non-stable var)
Expand All @@ -141,24 +141,24 @@ teardown() {
assert_command dfx deploy --mode=reinstall hello_backend

assert_match "YOU WILL LOSE ALL DATA IN THE CANISTER"
assert_match "Reinstalling code for canister hello_backend"
assert_match "Reinstalled code for canister hello_backend"
)
echo y | (
assert_command dfx deploy --mode=reinstall hello_backend

assert_match "YOU WILL LOSE ALL DATA IN THE CANISTER"
assert_match "Reinstalling code for canister hello_backend"
assert_match "Reinstalled code for canister hello_backend"
)
echo YES | (
assert_command dfx deploy --mode=reinstall hello_backend

assert_match "YOU WILL LOSE ALL DATA IN THE CANISTER"
assert_match "Reinstalling code for canister hello_backend"
assert_match "Reinstalled code for canister hello_backend"
)
echo YeS | (
assert_command dfx deploy --mode=reinstall hello_backend

assert_match "YOU WILL LOSE ALL DATA IN THE CANISTER"
assert_match "Reinstalling code for canister hello_backend"
assert_match "Reinstalled code for canister hello_backend"
)
}
6 changes: 3 additions & 3 deletions e2e/tests-replica/deploy.bash
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ teardown() {
assert_command dfx canister create --all

assert_command dfx deploy
assert_match 'Installing code for canister'
assert_match 'Installed code for canister'
}

@test "dfx deploy supports arguments" {
Expand All @@ -85,13 +85,13 @@ teardown() {
# Therefore, there is no "attempting (install|upgrade)" message.

assert_command dfx deploy hello_backend
assert_match 'Installing code for canister'
assert_match 'Installed code for canister'

assert_command dfx canister call hello_backend greet '("First")'
assert_eq '("Hello, First!")'

assert_command dfx deploy hello_backend --upgrade-unchanged
assert_match 'Upgrading code for canister'
assert_match 'Upgraded code for canister'

assert_command dfx canister call hello_backend greet '("Second")'
assert_eq '("Hello, Second!")'
Expand Down
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(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't play well with the "ask for consent" and interactive parameter prompting in that can happen when installing a canister. To repro, for example:

$ dfx canister install --wasm /Users/ericswanson/d/sdk/e2e/assets/wasm/identity/main.wasm --mode reinstall react_rust_backend
⠁ Reinstalling code for canister react_rust_backend, with canister ID bkyz2-fmaaa-aaaaa-qaaaq-cai                           WARNING!
You are about to reinstall the react_rust_backend canister
This will OVERWRITE all the data and code in the canister.

YOU WILL LOSE ALL DATA IN THE CANISTER.


Do you want to proceed? yes/No
⠋ Reinstalling code for canister react_rust_backend, with canister ID bkyz2-fmaaa-aaaaa-qaaaq-cai  

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());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also conflicts with prompting about upgrades or for initialization arguments:

$ dfx deploy
...
⠂ Installing canisters...
⠁ Installing code for canister dd_backend, with canister ID br5f7-7uaaa-aaaaa-qaaca-cai                                                              
This canister requires an initialization argument.
Auto-completions: aaabbbccc, abc3, abc4, alice, alice_e2e, anonymous, bob, bob_e2e, dd_backend, dd_frontend, default, ed, iii, k3, kt2, kt4, mainnet,⠠ Installing canisters...
⠤ Installing code for canister dd_backend, with canister ID br5f7-7uaaa-aaaaa-qaaca-cai  


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
Loading
Loading