Skip to content

Commit

Permalink
updated binary download script
Browse files Browse the repository at this point in the history
  • Loading branch information
gzukel committed Mar 1, 2024
1 parent 108da5e commit 1f94b35
Showing 1 changed file with 14 additions and 36 deletions.
50 changes: 14 additions & 36 deletions contrib/docker-scripts/download_binaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,61 +65,39 @@ def replace_binary(source, target):
try:
# Iterate over binaries to download
for binary in info["binaries"]:
download_link = binary
download_link = binary["download_url"]
binary_location = binary["binary_location"]
binary_directory = os.path.dirname(binary_location)
# Log download link
logger.log.info(f"DOWNLOAD LINK: {download_link}")
split_download_link = download_link.split("/")
# Log split download link parts
logger.log.info(f"SPLIT DOWNLOAD LINK: {split_download_link}")
# Extract binary name and version from the download link
binary_name = download_link.split("/")[8]
version = download_link.split("/")[7]
formatted_version = re.search(r'v\d{1,2}\.\d{1,2}\.\d{1,2}', version).group()
end_binary_name = os.environ["DAEMON_NAME"]
# Define the directory path where the binary will be stored
directory_path = f"{os.environ['DAEMON_HOME']}/{os.environ['VISOR_NAME']}/upgrades/{formatted_version}/bin"
# Check if binary already exists
logger.log.info(f"CHECKING / DOWNLOADING {directory_path}/{end_binary_name}")
logger.log.info(f"CHECKING / DOWNLOADING {binary_location}")

if os.path.exists(f"{directory_path}/{end_binary_name}"):
if os.path.exists(binary_location):
# If binary exists, log and do nothing
logger.log.info(f"BINARY EXISTS ALREADY: {directory_path}/{end_binary_name}")
logger.log.info(f"BINARY EXISTS ALREADY: {binary_location}")
else:
# If binary doesn't exist, download and save it
logger.log.info("BINARY DOES NOT EXIST.")
os.makedirs(directory_path, exist_ok=True)
os.makedirs(binary_directory, exist_ok=True)
response = requests.get(download_link)
if response.status_code == 200:
with open(f"{directory_path}/{end_binary_name}", "wb") as f:
with open(binary_location, "wb") as f:
f.write(response.content)
os.chmod(f"{directory_path}/{end_binary_name}", 0o755)
os.chmod(binary_location, 0o755)
logger.log.info("BINARY DOWNLOADED SUCCESSFULLY.")
else:
logger.log.info("FAILED TO DOWNLOAD BINARY. Status code:", response.status_code)

logger.log.info("Validate binary exists in folder.")
files_and_directories = os.listdir(binary_directory)
logger.log.info("Files and directories in '", binary_directory, "':")
for name in files_and_directories:
logger.log.info(name)
logger.log.info("BINARIES DOWNLOAD FINISHED...")

# Start the process of upgrading binaries to the latest patch version
# versions = set()
# logger.log.info("UPGRADING BINARIES WITH LATEST PATCH VERSION UPGRADE")
# # Collect versions of all binaries
# for folder in os.listdir(upgrade_path):
# match = re.match(r'v(\d+)\.(\d+)\.(\d+)', folder)
# if match:
# versions.add(match.groups())
#
# # For each version, find and replace with the latest patch version if applicable
# for major_version, minor_version, patch_version in versions:
# logger.log.info(f"BINARY VERSION: v{major_version}.{minor_version}.{patch_version}")
# latest_patch_version_path = find_latest_patch_version(major_version, minor_version)
# if latest_patch_version_path:
# logger.log.info(f"LATEST PATCH VERSION: {latest_patch_version_path}")
# symlink_path = os.path.join(upgrade_path, f"v{major_version}.{minor_version}.{patch_version}", "bin",
# "zetacored")
# logger.log.info(f"UPDATING BINARY: {symlink_path} TO: {latest_patch_version_path}")
# replace_binary(latest_patch_version_path, symlink_path)
# else:
# logger.log.info(f"NO PATCH UPDATE FOR v{major_version}.{minor_version}")

except Exception as e:
logger.log.error(str(e))

0 comments on commit 1f94b35

Please sign in to comment.