From 20cdf17c3235902c05455e9c2b45949f95b1a9d8 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Norswap\" Laurent" Date: Fri, 8 Dec 2023 01:47:03 +0100 Subject: [PATCH] check Docker --- README.md | 1 + block_explorer.py | 1 + deps.py | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/README.md b/README.md index 6ba135d..7097cb8 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ The following dependencies will be checked by `roll.py`: - Some common command line utilities: `make`, `curl`, `tar`, `awk` and `grep`. - Git +- Docker (if you wish to run the Blockscout block explorer) `roll.py` will check the following dependencies and install them for you if needed (the script will always for your permission before installing anything outside the current directory): diff --git a/block_explorer.py b/block_explorer.py index 7889b42..487c8ca 100644 --- a/block_explorer.py +++ b/block_explorer.py @@ -32,6 +32,7 @@ def launch_blockscout(config: Config): """ Launch the blockscout block explorer, setting up the repo if necessary. """ + deps.check_docker() setup_blockscout_repo() log_file_name = "logs/launch_blockscout.log" diff --git a/deps.py b/deps.py index 6f2f96c..d9f7216 100644 --- a/deps.py +++ b/deps.py @@ -483,4 +483,36 @@ def install_geth(): print(f"Successfully installed geth {INSTALL_GETH_VERSION} as ./bin/geth") + +#################################################################################################### + +MIN_DOCKER_VERSION = "24" +""" +Minimum supported Docker version. This is somewhat arbitrary, simply the latest major version, +that we also tested with. +""" + + +def check_docker(): + if shutil.which("docker") is None: + raise Exception( + "Docker is not installed. Please install either Docker Engine or Docker Desktop\n" + "by following the instructions at https://docs.docker.com/engine/install/.") + + version_blob = lib.run("get docker version", "docker --version") + match = re.search(r"(\d+\.\d+\.\d+)", version_blob) + if match is None: + raise Exception("Failed to parse the Docker version, " + f"try updating Docker engine to v{MIN_DOCKER_VERSION} or higher.") + elif match.group(1) < MIN_DOCKER_VERSION: + raise Exception(f"Please update docker to {MIN_DOCKER_VERSION} or higher. " + "Refer to https://docs.docker.com/engine/install/") + + try: + lib.run("try running docker compose", "docker compose version") + except Exception: + raise Exception("Docker Compose not available, please install the Compose plugin. " + "Refer to https://docs.docker.com/compose/install/") + + ####################################################################################################