-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add github action for upgrade testing (#101)
- Loading branch information
1 parent
529971a
commit 980cfa5
Showing
14 changed files
with
306 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,3 +52,27 @@ jobs: | |
run: | | ||
./contrib/localnet/localnet_liveness.sh 100 3 30 localhost | ||
if: env.GIT_DIFF | ||
upgrade-test: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 15 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/[email protected] | ||
with: | ||
go-version: 1.18 | ||
- uses: technote-space/get-diff-action@v4 | ||
id: git_diff | ||
with: | ||
PATTERNS: | | ||
app/upgrades/**/*.go | ||
- name: echo diff | ||
run: echo '${{ env.GIT_DIFF }}' | ||
- name: start localnet | ||
run: | | ||
make clean localnet-start-upgrade | ||
if: env.GIT_DIFF | ||
- name: test upgrade | ||
run: | | ||
chmod +x -R ./contrib/updates | ||
./contrib/updates/upgrade-test.sh | ||
if: env.GIT_DIFF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
all: terrad-env | ||
all: terrad-env terrad-upgrade-env | ||
|
||
terrad-env: | ||
docker build --platform linux/amd64 --no-cache --build-arg UID=$(shell id -u) --build-arg GID=$(shell id -g) --tag classic-terra/terrad-env terrad-env | ||
|
||
.PHONY: all terrad-env | ||
terrad-upgrade-env: | ||
docker build --platform linux/amd64 --build-arg UID=$(shell id -u) --build-arg GID=$(shell id -g) --build-arg entrypoint=cosmovisor-entrypoint.sh --tag classic-terra/terrad-upgrade-env terrad-env | ||
|
||
.PHONY: all terrad-env terrad-upgrade-env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env sh | ||
|
||
BINARY=/terrad/${BINARY:-cosmovisor} | ||
ID=${ID:-0} | ||
LOG=${LOG:-terrad.log} | ||
|
||
if ! [ -f "${BINARY}" ]; then | ||
echo "The binary $(basename "${BINARY}") cannot be found. Please add the binary to the shared folder. Please use the BINARY environment variable if the name of the binary is not 'terrad'" | ||
exit 1 | ||
fi | ||
|
||
BINARY_CHECK="$(file "$BINARY" | grep 'ELF 64-bit LSB executable, x86-64')" | ||
|
||
if [ -z "${BINARY_CHECK}" ]; then | ||
echo "Binary needs to be OS linux, ARCH amd64" | ||
exit 1 | ||
fi | ||
|
||
export TERRADHOME="/terrad/node${ID}/terrad" | ||
|
||
if [ -d "$(dirname "${TERRADHOME}"/"${LOG}")" ]; then | ||
"${BINARY}" run "$@" --home "${TERRADHOME}" | tee "${TERRADHOME}/${LOG}" | ||
else | ||
"${BINARY}" run "$@" --home "${TERRADHOME}" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM golang:1.18-alpine3.17 | ||
|
||
RUN set -eux; apk add --no-cache ca-certificates build-base; | ||
|
||
# make cosmovisor statically linked | ||
RUN go install -ldflags '-w -s -linkmode=external -extldflags "-Wl,-z,muldefs -static"' -trimpath cosmossdk.io/tools/cosmovisor/cmd/cosmovisor@latest | ||
|
||
ENTRYPOINT [ "/bin/sh" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
all: build-cosmovisor-linux | ||
|
||
build-cosmovisor-linux: | ||
mkdir -p $(BUILDDIR) | ||
docker build --platform linux/amd64 --no-cache --tag classic-terra/terraclassic.cosmovisor-binary --file Dockerfile.cosmovisor . | ||
docker create --platform linux/amd64 --name temp classic-terra/terraclassic.cosmovisor-binary:latest | ||
docker cp temp:/go/bin/cosmovisor $(BUILDDIR)/ | ||
docker rm temp | ||
|
||
.PHONY: all build-cosmovisor-linux |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
version: '3' | ||
|
||
services: | ||
terradnode0: | ||
container_name: terradnode0 | ||
image: "classic-terra/terrad-upgrade-env" | ||
ports: | ||
- "9090:9090" | ||
- "26656-26657:26656-26657" | ||
environment: | ||
- ID=0 | ||
- LOG=$${LOG:-terrad.log} | ||
- DAEMON_HOME=/terrad/node0/terrad | ||
- DAEMON_NAME=terrad | ||
- DAEMON_RESTART_AFTER_UPGRADE=true | ||
volumes: | ||
- ../../build:/terrad:Z | ||
networks: | ||
localnet: | ||
ipv4_address: 192.168.10.2 | ||
|
||
terradnode1: | ||
container_name: terradnode1 | ||
image: "classic-terra/terrad-upgrade-env" | ||
ports: | ||
- "9091:9090" | ||
- "26659-26660:26656-26657" | ||
environment: | ||
- ID=1 | ||
- LOG=$${LOG:-terrad.log} | ||
- DAEMON_HOME=/terrad/node1/terrad | ||
- DAEMON_NAME=terrad | ||
- DAEMON_RESTART_AFTER_UPGRADE=true | ||
volumes: | ||
- ../../build:/terrad:Z | ||
networks: | ||
localnet: | ||
ipv4_address: 192.168.10.3 | ||
|
||
terradnode2: | ||
container_name: terradnode2 | ||
image: "classic-terra/terrad-upgrade-env" | ||
environment: | ||
- ID=2 | ||
- LOG=$${LOG:-terrad.log} | ||
- DAEMON_HOME=/terrad/node2/terrad | ||
- DAEMON_NAME=terrad | ||
- DAEMON_RESTART_AFTER_UPGRADE=true | ||
ports: | ||
- "9092:9090" | ||
- "26661-26662:26656-26657" | ||
volumes: | ||
- ../../build:/terrad:Z | ||
networks: | ||
localnet: | ||
ipv4_address: 192.168.10.4 | ||
|
||
terradnode3: | ||
container_name: terradnode3 | ||
image: "classic-terra/terrad-upgrade-env" | ||
environment: | ||
- ID=3 | ||
- LOG=$${LOG:-terrad.log} | ||
- DAEMON_HOME=/terrad/node3/terrad | ||
- DAEMON_NAME=terrad | ||
- DAEMON_RESTART_AFTER_UPGRADE=true | ||
ports: | ||
- "9093:9090" | ||
- "26663-26664:26656-26657" | ||
volumes: | ||
- ../../build:/terrad:Z | ||
networks: | ||
localnet: | ||
ipv4_address: 192.168.10.5 | ||
|
||
networks: | ||
localnet: | ||
driver: bridge | ||
ipam: | ||
driver: default | ||
config: | ||
- | ||
subnet: 192.168.10.0/16 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/bin/bash | ||
|
||
# this bash will prepare cosmosvisor to the build folder so that it can perform upgrade | ||
# this script is supposed to be run by Makefile | ||
|
||
# These fields should be fetched automatically in the future | ||
# Need to do more upgrade to see upgrade patterns | ||
OLD_VERSION=v1.0.5 | ||
SOFTWARE_UPGRADE_NAME=$(ls -td -- ./app/upgrades/* | head -n 1 | cut -d'/' -f4) | ||
BUILDDIR=$1 | ||
|
||
# check if BUILDDIR is set | ||
if [ -z "$BUILDDIR" ]; then | ||
echo "BUILDDIR is not set" | ||
exit 1 | ||
fi | ||
|
||
# install old version of terrad | ||
|
||
## check if _build/classic-${OLD_VERSION} exists | ||
if [ ! -d "_build/core-${OLD_VERSION:1}" ]; then | ||
mkdir _build | ||
wget -c "https://github.com/classic-terra/core/archive/refs/tags/${OLD_VERSION}.zip" -O _build/${OLD_VERSION}.zip | ||
unzip _build/${OLD_VERSION}.zip -d _build | ||
fi | ||
|
||
## check if $BUILDDIR/old/terrad exists | ||
if [ ! -f "$BUILDDIR/old/terrad" ]; then | ||
mkdir -p $BUILDDIR/old | ||
docker build --platform linux/amd64 --no-cache --build-arg source=./_build/core-${OLD_VERSION:1}/ --tag classic-terra/terraclassic.terrad-binary.old . | ||
docker create --platform linux/amd64 --name old-temp classic-terra/terraclassic.terrad-binary.old:latest | ||
docker cp old-temp:/usr/local/bin/terrad $BUILDDIR/old/ | ||
docker rm old-temp | ||
fi | ||
|
||
# prepare cosmovisor config in four nodes | ||
if [ ! -f "$BUILDDIR/node0/terrad/config/genesis.json" ]; then docker run --rm \ | ||
--user $(id -u):$(id -g) \ | ||
-v $BUILDDIR:/terrad:Z \ | ||
-v /etc/group:/etc/group:ro \ | ||
-v /etc/passwd:/etc/passwd:ro \ | ||
-v /etc/shadow:/etc/shadow:ro \ | ||
--entrypoint /terrad/old/terrad \ | ||
classic-terra/terrad-upgrade-env testnet --v 4 -o . --starting-ip-address 192.168.10.2 --keyring-backend=test --home /terrad; | ||
fi | ||
|
||
for i in {0..3}; do | ||
CURRENT=$BUILDDIR/node$i/terrad | ||
|
||
# change gov params voting_period | ||
jq '.app_state.gov.voting_params.voting_period = "50s"' $CURRENT/config/genesis.json > $CURRENT/config/genesis.json.tmp && mv $CURRENT/config/genesis.json.tmp $CURRENT/config/genesis.json | ||
|
||
docker run --rm \ | ||
--user $(id -u):$(id -g) \ | ||
-v $BUILDDIR:/terrad:Z \ | ||
-v /etc/group:/etc/group:ro \ | ||
-v /etc/passwd:/etc/passwd:ro \ | ||
-v /etc/shadow:/etc/shadow:ro \ | ||
-e DAEMON_HOME=/terrad/node$i/terrad \ | ||
-e DAEMON_NAME=terrad \ | ||
-e DAEMON_RESTART_AFTER_UPGRADE=true \ | ||
--entrypoint /terrad/cosmovisor \ | ||
classic-terra/terrad-upgrade-env init /terrad/old/terrad | ||
mkdir -p $CURRENT/cosmovisor/upgrades/$SOFTWARE_UPGRADE_NAME/bin | ||
cp $BUILDDIR/terrad $CURRENT/cosmovisor/upgrades/$SOFTWARE_UPGRADE_NAME/bin | ||
touch $CURRENT/cosmovisor/upgrades/$SOFTWARE_UPGRADE_NAME/upgrade-info.json | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/bin/bash | ||
|
||
# should make this auto fetch upgrade name from app upgrades once many upgrades have been done | ||
SOFTWARE_UPGRADE_NAME=$(ls -td -- ./app/upgrades/* | head -n 1 | cut -d'/' -f4) | ||
NODE1_HOME=node1/terrad | ||
BINARY_OLD="docker exec terradnode1 ./terrad" | ||
|
||
# sleep to wait for localnet to come up | ||
sleep 10 | ||
|
||
# 100 block from now | ||
STATUS_INFO=($($BINARY_OLD status --home $NODE1_HOME | jq -r '.NodeInfo.network,.SyncInfo.latest_block_height')) | ||
CHAIN_ID=${STATUS_INFO[0]} | ||
UPGRADE_HEIGHT=$((STATUS_INFO[1] + 20)) | ||
|
||
$BINARY_OLD tx gov submit-proposal software-upgrade "$SOFTWARE_UPGRADE_NAME" --upgrade-height $UPGRADE_HEIGHT --upgrade-info "temp" --title "upgrade" --description "upgrade" --from node1 --keyring-backend test --chain-id $CHAIN_ID --home $NODE1_HOME -y | ||
|
||
sleep 5 | ||
|
||
$BINARY_OLD tx gov deposit 1 "20000000uluna" --from node1 --keyring-backend test --chain-id $CHAIN_ID --home $NODE1_HOME -y | ||
|
||
sleep 5 | ||
|
||
# loop from 0 to 3 | ||
for i in {0..3}; do | ||
# check if docker for node i is running | ||
if [[ $(docker ps -a | grep terradnode$i | wc -l) -eq 1 ]]; then | ||
$BINARY_OLD tx gov vote 1 yes --from node$i --keyring-backend test --chain-id $CHAIN_ID --home "node$i/terrad" -y | ||
sleep 5 | ||
fi | ||
done | ||
|
||
# keep track of block_height | ||
while true; do | ||
BLOCK_HEIGHT=$($BINARY_OLD status --home $NODE1_HOME | jq '.SyncInfo.latest_block_height' -r) | ||
if [[ $BLOCK_HEIGHT -ge $UPGRADE_HEIGHT ]]; then | ||
# assuming running only 1 terrad | ||
echo "UPGRADE REACHED, CONTINUING NEW CHAIN" | ||
break | ||
else | ||
$BINARY_OLD q gov proposal 1 --output=json --home $NODE1_HOME | jq ".status" | ||
echo "BLOCK_HEIGHT = $BLOCK_HEIGHT" | ||
sleep 10 | ||
fi | ||
done | ||
|
||
sleep 10 | ||
|
||
# check all nodes are online after upgrade | ||
for i in {0..3}; do | ||
if [[ $(docker ps -a | grep terradnode$i | wc -l) -eq 1 ]]; then | ||
docker exec terradnode$i ./terrad status --home "node$i/terrad" | ||
if [[ "${PIPESTATUS[0]}" != "0" ]]; then | ||
echo "node$i is not online" | ||
exit 1 | ||
fi | ||
else | ||
echo "terradnode$i is not running" | ||
exit 1 | ||
fi | ||
done |
Oops, something went wrong.