Skip to content

Commit 8f0bf9f

Browse files
authored
Separate image and tag (#21)
* separate image and tag parameters in config.json * update configs * remove outdated replaced images after testing
1 parent 411da5b commit 8f0bf9f

File tree

6 files changed

+35
-9
lines changed

6 files changed

+35
-9
lines changed

build.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,22 @@ def build_network(script_log, docker_log, network_name="sqlancer-net"):
4343
sys.exit(1)
4444

4545
def build_db_image(cfg, use_cache, script_log, docker_log, custom=False, dockerfile_path=""):
46+
image = f"{cfg['image_name']}:{cfg['tag']}"
47+
4648
if not use_cache and not custom:
47-
image = cfg["image"]
4849
script_log.info("Pulling db image: %s ...", image)
4950
run_command(["docker", "pull", image], docker_log)
5051
script_log.info("DB image pulled: %s", image)
5152
elif custom:
52-
build_cmd = ["docker", "build", "-t", cfg["image"], os.path.dirname(dockerfile_path)]
53+
build_cmd = ["docker", "build", "-t", image, os.path.dirname(dockerfile_path)]
5354
if not use_cache:
5455
build_cmd.insert(2, "--no-cache")
55-
script_log.info("Building db image: %s ...", cfg["image"])
56+
script_log.info("Building db image: %s ...", image)
5657
run_command(build_cmd, docker_log)
57-
script_log.info("DB image built: %s ...", cfg["image"])
58+
script_log.info("DB image built: %s ...", image)
5859
else:
59-
script_log.info("DB image already exists: %s", cfg["image"])
60+
script_log.info("DB image already exists: %s", image)
61+
6062

6163
def build_environment(cfg, use_cache, script_log, docker_log, custom=False, dockerfile_path=""):
6264
script_log.info("==============================Building environment==============================")

cockroachdb/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"embedded": "no",
33
"dbms": "cockroachdb",
4-
"image": "cockroachdb/cockroach:v24.1.0",
4+
"image_name": "cockroachdb/cockroach",
5+
"tag": "v24.1.0",
56
"container_name": "cockroachdb-sqlancer",
67
"port": 26257,
78
"startup_cmd": [

mysql/config.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"embedded": "no",
33
"dbms": "mysql",
44
"image": "mysql:8.0",
5+
"image_name": "mysql",
6+
"tag": "8.0",
57
"container_name": "mysql-sqlancer",
68
"port": 3306,
79
"env": {

postgres/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"embedded": "no",
33
"dbms": "postgres",
4-
"image": "postgres:13",
4+
"image_name": "postgres",
5+
"tag": "13",
56
"container_name": "postgres-sqlancer",
67
"port": 5432,
78
"env": {

test.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,17 @@ def container_exists(name):
1515
return name in result.stdout.strip().splitlines()
1616

1717
def start_db_container(dbms, cfg, script_log, docker_log):
18-
image = cfg.get("image")
18+
image_name = cfg.get("image_name")
19+
tag = cfg.get("tag")
20+
if not image_name:
21+
script_log.error("Missing 'image_name' field in config.json")
22+
sys.exit(1)
23+
if not tag or str(tag).strip() == "":
24+
script_log.error("Missing 'tag' field in config.json")
25+
sys.exit(1)
26+
else:
27+
image = f"{image_name}:{tag}"
28+
1929
container_name = cfg.get("container_name", f"{dbms}-sqlancer")
2030
env_dict = cfg.get("env", {})
2131
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
111121

112122
if cfg["embedded"] == "no":
113123
remove_container(cfg["container_name"], script_log, docker_log)
124+
remove_images(script_log, docker_log)
114125
script_log.info("==============================Executing test==============================")
115126

116127
def remove_container(container_name, script_log, docker_log):
@@ -121,6 +132,13 @@ def remove_container(container_name, script_log, docker_log):
121132
except subprocess.CalledProcessError as e:
122133
script_log.warning("Container removing failed: %s", container_name)
123134

135+
def remove_images(script_log, docker_log):
136+
script_log.info("Removing outdated images...")
137+
try:
138+
run_command(["docker", "image", "prune", "-f"], docker_log)
139+
script_log.info("Images removed")
140+
except subprocess.CalledProcessError as e:
141+
script_log.warning("Images removing failed")
124142

125143
def test_custom_dockerfile(dockerfile_path, cfg, script_log, docker_log, sqlancer_log, run_dir, use_cache=False):
126144
script_log.info("==============================Executing test==============================")
@@ -143,5 +161,6 @@ def test_custom_dockerfile(dockerfile_path, cfg, script_log, docker_log, sqlance
143161
)
144162

145163
remove_container(cfg["container_name"], script_log, docker_log)
164+
remove_images(script_log, docker_log)
146165
script_log.info("==============================Executing test==============================")
147166

tidb/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"embedded": "no",
33
"dbms": "tidb",
4-
"image": "pingcap/tidb:nightly",
4+
"image_name": "pingcap/tidb",
5+
"tag": "nightly",
56
"container_name": "tidb-sqlancer",
67
"port": 4000,
78
"username": "root",

0 commit comments

Comments
 (0)