Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic version override functionality #11

Merged
merged 2 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,14 @@ jobs:
timeout-minutes: 45
steps:
- name: Start container
run: docker run -d --name zetacored -p 8545:8545 -e MONIKER=$(uuidgen) -e ZETACHAIN_NETWORK=testnet ${{ needs.build.outputs.IMAGE }}
run: |
docker run -d \
--name zetacored \
-p 8545:8545 \
-e MONIKER=$(uuidgen) \
-e ZETACHAIN_NETWORK=testnet \
-e VERSION_OVERRIDE_v27=https://github.com/zeta-chain/node/releases/download/v27.0.4/zetacored-linux-amd64 \
${{ needs.build.outputs.IMAGE }}
- name: Wait for healthy
run: |
while ! curl -s -f --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":67}' -H 'Content-Type: application/json' http://localhost:8545; do
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN apt update && \

COPY --from=base-build /go/bin/cosmovisor /go/bin/go-getter /go/bin/dl-pipe /usr/local/bin

COPY run.sh init.sh /
COPY run.sh init.sh apply_version_overrides.sh /

ENTRYPOINT ["/run.sh"]

Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,14 @@ zetacored-docker is a simple way to run snapshot based `zetacored` in docker. It

The only environment variable you must set is `MONIKER`. See `run.sh` for the other variables you may set.

A persistent volume should be mounted on `/root`.
A persistent volume should be mounted on `/root`.

## Version Overrides

You may override a specific version by setting `VERSION_OVERRIDE_${version}=URL` variable. This is mostly useful for deploying minor non-consensus breaking patches. Example:

```
VERSION_OVERRIDE_v27=https://github.com/zeta-chain/node/releases/download/v27.0.4/zetacored-linux-amd64
```

The old version will be ran if the download of this file changes.
31 changes: 31 additions & 0 deletions apply_version_overrides.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

set -eo pipefail

if [[ -n $DEBUG ]]; then
set -x
fi

upgrades_path="${HOME}/.zetacored/cosmovisor/upgrades/"

for version_dir in "$upgrades_path"/*/; do
if [ ! -d "$version_dir" ]; then
continue
fi
# Extract version name from path
version=$(basename "$version_dir")
# Check for override variable
override_var="VERSION_OVERRIDE_${version}"
if [ -n "${!override_var}" ]; then
echo "Found override for version $version: ${!override_var}"
# Download binary using go-getter
if go-getter --mode file "${!override_var}" /tmp/zetacored; then
# If download successful, move to correct location
chmod +x /tmp/zetacored
mv /tmp/zetacored "${version_dir}/bin/zetacored"
echo "Successfully updated binary for version $version"
else
echo "Failed to download binary for version $version, using existing version"
fi
fi
done
19 changes: 10 additions & 9 deletions init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,6 @@ download_configs() {
install_genesis_zetacored() {
echo "Installing genesis zetacored"

# create the genesis bin path and symlink it to the current path
genesis_path=".zetacored/cosmovisor/genesis"
mkdir -p "$genesis_path"
mkdir -p "${genesis_path}/bin"
current_path=".zetacored/cosmovisor/current"
ln -s "${HOME}/${genesis_path}" "${HOME}/${current_path}"

if [[ -z $ZETACORED_BINARY_URL ]]; then
max_height=$($CURL "${ZETACHAIN_SNAPSHOT_METADATA_URL}" | jq -r '.snapshots[0].height')
echo "Getting latest passed upgrade plan before ${max_height}"
Expand All @@ -87,8 +80,16 @@ install_genesis_zetacored() {
ZETACORED_BINARY_URL=$(jq -r '.plan.info' /tmp/init-upgrade-plan.json | jq -r ".binaries[\"linux/$GOARCH\"]")
fi
# go-getter will verify the checksum of the downloaded binary
go-getter --mode file "$ZETACORED_BINARY_URL" .zetacored/cosmovisor/genesis/bin/zetacored
chmod +x .zetacored/cosmovisor/genesis/bin/zetacored
go-getter --mode file "$ZETACORED_BINARY_URL" /tmp/zetacored
chmod +x /tmp/zetacored

upgrades_path=.zetacored/cosmovisor/upgrades/$(/tmp/zetacored upgrade-handler-version)
upgrades_bin_path="${upgrades_path}/bin/"
mkdir -p $upgrades_bin_path
mv /tmp/zetacored $upgrades_bin_path

ln -sf "${HOME}/$upgrades_path" "${HOME}/.zetacored/cosmovisor/genesis"
ln -sf "${HOME}/$upgrades_path" "${HOME}/.zetacored/cosmovisor/current"

# run the zetacored version to ensure it's the correct architecture, glibc version, and is in PATH
zetacored version
Expand Down
4 changes: 4 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@ export DAEMON_NAME="zetacored"
export DAEMON_HOME="$HOME/.zetacored"
export UNSAFE_SKIP_BACKUP=true

# apply any version overrides
# these should run on every start the version can change at any time
/apply_version_overrides.sh

# shellcheck disable=SC2068
exec cosmovisor run start --moniker "$MONIKER" $@