-
Notifications
You must be signed in to change notification settings - Fork 0
208 lines (177 loc) · 10.3 KB
/
deployment.yml
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
# This workflows will build a docker container, publish it to Google Container Registry, and deploy it to GKE when a release is created
name: Build and Deploy Testnet
# Explicitly trigger this workflow from the web interface: https://github.com/ElrondNetwork/elrond-go/actions
on:
workflow_dispatch
# Alternatively, uncomment the configuration below to switch to different triggers
# Types of pull_request trigger: [assigned, unassigned, labeled, unlabeled, opened, edited, closed, reopened, synchronize, ready_for_review, locked, unlocked, review_requested, review_request_removed]
# on:
# pull_request:
# branches: [development]
# types: [opened, ready_for_review]
# push:
# branches:
# - my-branch
# Environment variables available to all jobs and steps in this workflows
env:
GKE_PROJECT: ${{ secrets.GKE_PROJECT }}
GITHUB_SHA: ${{ github.sha }}
GKE_REGION: europe-west4
GKE_CLUSTER: elrond-testnets-cluster
IMAGE_NODE: elrond-go-node
IMAGE_SEEDNODE: elrond-go-seednode
IMAGE_KEYGENERATOR: elrond-go-keygenerator
IMAGE_PROXY: elrond-go-proxy
IMAGE_TXGEN: elrond-go-txgen
REGISTRY_HOSTNAME: gcr.io
BASE_PATH: /home/runner/work/elrond-go/elrond-go
jobs:
setup-build-publish-deploy:
name: Setup, Build, Publish, and Deploy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
# https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#set-an-output-parameter-set-output
- name: Build decission
run: '(test -f .github/workflows/env && echo ::set-env name=build_env::true) || echo ENV testnet config does not exist'
# https://github.com/actions/checkout#Checkout-multiple-repos-side-by-side
# https://github.com/actions/checkout
- name: Checkout deployment config repo
uses: actions/checkout@v2
with:
repository: elrondnetwork/elrond-k8s-testnet
token: ${{ secrets.PAT }} # `GitHub_PAT` is a secret that contains your PAT
path: elrond-k8s-testnet
ref: master
- name: Checkout deployment config repo
uses: actions/checkout@v2
with:
repository: elrondnetwork/elrond-proxy-go
token: ${{ secrets.PAT }}
path: elrond-proxy-go
ref: master
- name: Checkout deployment config repo
uses: actions/checkout@v2
with:
repository: elrondnetwork/elrond-txgen-go
token: ${{ secrets.PAT }}
path: elrond-txgen-go
ref: master
# Setup gcloud CLI
- name: Setup gcloud CLI
uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
with:
version: '299.0.0'
service_account_email: ${{ secrets.GKE_EMAIL }}
service_account_key: ${{ secrets.GKE_KEY }}
- name: Prep Ubunut
run: |
sudo apt update
sudo apt install bc -y
- name: Create Configs
run: |
source .github/workflows/env
echo elrond-node-shard="$NUM_NODES_SHARD" observer-shard="$NUM_OF_SHARDS"
docker run \
-v "/home/runner/work/elrond-go/elrond-go/cmd/node/config/:/data/" \
elrondnetwork/elrond-go-filegen:latest \
-num-of-shards $NUM_OF_SHARDS \
-num-of-nodes-in-each-shard $NUM_NODES_SHARD \
-total-supply 20000000000000000000000000 \
-node-price 2500000000000000000000 \
-consensus-group-size $CONSENSUS_GROUP_SIZE \
-num-of-metachain-nodes $NUM_NODES_METACHAIN \
-metachain-consensus-group-size $METACHAIN_CONSENSUS_GROUP_SIZE \
-num-of-observers-in-each-shard 1 \
-num-of-observers-in-metachain 1 \
-chain-id ${{ github.sha }} \
-hysteresis $HYSTERESIS \
-stake-type delegated \
-output-directory ./
- name: Prepare Configs
run: |
source .github/workflows/env
echo scenarios=$SCENARIOS scenarios-config=$TXGEN_CONFIG_SCENARIOS
cp -r $BASE_PATH/cmd/node/config/ $BASE_PATH/filegenConfigLocal/
cp $BASE_PATH/elrond-k8s-testnet/filegenConfig/observerKey.pem $BASE_PATH/filegenConfigLocal/
sed 's/\"startTime\":.*/\"startTime\": '"$(date -d '5 minutes' +%s)",'/g' $BASE_PATH/filegenConfigLocal/nodesSetup.json > $BASE_PATH/filegenConfigLocal/nodesSetupUpdated.json
sed -i.bak 's/Port.*/Port = \"1000\"/' $BASE_PATH/filegenConfigLocal/p2p.toml
sed -i.bak 's/InitialPeerList.*/InitialPeerList = [\"\/dns4\/elrond-seednode\/tcp\/10000\/p2p\/16Uiu2HAkw5SNNtSvH1zJiQ6Gc3WoGNSxiyNueRKe6fuAuh57G3Bk\"]/' $BASE_PATH/filegenConfigLocal/p2p.toml
sed -i.bak 's/Address.*80\"/Address = \"http:\/\/observer-shard-zero:8080\"/' $BASE_PATH/elrond-proxy-go/cmd/proxy/config/config.toml
sed -i.bak 's/Address.*81\"/Address = \"http:\/\/observer-shard-one:8080\"/' $BASE_PATH/elrond-proxy-go/cmd/proxy/config/config.toml
sed -i.bak "/Scenarios =/c\ Scenarios = [${TXGEN_CONFIG_SCENARIOS}]" $BASE_PATH/elrond-txgen-go/cmd/txgen/config/config.toml
sed -i.bak 's/8080/8001/' $BASE_PATH/elrond-txgen-go/cmd/txgen/config/config.toml
shell: bash
# Configure docker to use the gcloud command-line tool as a credential helper
- run: |
# Set up docker to authenticate
gcloud auth configure-docker
# Build the Docker image
- name: Build
run: |
docker build -t "$REGISTRY_HOSTNAME"/"$GKE_PROJECT"/"$IMAGE_NODE":"$GITHUB_SHA" -f ./docker/elrond/Dockerfile .
docker build -t "$REGISTRY_HOSTNAME"/"$GKE_PROJECT"/"$IMAGE_SEEDNODE":"$GITHUB_SHA" -f ./docker/seednode/Dockerfile .
docker build -t "$REGISTRY_HOSTNAME"/"$GKE_PROJECT"/"$IMAGE_KEYGENERATOR":"$GITHUB_SHA" -f ./docker/keygenerator/Dockerfile .
cd elrond-proxy-go
docker build -t "$REGISTRY_HOSTNAME"/"$GKE_PROJECT"/"$IMAGE_PROXY":"$GITHUB_SHA" -f ./Docker/Dockerfile .
cd ../elrond-txgen-go
docker build -t "$REGISTRY_HOSTNAME"/"$GKE_PROJECT"/"$IMAGE_TXGEN":"$GITHUB_SHA" -f ./Docker/Dockerfile .
cd ..
# Push the Docker image to Google Container Registry
- name: Publish
run: |
docker push $REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE_NODE:$GITHUB_SHA
docker push $REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE_SEEDNODE:$GITHUB_SHA
docker push $REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE_KEYGENERATOR:$GITHUB_SHA
docker push $REGISTRY_HOSTNAME"/"$GKE_PROJECT"/"$IMAGE_PROXY":"$GITHUB_SHA
docker push $REGISTRY_HOSTNAME"/"$GKE_PROJECT"/"$IMAGE_TXGEN":"$GITHUB_SHA
# Deploy the Docker images to the GKE cluster
- name: Deploy
run: |
sudo apt update
sudo apt install bc -y
source .github/workflows/env
export HYSTERESISMUL=$(bc <<< "(1 + $HYSTERESIS)")
export NVS=$(bc <<< "($NUM_NODES_SHARD + $HYSTERESISMUL - 1) * $HYSTERESISMUL")
export NUM_VALIDATORS_ON_SHARD=$(bc <<< "($NVS+1)/1")
export NVM=$(bc <<< "($NUM_NODES_METACHAIN + $HYSTERESISMUL - 1) * $HYSTERESISMUL")
export NUM_VALIDATORS_ON_META=$(bc <<< "($NVM+1)/1")
export NUM_NODES_TOTAL=$(bc <<< "($NUM_VALIDATORS_ON_SHARD + $NUM_VALIDATORS_ON_META)")
echo elrond-node="$NUM_NODES_TOTAL" validators-shard="$NUM_VALIDATORS_ON_SHARD" observer-shard="$NUM_OF_SHARDS"
cd $BASE_PATH/elrond-k8s-testnet/kube/
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
chmod u+x ./kustomize
gcloud container clusters get-credentials "$GKE_CLUSTER" --region "$GKE_REGION" --project "$GKE_PROJECT"
#TODO: this should add node-pools for new deployment, we need to find logix to delete it with the deletion of a testnet
#gcloud container node-pools create ${{ github.sha }} --preemptible --cluster "$GKE_CLUSTER"
#kubernetes regex for namepsace evaluation '[a-z0-9]([-a-z0-9]*[a-z0-9])?'
export NAMESPACE=$( echo ${{ github.sha }}/erd/${{ github.ref }} | sed -e 's/[[:punct:]]/-/g' | awk '{print tolower(substr($0,0,63))}' )
kubectl create namespace "$NAMESPACE"
kubectl -n $NAMESPACE create configmap elrond-node-config \
--from-file=$BASE_PATH/filegenConfigLocal/validatorKey.pem \
--from-file=$BASE_PATH/filegenConfigLocal/observerKey.pem \
--from-file=$BASE_PATH/filegenConfigLocal/p2p.toml \
--from-file=$BASE_PATH/filegenConfigLocal/delegationWalletKey.pem \
--from-file=$BASE_PATH/filegenConfigLocal/genesis.json \
--from-file=$BASE_PATH/filegenConfigLocal/genesisSmartContracts.json \
--from-file=nodesSetup.json=$BASE_PATH/filegenConfigLocal/nodesSetupUpdated.json \
--from-file=$BASE_PATH/filegenConfigLocal/walletKey.pem \
--from-file=proxyConfig.toml=$BASE_PATH/elrond-proxy-go/cmd/proxy/config/config.toml \
--from-file=proxyEconomics.toml=$BASE_PATH/elrond-proxy-go/cmd/proxy/config/economics.toml \
--from-file=txgenConfig.toml=$BASE_PATH/elrond-txgen-go/cmd/txgen/config/config.toml \
--from-file=txgenEconomics.toml=$BASE_PATH/elrond-txgen-go/cmd/txgen/config/economics.toml
kubectl -n $NAMESPACE create configmap txgen-config \
--from-literal=num_shards_txgen="$NUM_OF_SHARDS" \
--from-literal=minting_value="$PROXY_MINTING_VALUE" \
--from-literal=num_accounts="$PROXY_NUM_ACCOUNTS" \
--from-literal=screnarios="${SCENARIOS}"
./kustomize edit set replicas elrond-node=$NUM_NODES_TOTAL observer-shard=$NUM_OF_SHARDS
./kustomize edit set image elrondnetwork/elrond-go-node=$REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE_NODE:$GITHUB_SHA
./kustomize edit set image elrondnetwork/elrond-go-seednode=$REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE_SEEDNODE:$GITHUB_SHA
./kustomize edit set image elrondnetwork/elrond-go-proxy=$REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE_PROXY:$GITHUB_SHA
./kustomize edit set image elrondnetwork/elrond-go-txgen=$REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE_TXGEN:$GITHUB_SHA
./kustomize edit set namespace "$NAMESPACE"
./kustomize build ./ | kubectl -n "$NAMESPACE" apply --validate=false -f -