-
Notifications
You must be signed in to change notification settings - Fork 261
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·239 lines (200 loc) · 7.43 KB
/
deploy.sh
File metadata and controls
executable file
·239 lines (200 loc) · 7.43 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/usr/bin/env bash
set -eux
# shellcheck disable=SC2207
GRAPH_CLI="npx --package=@graphprotocol/graph-cli --yes -- graph"
# shellcheck disable=SC2207
GOLDSKY_CLI="npx --package=@goldskycom/cli --yes -- goldsky"
SUPPORTED_VENDORS=( "graph" "alchemy" "superfluid" "goldsky" "airstack" )
VENDOR=""
NETWORK=""
DEPLOYMENT_ENV=""
VERSION_LABEL=""
print_usage_and_exit() {
echo "Usage: $0 -o graph|alchemy|superfluid|goldsky|airstack -n <network_name> -r <deployment_env> -v <version_label>"
exit 1
}
# Command-line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-o|--vendor)
VENDOR="${2}"
shift 2
;;
-n|--network)
NETWORK="$2"
shift 2
;;
-r|--deployment-env)
DEPLOYMENT_ENV="$2"
shift 2
;;
-v|--version-label)
VERSION_LABEL="$2"
shift 2
;;
*)
echo "Unknown option: $1"
print_usage_and_exit
;;
esac
done
prepare_deployment() {
# Read environment variables directly, with a fallback Git command for commit_hash
local commit_hash="${GITHUB_SHA:-$(git rev-parse HEAD)}"
local configuration="${CONFIGURATION:-v1}"
# Get ABI
echo "Getting ABI..."
node "./scripts/getAbi.js"
# Prepare subgraph manifest
echo "Preparing subgraph manifest..."
./tasks/prepare-manifest.sh mock
# Generate meta.ignore.ts file
echo "Generating meta.ignore.ts file..."
COMMIT_HASH="$commit_hash" CONFIGURATION="$configuration" yarn generate-sf-meta
# Generate AssemblyScript types
echo "Generating AssemblyScript types..."
yarn codegen
# Get Hosted Service Networks from metadata
echo "Getting Hosted Service Networks from metadata..."
npx ts-node "./scripts/getHostedServiceNetworks.ts"
}
deploy_to_graph() {
local network="$1"
local -A networkToSubgraphNames=(
["xdai-mainnet"]="superfluid-v1-gnosis"
["polygon-mainnet"]="superfluid-v1-polygon"
["optimism-mainnet"]="superfluid-v1-optimism"
["arbitrum-one"]="superfluid-v1-arbitrum"
["eth-mainnet"]="superfluid-v1-ethereum"
["avalanche-c"]="superfluid-v1-avalanche"
["scroll-mainnet"]="superfluid-v1-scroll"
["bsc-mainnet"]="superfluid-v1-bnb"
["celo-mainnet"]="superfluid-v1-celo"
["base-mainnet"]="superfluid-v1-base"
["base-sepolia"]="superfluid-v1-base-sepolia"
)
local subgraphName="${SUBGRAPH_NAME:-${networkToSubgraphNames[$network]}}"
echo "********* Deploying $network subgraph $subgraphName to The Graph Network. **********"
if ! $GRAPH_CLI deploy "$subgraphName" --deploy-key "$THE_GRAPH_ACCESS_TOKEN" --version-label "$VERSION_LABEL"; then
echo "Error: Deployment to The Graph Network failed for $network"
exit 1
fi
}
deploy_to_alchemy() {
local network="$1"
# name mapping for subgraphs (no excuse here for not having canonical names)
local -A legacyNetworkNames=(
["xdai-mainnet"]="xdai"
["polygon-mainnet"]="matic"
["degenchain"]="degen-mainnet"
)
local alchemyNetwork="${legacyNetworkNames[$network]:-$network}"
# If network needs to be replaced in subgraph.yaml
if [[ -n "${legacyNetworkNames[$network]}" ]]; then
echo "Replacing network name in subgraph.yaml for $network to ${legacyNetworkNames[$network]}"
sed -i "s/^\([[:space:]]*network:\)[[:space:]]*[^[:space:]]*/\1 ${legacyNetworkNames[$network]}/" ./subgraph.yaml
fi
echo "********* Deploying $network ($alchemyNetwork) subgraph to Alchemy. **********"
$GRAPH_CLI deploy "$alchemyNetwork" \
--version-label "$VERSION_LABEL" \
--node https://subgraphs.alchemy.com/api/subgraphs/deploy \
--deploy-key "$ALCHEMY_DEPLOY_KEY" \
--ipfs https://ipfs.satsuma.xyz
}
deploy_to_superfluid() {
local network="$1"
echo "********* Deploying $network subgraph to Superfluid (self hosted). **********"
local nodeUrl="${SUBGRAPH_URL_TEMPLATE//\{\{NETWORK\}\}/$network}/admin/"
local subgraphName="protocol-$DEPLOYMENT_ENV"
echo "node url: $nodeUrl, subgraph name: $subgraphName"
if ! $GRAPH_CLI create "$subgraphName" --node "$nodeUrl"; then
echo "Error: Creation of subgraph $subgraphName on Superfluid (self hosted) failed for $network"
exit 1
fi
if ! $GRAPH_CLI deploy "$subgraphName" --version-label "$VERSION_LABEL" --node "$nodeUrl" --ipfs "$SUPERFLUID_IPFS_API"; then
echo "Error: Deployment to Superfluid (self hosted) failed for $network"
exit 1
fi
}
deploy_to_goldsky() {
local network="$1"
# TODO: use tagging?
# Get subgraph version from package.json
PACKAGE_JSON_PATH="package.json"
SUBGRAPH_VERSION=$(jq -r '.version' $PACKAGE_JSON_PATH)
local subgraphName="protocol-$DEPLOYMENT_ENV-$network/$SUBGRAPH_VERSION"
# Note: when using Graph CLI to deploy, it implicitly triggers build too, but Goldsky CLI doesn't, so we do it explicitly.
if ! $GRAPH_CLI build; then
echo "Error: Build for Goldsky failed"
exit 1
fi
echo "********* Deploying $network subgraph $subgraphName to Goldsky. **********"
if ! $GOLDSKY_CLI subgraph deploy "$subgraphName" --path . --token "$GOLDSKY_API_KEY"; then
echo "Error: Deployment to Goldsky failed for $network"
exit 1
fi
}
deploy_to_airstack() {
local network="$1"
local nodeUrl="https://subgraph.airstack.xyz/indexer/"
local subgraphName="protocol-$DEPLOYMENT_ENV-$network"
echo "********* Deploying $network subgraph $subgraphName to Airstack. **********"
if ! $GRAPH_CLI create "$subgraphName" --node "$nodeUrl" --access-token "$AIRSTACK_API_KEY"; then
echo "Error: Creation of subgraph $subgraphName on Airstack failed for $network"
exit 1
fi
if ! $GRAPH_CLI deploy --version-label "$VERSION_LABEL" --node "$nodeUrl" --deploy-key "$AIRSTACK_API_KEY" --ipfs https://ipfs.airstack.xyz/ipfs/api/v0 --headers '{"Authorization": "'"$AIRSTACK_API_KEY"'"}' "$subgraphName"; then
echo "Error: Deployment to Airstack failed for $network"
exit 1
fi
}
# Vendor specific function dispatcher
# Expected arguments:
# $1 - vendor
# $2 - canonical network name
deploy_to() {
local vendor="$1"
local network="$2"
npx ts-node ./scripts/buildNetworkConfig.ts "$network" "$vendor"
# prepare the manifest prior to deployment
# this generates the subgraph.yaml and
# inputs the correct addresses for the specified network ($2)
./tasks/prepare-manifest.sh "$network"
case "$vendor" in
graph)
deploy_to_graph "$network"
;;
alchemy)
deploy_to_alchemy "$network"
;;
superfluid)
deploy_to_superfluid "$network"
;;
goldsky)
deploy_to_goldsky "$network"
;;
airstack)
deploy_to_airstack "$network"
;;
*)
print_usage_and_exit
;;
esac
}
# Argument validation
if [ -z "$VENDOR" ] || [ -z "$NETWORK" ] || [ -z "$DEPLOYMENT_ENV" ] || [ -z "$VERSION_LABEL" ]; then
print_usage_and_exit
fi
# We can safely ignore this warning, because the value in vendor won't contain whitespaces
# shellcheck disable=SC2199,SC2076
if [[ ! " ${SUPPORTED_VENDORS[@]} " =~ " $VENDOR " ]]; then
print_usage_and_exit
fi
#Prepare deployment
# Prepare deployment
if ! prepare_deployment; then
echo "Error: Failed to prepare deployment"
exit 1
fi
# Deploy the specified network
deploy_to "$VENDOR" "$NETWORK"