Skip to content

Commit ecaf243

Browse files
authored
Support duckdb (#22)
* support embedded ducdb with fixed version * aupport test different version of duckdb by modifying pom.xml * add customzied dockerfile to duckdb/ * add customized dckerfile * return to original dockerfile * modify config
1 parent 8f0bf9f commit ecaf243

File tree

7 files changed

+74
-10
lines changed

7 files changed

+74
-10
lines changed

build.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,29 @@
44
import logging
55
from 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+
2651
def 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
6388
def 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==============================")

config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"dbms_list": ["mysql", "postgres", "sqlite", "tidb", "cockroachdb"],
2+
"dbms_list": ["mysql", "postgres", "sqlite", "tidb", "cockroachdb", "duckdb"],
33
"dbms": "mysql",
44
"container_name": "mysql-custom",
55
"image": "mysql-custom",

duckdb/Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM ubuntu:20.04
2+
ENV DEBIAN_FRONTEND=noninteractive
3+
RUN apt-get update && \
4+
apt-get install -y openjdk-17-jdk maven git jq netcat mysql-client && \
5+
rm -rf /var/lib/apt/lists/*
6+
7+
WORKDIR /root/sqlancer
8+
9+
ARG DUCKDB_JDBC_VERSION=1.2.2.0
10+
11+
RUN git clone https://github.com/sqlancer/sqlancer.git . && \
12+
mvn -q versions:use-dep-version \
13+
-Dincludes=org.duckdb:duckdb_jdbc \
14+
-DdepVersion=${DUCKDB_JDBC_VERSION} \
15+
-DforceVersion=true && \
16+
mvn -q clean package -DskipTests
17+
18+
COPY entrypoint.sh /root/entrypoint.sh
19+
RUN chmod +x /root/entrypoint.sh
20+
CMD ["/root/entrypoint.sh"]

duckdb/__init__.py

Whitespace-only changes.

duckdb/config.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"embedded": "yes",
3+
"dbms": "duckdb",
4+
"username": "N/A",
5+
"password": "N/A",
6+
"container_name": "localhost",
7+
"oracle": "NoREC",
8+
"num_threads": 4,
9+
"timeout_seconds": 60
10+
}

sqlancer/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,3 @@ RUN chmod +x /root/entrypoint.sh
1616

1717
CMD ["/root/entrypoint.sh"]
1818

19-

sqlancer/entrypoint.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,22 @@ for i in {1..60}; do
1818
sleep 1
1919
done
2020

21-
CMD="java -jar sqlancer-*.jar --num-threads \"$SQLANCER_THREADS\" --timeout-seconds \"$SQLANCER_TIMEOUT\" --username \"$SQLANCER_USERNAME\" --password \"$SQLANCER_PASSWORD\" --host \"$SQLANCER_HOST\" \"$SQLANCER_DBMS\" --oracle \"$SQLANCER_ORACLE\""
2221

23-
# Show command to console + log file
22+
CMD="java -jar sqlancer-*.jar --num-threads \"$SQLANCER_THREADS\" --timeout-seconds \"$SQLANCER_TIMEOUT\" --host \"$SQLANCER_HOST\" \"$SQLANCER_DBMS\" --oracle \"$SQLANCER_ORACLE\""
23+
24+
25+
if [ "$(printf '%s' "${SQLANCER_USERNAME:-}" | tr '[:lower:]' '[:upper:]')" != "N/A" ]; then
26+
CMD="$CMD --username \"$SQLANCER_USERNAME\""
27+
fi
28+
29+
30+
if [ "$(printf '%s' "${SQLANCER_PASSWORD:-}" | tr '[:lower:]' '[:upper:]')" != "N/A" ]; then
31+
CMD="$CMD --password \"$SQLANCER_PASSWORD\""
32+
fi
33+
34+
2435
echo "Running: $CMD" | tee -a "$LOG_FILE"
2536

26-
# Run command: log everything, show only stats to console
2737
eval "$CMD" 2>&1 | tee -a "$LOG_FILE" | grep --line-buffered "Executed"
2838

2939
echo "[INFO] SQLancer finished. Logs saved to $LOG_DIR"

0 commit comments

Comments
 (0)