This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
forked from dfinity/nns-dapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·107 lines (87 loc) · 3.23 KB
/
deploy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env bash
set -euo pipefail
export PATH="$PWD/scripts:$PATH"
cd "$(dirname "$(realpath "$0")")" || exit
# Get commands for network configuration.
. scripts/network-config
help_text() {
cat <<-"EOF"
Deploys the nns-dapp or internet identity to a network.
This file will recreate the arguments file and override it.
If you want to use a custom arguments file, use dfx directly.
Usage:
Preflight: Make sure that you can run build.sh before using deploy.sh. The build
script requires a number of dependencies. If you cannot run "build.sh" then
"dfx deploy" will fail. To check, run: DFX_NETWORK=mainnet build.sh
./deploy.sh --nns-dapp <network>
Deploys nns-dapp to the selected network. The default is "local".
The available networks are the ones listed in dfx.json.
EOF
}
#
DFX_NETWORK=local # which network to deploy to
# Whether to run each action:
DEPLOY_II="false"
DEPLOY_NNS_DAPP="false"
DEPLOY_SNS_AGGREGATOR="false"
while (($# > 0)); do
env="$1"
shift 1
case "$env" in
--help)
help_text | "${PAGER:-less}"
exit 0
;;
--ii)
DEPLOY_II="true"
;;
--nns-dapp)
DEPLOY_NNS_DAPP="true"
;;
--sns-aggregator)
DEPLOY_SNS_AGGREGATOR="true"
;;
*)
DFX_NETWORK="$env"
# Check that the network is valid. (Using a function from `./scripts/network-config`.)
assert_dfx_network_var_is_configured || exit 1
;;
esac
done
export DFX_NETWORK
if [[ "$DEPLOY_II" == "true" ]]; then
dfx deploy --network "$DFX_NETWORK" internet_identity --no-wallet
echo "Waiting for II to be stable..."
sleep 4
fi
# Reference: `./config.sh`
# TODO: Do we want to share this with `config.sh`?
first_not_null() {
for x in "$@"; do
if [ "$x" != "null" ]; then
echo "$x"
return
fi
done
echo "null"
}
canister_static_url_from_id() {
: "If we have a canister ID, insert it into HOST as a subdomain."
test -z "${1:-}" || { static_host | sed -E "s,^(https?://)?,&${1}.,g"; }
}
if [[ "$DEPLOY_SNS_AGGREGATOR" == "true" ]]; then
dfx canister --network "$DFX_NETWORK" create sns_aggregator --no-wallet || echo "canister for SNS Aggregator may have been created already"
dfx deploy --network "$DFX_NETWORK" sns_aggregator --no-wallet --upgrade-unchanged --argument '(opt record { update_interval_ms = 1000; fast_interval_ms = 1_000_000_000; })'
SNS_AGGREGATOR_CANISTER_ID="$(dfx canister --network "$DFX_NETWORK" id sns_aggregator 2>/dev/null || true)"
SNS_AGGREGATOR_CANISTER_URL="$(canister_static_url_from_id "$SNS_AGGREGATOR_CANISTER_ID")"
echo "SNS Aggregator deployed to: $SNS_AGGREGATOR_CANISTER_URL"
fi
if [[ "$DEPLOY_NNS_DAPP" == "true" ]]; then
# Note: NNS Dapp is the only canister provided by this repo, however dfx.json
# includes other canisters for testing purposes. If testing you MAY wish
# to deploy these other canisters as well, but you probably don't.
DFX_NETWORK="$DFX_NETWORK" ./config.sh
dfx canister --network "$DFX_NETWORK" create nns-dapp --no-wallet || echo "canister for NNS Dapp may have been created already"
dfx deploy nns-dapp --argument "$(cat "nns-dapp-arg-${DFX_NETWORK}.did")" --upgrade-unchanged --network "$DFX_NETWORK" --no-wallet
echo "NNS Dapp deployed to: $(dfx-canister-url --network "$DFX_NETWORK" nns-dapp)"
fi