Summary
Request for icp.yaml to support per-environment build command overrides, so that icp deploy -e staging and icp deploy -e prod can run different build scripts without workarounds.
Current behavior
icp.yaml supports a single build command for a canister, shared across all environments:
canisters:
- name: frontend
recipe:
type: "@dfinity/asset-canister@v2.1.0"
configuration:
dir: frontend/dist
build:
- "npm run build:${ICP_ENVIRONMENT:-prod}"
environments:
- name: staging
network: ic
canisters: [frontend, backend]
- name: prod
network: ic
canisters: [frontend, backend]
The intent was to use ${ICP_ENVIRONMENT:-prod} to branch per environment. However, icp-cli does not export ICP_ENVIRONMENT to build subprocess shells — it only reads it as an input flag. The shell variable therefore always falls back to prod, so both icp deploy -e staging and icp deploy -e prod run npm run build:prod.
Confirmed via icp deploy -e staging --debug:
> @yogabuild/amazing@0.14.0 build:prod
> vite build --mode prod
[vite.config] mode: prod | ICP_ENVIRONMENT: undefined
Desired behavior
One of the following (or both):
Option A — Per-environment build overrides in icp.yaml
canisters:
- name: frontend
recipe:
type: "@dfinity/asset-canister@v2.1.0"
configuration:
dir: frontend/dist
build:
- "npm run build:prod" # default
environments:
- name: staging
network: ic
canisters:
- name: frontend
recipe:
configuration:
build:
- "npm run build:staging"
- name: backend
- name: prod
network: ic
canisters: [frontend, backend]
Option B — icp-cli exports ICP_ENVIRONMENT to build subprocesses
When running icp deploy -e staging, automatically export ICP_ENVIRONMENT=staging into the shell environment that runs the build commands. This would make ${ICP_ENVIRONMENT:-prod} work as expected, and the current icp.yaml would work without any changes.
Actual workaround
AFAIK my options are to pre-set the variable before calling icp:
ICP_ENVIRONMENT=staging icp deploy frontend -e staging
and have them as an npm command like npm run deploy:staging.
This works, but isn’t exactly elegant
… I mean I miss typing icp deploy
![]()
Thanks — the environment system is a great step forward over dfx, this would push it a bit further.