44import logging
55from utils import run_command
66
7- def build_sqlancer_image (script_log , docker_log , force_rebuild = False ):
7+ def build_sqlancer_image (script_log , docker_log , embedded , dbms , force_rebuild = False ):
8+ context_dir = "./sqlancer"
9+ if embedded == "yes" :
10+ dockerfile_path = f"./{ dbms } /Dockerfile"
11+ script_log .info (f"Using embedded DBMS Dockerfile: { dockerfile_path } " )
12+ script_log .info ("Embedded mode: rebuilding SQLancer image unconditionally ..." )
13+ run_command (
14+ ["docker" , "build" , "--no-cache" , "-f" , dockerfile_path , "-t" , "sqlancer:latest" , context_dir ],
15+ docker_log
16+ )
17+ script_log .info ("SQLancer image built: sqlancer:latest" )
18+ return
19+ else :
20+ dockerfile_path = "./sqlancer/Dockerfile"
21+ context_dir = "./sqlancer"
22+ script_log .info (f"Using default SQLancer Dockerfile: { dockerfile_path } " )
23+
824 if force_rebuild :
925 script_log .info ("Rebuilding SQLancer image: sqlancer:latest ..." )
10- run_command (["docker" , "build" , "--no-cache" , "-t" , "sqlancer:latest" , "./sqlancer" ], docker_log )
26+ run_command (
27+ ["docker" , "build" , "--no-cache" , "-f" , dockerfile_path , "-t" , "sqlancer:latest" , context_dir ],
28+ docker_log
29+ )
1130 script_log .info ("SQLancer image built: sqlancer:latest" )
1231 return
1332
@@ -19,10 +38,16 @@ def build_sqlancer_image(script_log, docker_log, force_rebuild=False):
1938 if "sqlancer:latest" in images :
2039 script_log .info ("SQLancer image exists: sqlancer:latest" )
2140 else :
22- script_log .info ("Building SQLancer image from cache: sqlancer:latest..." )
23- run_command (["docker" , "build" , "-t" , "sqlancer:latest" , "./sqlancer" ], docker_log )
41+ script_log .info ("Building SQLancer image from cache: sqlancer:latest ..." )
42+ run_command (
43+ ["docker" , "build" , "-f" , dockerfile_path , "-t" , "sqlancer:latest" , context_dir ],
44+ docker_log
45+ )
2446 script_log .info ("SQLancer image built: sqlancer:latest" )
2547
48+
49+
50+
2651def build_network (script_log , docker_log , network_name = "sqlancer-net" ):
2752 try :
2853 output = subprocess .check_output ([
@@ -63,7 +88,7 @@ def build_db_image(cfg, use_cache, script_log, docker_log, custom=False, dockerf
6388def build_environment (cfg , use_cache , script_log , docker_log , custom = False , dockerfile_path = "" ):
6489 script_log .info ("==============================Building environment==============================" )
6590 build_network (script_log , docker_log )
66- build_sqlancer_image (script_log , docker_log , force_rebuild = not use_cache )
91+ build_sqlancer_image (script_log , docker_log , cfg [ "embedded" ], cfg [ "dbms" ], force_rebuild = False )
6792 if cfg ["embedded" ] == "no" :
6893 build_db_image (cfg , use_cache , script_log , docker_log , custom , dockerfile_path )
6994 script_log .info ("==============================Building environment==============================" )
0 commit comments