-
Notifications
You must be signed in to change notification settings - Fork 1
/
blockscout_build.sh
223 lines (193 loc) · 6.16 KB
/
blockscout_build.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
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
#!/bin/bash
if [ $# -lt 3 ]; then
echo "Insufficient # of parameters supplied."
exit 1
fi
CONSORTIUM_IP=$1
WEBSOCKET_IP=$2
DATABASE_PW=$3
RPC_PORT=${4:-9933}
WEBSOCKET_PORT=${5:-9944}
# Erlang VM & Elixir Install
wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb && sudo dpkg -i erlang-solutions_1.0_all.deb
sudo apt-get update
sudo apt-get -y install esl-erlang=1:21.1.1-1
sudo apt-get -y install elixir=1.7.4-1
# gcc, make and build-essential Install
sudo apt-get install make
sudo apt-get -y install gcc
sudo apt-get -y install build-essential
# nginx Install
sudo apt-get -y install nginx && sudo ufw allow 'Nginx HTTP'
# Node.js & NPM Install
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get -y install nodejs
sudo ln -s /usr/bin/nodejs /usr/bin/node
# PostgreSQL Install
echo 'deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main' sudo tee -a /etc/apt/sources.list.d/pgdg.list
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update && sudo apt-get -y install postgresql
sudo apt-get update && sudo apt-get -y install postgresql-client
# PostgreSQL Configuration
sudo -u postgres psql -U postgres -d postgres -c "alter user postgres with password '$DATABASE_PW';"
# Git Install & Clone
sudo apt-get install -y git
sudo git clone https://github.com/poanetwork/blockscout.git && echo "cloned"
cd blockscout
sudo git checkout 53ea60c3 && echo "checked out"; cd -
sudo chmod -R a+x blockscout && echo "permissions granted"
export ETHEREUM_JSONRPC_VARIANT=geth
# Install Mix Dependencies
cd blockscout
sudo MIX_ENV=prod mix local.hex --force && echo "hex installed"
sudo MIX_ENV=prod mix deps.update libsecp256k1
sudo MIX_ENV=prod mix do deps.get, local.rebar --force, deps.compile, compile && echo "mix deps installed"
# Update Explorer Configuration Files
cd apps/explorer/config/prod
echo "
use Mix.Config
config :explorer,
json_rpc_named_arguments: [
transport: EthereumJSONRPC.HTTP,
transport_options: [
http: EthereumJSONRPC.HTTP.HTTPoison,
url: \"http://$CONSORTIUM_IP:$RPC_PORT\",
method_to_url: [
eth_call: \"http://$CONSORTIUM_IP:$RPC_PORT\,
eth_getBalance: \"http://$CONSORTIUM_IP:$RPC_PORT\",
trace_replayTransaction: \"http://$CONSORTIUM_IP:$RPC_PORT\"
],
http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: [pool: :ethereum_jsonrpc]]
],
variant: EthereumJSONRPC.Geth
],
subscribe_named_arguments: [
transport: EthereumJSONRPC.WebSocket,
transport_options: [
web_socket: EthereumJSONRPC.WebSocket.WebSocketClient,
url: \"ws://$WEBSOCKET_IP:$WEBSOCKET_PORT\"
],
variant: EthereumJSONRPC.Geth
]" | sudo tee geth.exs
cd -
cd apps/explorer/config
echo "
use Mix.Config
config :explorer, Explorer.Repo,
username: \"postgres\",
password: \"$DATABASE_PW\",
database: \"explorer_test\",
hostname: \"localhost\",
port: \"5432\",
#url: \"postgres:localhost:5432/explorer_test\",
pool_size: String.to_integer(System.get_env(\"POOL_SIZE\") || \"10\"),
#ssl: String.equivalent?(System.get_env(\"ECTO_USE_SSL\") || \"true\", \"true\"),
prepare: :unnamed,
timeout: :timer.seconds(60)
variant =
if is_nil(System.get_env(\"ETHEREUM_JSONRPC_VARIANT\")) do
\"geth\"
else
System.get_env(\"ETHEREUM_JSONRPC_VARIANT\")
|> String.split(\".\")
|> List.last()
|> String.downcase()
end" | sudo tee prod.exs
cd -
# Update Indexer Configuration Files
cd apps/indexer/config/prod
echo "
use Mix.Config
config :indexer,
block_interval: :timer.seconds(5),
json_rpc_named_arguments: [
transport: EthereumJSONRPC.HTTP,
transport_options: [
http: EthereumJSONRPC.HTTP.HTTPoison,
url: \"http://$CONSORTIUM_IP:$RPC_PORT\",
method_to_url: [
eth_getBalance: \"http://$CONSORTIUM_IP:$RPC_PORT\",
trace_block: \"http://$CONSORTIUM_IP:$RPC_PORT\",
trace_replayTransaction: \"http://$CONSORTIUM_IP:$RPC_PORT\"
],
http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: [pool: :ethereum_jsonrpc]]
],
variant: EthereumJSONRPC.Geth
],
subscribe_named_arguments: [
transport: EthereumJSONRPC.WebSocket,
transport_options: [
web_socket: EthereumJSONRPC.WebSocket.WebSocketClient,
url: \"ws://$WEBSOCKET_IP:$WEBSOCKET_PORT\"
]
]
" | sudo tee geth.exs
cd -
# Update Blockscout Web Configuration Files
cd apps/block_scout_web/config
echo "
use Mix.Config
config :block_scout_web, BlockScoutWeb.Endpoint,
force_ssl: false,
check_origin: false,
http: [port: 4000],
url: [
scheme: \"http\",
port: \"4000\",
host: \"*.azure.com\"
]" | sudo tee prod.exs
cd -
# Drop Old DB (If Exists) && Create + Migrate DB
sudo MIX_ENV=prod mix do ecto.drop --no-compile --force, ecto.create --no-compile, ecto.migrate --no-compile && echo "migrated DB"
# Install NPM Dependencies
cd apps/block_scout_web/assets && sudo npm install --unsafe-perm; cd -
cd apps/explorer && sudo npm install --unsafe-perm; cd -
# NPM Deploy
cd apps/block_scout_web/assets && sudo npm run-script deploy; cd -
# Create systemd Service File
cd ../../../etc/systemd/system
echo "
[Unit]
Description=Blockscout Web App
[Service]
Type=simple
User=$USER
Group=$USER
Restart=on-failure
Environment=MIX_ENV=prod
Environment=LANG=en_US.UTF-8
WorkingDirectory=/home/$USER/blockscout
export ETHEREUM_JSONRPC_VARIANT=geth
ExecStart=/usr/local/bin/mix phx.server
[Install]
WantedBy=multi-user.target
" | sudo tee blockscout.service
cd -
# Edit nginx Configuration File
cd ../../../etc/nginx
echo "
events {
worker_connections 1024;
}
http {
server {
listen 80;
server_name \"\";
location / {
proxy_pass http://localhost:4000;
proxy_http_version 1.1;
proxy_redirect off;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header Host \$host;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection \"upgrade\";
}
}
}
" | sudo tee nginx.conf
cd -
sudo service nginx reload
# Start systemd Service
sudo systemctl daemon-reload
sudo systemctl start blockscout.service