Skip to content

Commit

Permalink
fix: updated the download binaries script to use dynamic home directo…
Browse files Browse the repository at this point in the history
…ry instead of manually specifying it
  • Loading branch information
gzukel committed Mar 6, 2024
1 parent 22549db commit c916790
Showing 1 changed file with 1 addition and 41 deletions.
42 changes: 1 addition & 41 deletions contrib/docker-scripts/download_binaries.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import re
import requests
import os
import json
import logging
import sys
import shutil


# Logger class for easier logging setup
class Logger:
Expand All @@ -22,51 +19,14 @@ def __init__(self):
# Initialize logger instance
logger = Logger()

# Define the path where upgrades will be stored, using an environment variable for the base path
upgrade_path = f'{os.environ["DAEMON_HOME"]}/cosmovisor/upgrades/'


# Function to find the latest patch version of a binary based on major and optional minor version
def find_latest_patch_version(major_version, minor_version=None):
# Define a regex pattern to match version directories
pattern = re.compile(
f"v{major_version}\.{minor_version}\.(\d+)" if minor_version else f"v{major_version}\.0\.(\d+)")
# List directories that match the version pattern
versions = [folder for folder in os.listdir(upgrade_path) if pattern.match(folder)]
if versions:
try:
# Find the maximum version, assuming it's the latest patch
latest_patch_version = max(versions)
# Return the path to the binary of the latest patch version
return os.path.join(upgrade_path, latest_patch_version, "bin", "zetacored")
except ValueError as e:
logger.log.error(f"Error finding latest patch version: {e}")
return None
return None


# Function to replace an old binary with a new one
def replace_binary(source, target):
try:
# Log deletion of old binary
if os.path.exists(target):
logger.log.info(f"Deleted old binary: {target}")
os.remove(target)
# Copy the new binary to the target location
shutil.copy(source, target)
logger.log.info(f"Binary replaced: {target} -> {source}")
except Exception as e:
logger.log.error(f"Error replacing binary: {e}")


# Parse JSON from an environment variable to get binary download information
info = json.loads(os.environ["DOWNLOAD_BINARIES"])

try:
# Iterate over binaries to download
for binary in info["binaries"]:
download_link = binary["download_url"]
binary_location = binary["binary_location"]
binary_location = f'{os.environ["DAEMON_HOME"]}/{binary["binary_location"]}'
binary_directory = os.path.dirname(binary_location)
# Log download link
logger.log.info(f"DOWNLOAD LINK: {download_link}")
Expand Down

0 comments on commit c916790

Please sign in to comment.