From 58d3529f3bbcd0f2c9c30f2678a60096e55c1a1a Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 16 Sep 2022 09:43:58 +0200 Subject: [PATCH 1/6] Env vars don't like hyphens --- src/dfx/src/lib/builders/mod.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/dfx/src/lib/builders/mod.rs b/src/dfx/src/lib/builders/mod.rs index a45bd71a70..25867afebd 100644 --- a/src/dfx/src/lib/builders/mod.rs +++ b/src/dfx/src/lib/builders/mod.rs @@ -316,14 +316,20 @@ pub fn environment_variables<'a>( }; vars.push(( - Owned(format!("CANISTER_CANDID_PATH_{}", canister.get_name())), + Owned(format!( + "CANISTER_CANDID_PATH_{}", + canister.get_name().replace("-", "_") + )), Borrowed(candid_path), )); } } for canister in pool.get_canister_list() { vars.push(( - Owned(format!("CANISTER_ID_{}", canister.get_name())), + Owned(format!( + "CANISTER_ID_{}", + canister.get_name().replace("-", "_") + )), Owned(canister.canister_id().to_text().into()), )); } From e24cc2c9ef62316739ecd4e5400567ffed64dde1 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 20 Sep 2022 16:19:16 +0200 Subject: [PATCH 2/6] lint --- src/dfx/src/lib/builders/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dfx/src/lib/builders/mod.rs b/src/dfx/src/lib/builders/mod.rs index 25867afebd..da19322364 100644 --- a/src/dfx/src/lib/builders/mod.rs +++ b/src/dfx/src/lib/builders/mod.rs @@ -318,7 +318,7 @@ pub fn environment_variables<'a>( vars.push(( Owned(format!( "CANISTER_CANDID_PATH_{}", - canister.get_name().replace("-", "_") + canister.get_name().replace('-', "_") )), Borrowed(candid_path), )); @@ -328,7 +328,7 @@ pub fn environment_variables<'a>( vars.push(( Owned(format!( "CANISTER_ID_{}", - canister.get_name().replace("-", "_") + canister.get_name().replace('-', "_") )), Owned(canister.canister_id().to_text().into()), )); From 110e0729d67dfb2ec95e4493b15986036548fb0e Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 20 Sep 2022 16:37:19 +0200 Subject: [PATCH 3/6] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f2d752ab5..0eeb87cfaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,10 @@ If you want to disable this behavior, you can config it in dfx.json: } } +### fix: Valid canister-based env vars + +Hyphens are not valid in shell environment variables, but do occur in canister names such as `smiley-dapp`. This poses a problem for vars with names such as `CANISTER_ID_${CANISTER_NAME}`. With this change, hyphens are replaced with underscores in environment variables. The canister id of `smiley-dapp` will be available as `CANISTER_ID_smiley_dapp`. Other environment variables are unaffected. + ### feat: Add dfx sns deploy This allows users to deploy a set of SNS canisters. From 19e66884eefb81e3fb00a5a933763d98013a314b Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 20 Sep 2022 16:38:10 +0200 Subject: [PATCH 4/6] Test by rename --- e2e/assets/post_install/dfx.json | 2 +- e2e/tests-dfx/install.bash | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/e2e/assets/post_install/dfx.json b/e2e/assets/post_install/dfx.json index 13f72c635f..5a53033c86 100644 --- a/e2e/assets/post_install/dfx.json +++ b/e2e/assets/post_install/dfx.json @@ -1,7 +1,7 @@ { "version": 1, "canisters": { - "postinstall": { + "post-install": { "main": "main.mo", "post_install": "echo hello-file" }, diff --git a/e2e/tests-dfx/install.bash b/e2e/tests-dfx/install.bash index c831434ea6..f86ccf89ef 100644 --- a/e2e/tests-dfx/install.bash +++ b/e2e/tests-dfx/install.bash @@ -99,7 +99,7 @@ teardown() { assert_command dfx canister create --all assert_command dfx build - assert_command dfx canister install postinstall + assert_command dfx canister install post-install assert_match 'hello-file' assert_command dfx canister install postinstall_script @@ -133,11 +133,11 @@ teardown() { @test "post-install tasks discover dependencies" { install_asset post_install dfx_start - echo "echo hello \$CANISTER_ID_postinstall" >> postinstall.sh + echo "echo hello \$CANISTER_ID_post_install" >> postinstall.sh assert_command dfx canister create --all assert_command dfx build - id=$(dfx canister id postinstall) + id=$(dfx canister id post-install) assert_command dfx canister install postinstall_script assert_match "hello $id" From 60792355ea5dcca3f20de24c272bab6257bc6e38 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 20 Sep 2022 16:41:07 +0200 Subject: [PATCH 5/6] Update docs --- docs/cli-reference/dfx-envars.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/cli-reference/dfx-envars.md b/docs/cli-reference/dfx-envars.md index e8d35dbd40..edf0f37a13 100644 --- a/docs/cli-reference/dfx-envars.md +++ b/docs/cli-reference/dfx-envars.md @@ -16,9 +16,9 @@ For example, if you have a `whoami_frontend` canister that lists `whoami` under ## CANISTER_ID\_{canister.name} -Use environment variables with the `CANISTER_ID` prefix to reference the canister identifier for each canister in the `dfx.json` file for your project. +Use environment variables with the `CANISTER_ID` prefix to reference the canister identifier for each canister in the `dfx.json` file for your project. Hyphens are invalid in environment variables and are replaced by underscores. -For example, if you have a `linkedup` project that consists of the `linkedup` and `connectd` canisters, you could use the `CANISTER_ID_linkedup` and `CANISTER_ID_connectd` environment variables to refer to the canister identifiers—for example `ryjl3-tyaaa-aaaaa-aaaba-cai` and `rrkah-fqaaa-aaaaa-aaaaq-cai`—created for your project. +For example, if you have a `linkedup` project that consists of the `linkedup` and `connect-d` canisters, you could use the `CANISTER_ID_linkedup` and `CANISTER_ID_connect_d` environment variables to refer to the canister identifiers—for example `ryjl3-tyaaa-aaaaa-aaaba-cai` and `rrkah-fqaaa-aaaaa-aaaaq-cai`—created for your project. ## DFX_CONFIG_ROOT From 3977e1439bab0531b5011ede8b068c5ea018a589 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 20 Sep 2022 18:18:59 +0200 Subject: [PATCH 6/6] Revert "Test by rename" This reverts commit 19e66884eefb81e3fb00a5a933763d98013a314b. --- e2e/assets/post_install/dfx.json | 2 +- e2e/tests-dfx/install.bash | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/e2e/assets/post_install/dfx.json b/e2e/assets/post_install/dfx.json index 5a53033c86..13f72c635f 100644 --- a/e2e/assets/post_install/dfx.json +++ b/e2e/assets/post_install/dfx.json @@ -1,7 +1,7 @@ { "version": 1, "canisters": { - "post-install": { + "postinstall": { "main": "main.mo", "post_install": "echo hello-file" }, diff --git a/e2e/tests-dfx/install.bash b/e2e/tests-dfx/install.bash index f86ccf89ef..c831434ea6 100644 --- a/e2e/tests-dfx/install.bash +++ b/e2e/tests-dfx/install.bash @@ -99,7 +99,7 @@ teardown() { assert_command dfx canister create --all assert_command dfx build - assert_command dfx canister install post-install + assert_command dfx canister install postinstall assert_match 'hello-file' assert_command dfx canister install postinstall_script @@ -133,11 +133,11 @@ teardown() { @test "post-install tasks discover dependencies" { install_asset post_install dfx_start - echo "echo hello \$CANISTER_ID_post_install" >> postinstall.sh + echo "echo hello \$CANISTER_ID_postinstall" >> postinstall.sh assert_command dfx canister create --all assert_command dfx build - id=$(dfx canister id post-install) + id=$(dfx canister id postinstall) assert_command dfx canister install postinstall_script assert_match "hello $id"