Skip to content

Commit

Permalink
fix: updated makefile, and auto-update script
Browse files Browse the repository at this point in the history
  • Loading branch information
codebender37 committed Oct 18, 2024
1 parent 11b36c6 commit 0d20bd4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 30 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ btcli:
docker compose -f docker-compose.shared.yaml run --rm btcli

validator-pull:
docker compose --env-file .env.validator -f docker-compose.validator.yaml pull
docker compose --env-file .env.validator -f docker-compose.validator.yaml pull --include-deps

miner-pull:
docker compose --env-file .env.miner -f docker-compose.miner.yaml pull
docker compose --env-file .env.miner -f docker-compose.miner.yaml pull --include-deps

# ---------------------------------------------------------------------------- #
# CORE SERVICES #
Expand Down
76 changes: 48 additions & 28 deletions auto_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,38 @@

CONFIG = {
"validator": {
"services": [
"redis-service",
"synthetic-api",
"node-subtensor-testnet",
"validator-testnet",
],
# "services": [
# "redis-service",
# "synthetic-api",
# "postgres-vali",
# "prisma-setup-vali",
# "validator",
# ],
"images": ["dojo-synthetic-api"],
"docker_compose_down": "docker compose --env-file .env.validator -f docker-compose.validator.yaml down",
"docker_compose_up": "docker compose --env-file .env.validator -f docker-compose.validator.yaml up --build -d validator",
},
"miner-decentralised": {
# "services": [
# "redis-miner",
# "postgres-miner",
# "sidecar",
# "prisma-setup-miner",
# "worker-api",
# "worker-ui",
# "miner-decentralised",
# ],
"images": ["dojo-worker-api", "dojo-ui"],
"docker_compose_down": "docker compose --env-file .env.miner -f docker-compose.miner.yaml down",
"docker_compose_up": "docker compose --env-file .env.miner -f docker-compose.miner.yaml up --build -d miner-decentralised",
},
"miner": {
"miner-centralised": {
"services": [
"redis-service",
"postgres-service",
"prisma-setup",
"node-subtensor-testnet",
"sidecar",
"worker-api",
"worker-ui",
"miner-testnet",
"miner-centralised",
],
"images": ["dojo-worker-api", "dojo-ui"],
"images": [],
"docker_compose_down": "docker compose --env-file .env.miner -f docker-compose.miner.yaml down",
"docker_compose_up": "docker compose --env-file .env.miner -f docker-compose.miner.yaml up --build -d miner-centralised",
},
}

Expand Down Expand Up @@ -141,6 +153,19 @@ def pull_docker_images(list_of_images: list[str]):


def check_for_image_updates(images):
"""
Check for updates for a list of Docker images.
This function iterates over a list of image names, constructs the full image URL,
and checks if there is an update available for each image by comparing the local
and remote image digests. If any image has an update, pull the images quietly, and returns True.
Args:
images (list[str]): A list of Docker image names to check for updates.
Returns:
bool: True if any of the images have updates available, False otherwise.
"""
logger.info(f"Checking images: {images}")
has_update = False
for image_name in images:
Expand Down Expand Up @@ -178,23 +203,18 @@ def pop_stash():


def restart_docker(service_name):
logger.info(f"Restarting Docker services for: {service_name}.")
# Get the service data e.g. miner or validator
service_data = CONFIG.get(service_name, {})
services_to_restart = service_data.get("services", [])
main_service = "miner-testnet" if service_name == "miner" else "validator-testnet"

if not services_to_restart:
logger.error(f"No services found for {service_name}.")
return

logger.info(f"Restarting Docker services for: {service_name}.")
docker_compose_down: list[str] = service_data.get("docker_compose_down", "").split()
docker_compose_up: list[str] = service_data.get("docker_compose_up", "").split()

# Stop the services in a single command
# TODO change based on miner/validator services
subprocess.run(["docker", "compose", "stop"] + services_to_restart, check=True)
subprocess.run(docker_compose_down, check=True)

# Start the services in a single command
# TODO change based on miner/validator services
subprocess.run(["docker", "compose", "up", "-d", main_service], check=True)
subprocess.run(docker_compose_up, check=True)


def get_current_version():
Expand Down Expand Up @@ -246,7 +266,7 @@ def main(service_name):
parser = argparse.ArgumentParser(description="Run the auto-update script.")
parser.add_argument(
"service",
choices=["miner", "validator"],
choices=["miner-decentralised", "miner-centralised", "validator"],
help="Specify the service to run (miner or validator).",
)
args = parser.parse_args()
Expand Down

0 comments on commit 0d20bd4

Please sign in to comment.