forked from pieceofr/mango-simulation-dos
-
Notifications
You must be signed in to change notification settings - Fork 7
/
start-build-dependency.sh
executable file
·135 lines (125 loc) · 4.8 KB
/
start-build-dependency.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
#!/usr/bin/env bash
## start-build-dependency.sh
## arg 1: wheather to build solana-mango-simulator
## arg 2: ARTIFACT BUCKET
## arg 3: NAME OF ENV ARTIFACT FILE
## env
set -ex
## fiunctions
## s1: bucket name s2: file name s3: local directory
download_file() {
for retry in 0 1 2
do
gsutil cp "$1/$2" "$3"
if [[ ! -f "$2" ]];then
echo NO "$2" found, retry=$retry
else
echo "$2" dowloaded
break
fi
sleep 5
done
}
# s1: local file s2: bucket name
upload_file() {
gsutil cp "$1" "$2"
}
## Download key files from gsutil
if [[ "$1" != "true" && "$1" != "false" ]];then
build_binary="false"
else
build_binary="$1"
fi
[[ ! "$2" ]]&& echo "No artifact bucket" && exit 1
[[ ! "$3" ]]&& echo "No artifact filename" && exit 1
download_file "gs://$2" "$3" "$HOME"
sleep 5
[[ ! -f "env-artifact.sh" ]] && echo no "env-artifact.sh" downloaded && exit 2
# shellcheck source=/dev/null
source $HOME/.profile
# shellcheck source=env-artifact.sh
source $HOME/env-artifact.sh
# export Env for refund)users.ts
export ENDPOINT_URL=$ENDPOINT
## preventing lock-file build fail,
## also need to disable software upgrade in image
sudo fuser -vki -TERM /var/lib/dpkg/lock /var/lib/dpkg/lock-frontend || true
sudo dpkg --configure -a
sudo apt update
## pre-install and rust version
sudo apt-get install -y libssl-dev libudev-dev pkg-config zlib1g-dev llvm clang cmake make libprotobuf-dev protobuf-compiler
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list \
sudo apt-get update
sudo apt-get install nodejs -y
sudo npm install -g typescript
sudo npm install -g ts-node
sudo npm install -g yarn
# warning package-lock.json found.
# Your project contains lock files generated by tools other than Yarn.
# It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files.
# To clear this warning, remove package-lock.json.
# Memo by author: use yarn instead of npm install
rm -f package-lock.json || true
yarn install
rustup default stable
rustup update
echo ------- stage: git clone repos ------
cd $HOME
[[ -d "$GIT_REPO_DIR" ]]&& rm -rf $GIT_REPO_DIR
git clone "$GIT_REPO"
cd $GIT_REPO_DIR
git checkout "$BUILDKITE_BRANCH"
cd $HOME
[[ -d "$HOME/$MANGO_CONFIGURE_DIR" ]]&& rm -rf "$HOME/$MANGO_CONFIGURE_DIR"
git clone "$MANGO_CONFIGURE_REPO" # may remove later
[[ -d "$HOME/$MANGO_SIMULATION_DIR" ]]&& rm -rf "$HOME/$MANGO_SIMULATION_DIR"
git clone "$MANGO_SIMULATION_REPO" "$HOME/$MANGO_SIMULATION_DIR"
echo ------- stage: build or download mango-simulation ------
# clone mango_bencher and mkdir dep dir
cd "$HOME/$MANGO_SIMULATION_DIR"
if [[ "$build_binary" == "true" ]];then
git checkout "$MANGO_SIMULATION_BRANCH"
cargo build --release
cp "$HOME/$MANGO_SIMULATION_DIR/target/release/mango-simulation" $HOME
chmod +x $HOME/mango-simulation
upload_file $HOME/mango-simulation "gs://$ARTIFACT_BUCKET/$BUILDKITE_PIPELINE_ID/$BUILDKITE_BUILD_ID/$BUILDKITE_JOB_ID/$MANGO_SIMULATION_ARTIFACT_FILE"
else
# download from bucket
cd $HOME
download_file "gs://$ARTIFACT_BUCKET/$BUILDKITE_PIPELINE_ID/$BUILDKITE_BUILD_ID/$BUILDKITE_JOB_ID" "$MANGO_SIMULATION_ARTIFACT_FILE" "$HOME"
[[ ! -f "$HOME/mango-simulation" ]] && echo no mango-simulation downloaded && exit 1
chmod +x $HOME/mango-simulation
echo mango-simuation downloaded
fi
echo ---- stage: copy files to HOME and mkdir log folder ----
cp "$HOME/$GIT_REPO_DIR/start-dos-test.sh" /home/sol/start-dos-test.sh
cp "$HOME/$GIT_REPO_DIR/start-upload-logs.sh" /home/sol/start-upload-logs.sh
[[ -d "$HOME/$HOSTNAME" ]] && rm -rf "$HOME/$HOSTNAME"
mkdir -p "$HOME/$HOSTNAME"
echo ---- stage: download id, accounts and authority file in HOME ----
cd $HOME
download_file "gs://$MANGO_SIMULATION_PRIVATE_BUCKET" "$ID_FILE" "$HOME"
[[ ! -f "$ID_FILE" ]]&&echo no "$ID_FILE" file && exit 1
download_file "gs://$MANGO_SIMULATION_PRIVATE_BUCKET" "$AUTHORITY_FILE" "$HOME"
[[ ! -f "$AUTHORITY_FILE" ]]&&echo no "$AUTHORITY_FILE" file && exit 1
download_file "gs://$MANGO_SIMULATION_PRIVATE_BUCKET" "$VALIDATOR_ID_FILE" "$HOME"
[[ ! -f "$VALIDATOR_ID_FILE" ]]&&echo no "$VALIDATOR_ID_FILE" file && exit 1
download_accounts=( $ACCOUNTS )
for acct in "${download_accounts[@]}"
do
download_file "gs://$MANGO_SIMULATION_PRIVATE_BUCKET" "$acct" "$HOME"
[[ ! -f "$acct" ]]&& echo no "$acct" file && exit 1 || echo "$acct" downloaded
done
echo --- stage: Start refunding clients accounts
cd "$MANGO_CONFIGURE_DIR"
sudo yarn install
cp "$HOME/$AUTHORITY_FILE" .
for acct in "${download_accounts[@]}"
do
ts-node refund_users.ts "${HOME}/$acct" > out.log 2>1 || true
if [ "$?" -ne 0 ]; then
echo --- refund failed for $acct
fi
done
exit 0