Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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==============================")
Expand Down
3 changes: 2 additions & 1 deletion cockroachdb/config.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
2 changes: 2 additions & 0 deletions mysql/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
3 changes: 2 additions & 1 deletion postgres/config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"embedded": "no",
"dbms": "postgres",
"image": "postgres:13",
"image_name": "postgres",
"tag": "13",
"container_name": "postgres-sqlancer",
"port": 5432,
"env": {
Expand Down
21 changes: 20 additions & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", [])
Expand Down Expand Up @@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we'll need a CLI option/config to control whether we want to remove the image after each testing? Or perhaps we don't need this pruning.

script_log.info("==============================Executing test==============================")

def remove_container(container_name, script_log, docker_log):
Expand All @@ -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==============================")
Expand All @@ -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==============================")

3 changes: 2 additions & 1 deletion tidb/config.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down