diff --git a/build.py b/build.py index 3cd0d8e..dc73106 100644 --- a/build.py +++ b/build.py @@ -43,20 +43,22 @@ def build_network(script_log, docker_log, network_name="sqlancer-net"): sys.exit(1) def build_db_image(cfg, use_cache, script_log, docker_log, custom=False, dockerfile_path=""): + image = f"{cfg['image_name']}:{cfg['tag']}" + if not use_cache and not custom: - image = cfg["image"] script_log.info("Pulling db image: %s ...", image) run_command(["docker", "pull", image], docker_log) script_log.info("DB image pulled: %s", image) elif custom: - build_cmd = ["docker", "build", "-t", cfg["image"], os.path.dirname(dockerfile_path)] + build_cmd = ["docker", "build", "-t", image, os.path.dirname(dockerfile_path)] if not use_cache: build_cmd.insert(2, "--no-cache") - script_log.info("Building db image: %s ...", cfg["image"]) + script_log.info("Building db image: %s ...", image) run_command(build_cmd, docker_log) - script_log.info("DB image built: %s ...", cfg["image"]) + script_log.info("DB image built: %s ...", image) else: - script_log.info("DB image already exists: %s", cfg["image"]) + script_log.info("DB image already exists: %s", image) + def build_environment(cfg, use_cache, script_log, docker_log, custom=False, dockerfile_path=""): script_log.info("==============================Building environment==============================") diff --git a/cockroachdb/config.json b/cockroachdb/config.json index 3ed5fa5..c3dc21e 100644 --- a/cockroachdb/config.json +++ b/cockroachdb/config.json @@ -1,7 +1,8 @@ { "embedded": "no", "dbms": "cockroachdb", - "image": "cockroachdb/cockroach:v24.1.0", + "image_name": "cockroachdb/cockroach", + "tag": "v24.1.0", "container_name": "cockroachdb-sqlancer", "port": 26257, "startup_cmd": [ diff --git a/mysql/config.json b/mysql/config.json index c359263..37564fe 100644 --- a/mysql/config.json +++ b/mysql/config.json @@ -2,6 +2,8 @@ "embedded": "no", "dbms": "mysql", "image": "mysql:8.0", + "image_name": "mysql", + "tag": "8.0", "container_name": "mysql-sqlancer", "port": 3306, "env": { diff --git a/postgres/config.json b/postgres/config.json index 35cd0a7..969b23f 100644 --- a/postgres/config.json +++ b/postgres/config.json @@ -1,7 +1,8 @@ { "embedded": "no", "dbms": "postgres", - "image": "postgres:13", + "image_name": "postgres", + "tag": "13", "container_name": "postgres-sqlancer", "port": 5432, "env": { diff --git a/test.py b/test.py index 75407f5..e799595 100644 --- a/test.py +++ b/test.py @@ -15,7 +15,17 @@ def container_exists(name): return name in result.stdout.strip().splitlines() def start_db_container(dbms, cfg, script_log, docker_log): - image = cfg.get("image") + image_name = cfg.get("image_name") + tag = cfg.get("tag") + if not image_name: + script_log.error("Missing 'image_name' field in config.json") + sys.exit(1) + if not tag or str(tag).strip() == "": + script_log.error("Missing 'tag' field in config.json") + sys.exit(1) + else: + image = f"{image_name}:{tag}" + container_name = cfg.get("container_name", f"{dbms}-sqlancer") env_dict = cfg.get("env", {}) startup_cmd = cfg.get("startup_cmd", []) @@ -111,6 +121,7 @@ def test_single(cfg, script_log, docker_log, sqlancer_log, run_dir, use_cache=Fa if cfg["embedded"] == "no": remove_container(cfg["container_name"], script_log, docker_log) + remove_images(script_log, docker_log) script_log.info("==============================Executing test==============================") def remove_container(container_name, script_log, docker_log): @@ -121,6 +132,13 @@ def remove_container(container_name, script_log, docker_log): except subprocess.CalledProcessError as e: script_log.warning("Container removing failed: %s", container_name) +def remove_images(script_log, docker_log): + script_log.info("Removing outdated images...") + try: + run_command(["docker", "image", "prune", "-f"], docker_log) + script_log.info("Images removed") + except subprocess.CalledProcessError as e: + script_log.warning("Images removing failed") def test_custom_dockerfile(dockerfile_path, cfg, script_log, docker_log, sqlancer_log, run_dir, use_cache=False): script_log.info("==============================Executing test==============================") @@ -143,5 +161,6 @@ def test_custom_dockerfile(dockerfile_path, cfg, script_log, docker_log, sqlance ) remove_container(cfg["container_name"], script_log, docker_log) + remove_images(script_log, docker_log) script_log.info("==============================Executing test==============================") diff --git a/tidb/config.json b/tidb/config.json index 40c5b15..aaa34c7 100644 --- a/tidb/config.json +++ b/tidb/config.json @@ -1,7 +1,8 @@ { "embedded": "no", "dbms": "tidb", - "image": "pingcap/tidb:nightly", + "image_name": "pingcap/tidb", + "tag": "nightly", "container_name": "tidb-sqlancer", "port": 4000, "username": "root",