diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 68d6ed5..e34c7dd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/Dockerfile b/Dockerfile index 12cf15a..b8b80d8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/README.md b/README.md index 6d6359a..d9d215d 100644 --- a/README.md +++ b/README.md @@ -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`. \ No newline at end of file +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. \ No newline at end of file diff --git a/apply_version_overrides.sh b/apply_version_overrides.sh new file mode 100755 index 0000000..b81ac08 --- /dev/null +++ b/apply_version_overrides.sh @@ -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 \ No newline at end of file diff --git a/init.sh b/init.sh index b5761bf..ccc1cb9 100755 --- a/init.sh +++ b/init.sh @@ -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}" @@ -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 diff --git a/run.sh b/run.sh index 46e3a3d..e25f567 100755 --- a/run.sh +++ b/run.sh @@ -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" $@ \ No newline at end of file