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
35 changes: 30 additions & 5 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,29 @@
import logging
from utils import run_command

def build_sqlancer_image(script_log, docker_log, force_rebuild=False):
def build_sqlancer_image(script_log, docker_log, embedded, dbms, force_rebuild=False):
context_dir = "./sqlancer"
if embedded == "yes":
dockerfile_path = f"./{dbms}/Dockerfile"
script_log.info(f"Using embedded DBMS Dockerfile: {dockerfile_path}")
script_log.info("Embedded mode: rebuilding SQLancer image unconditionally ...")
run_command(
["docker", "build", "--no-cache", "-f", dockerfile_path, "-t", "sqlancer:latest", context_dir],
docker_log
)
script_log.info("SQLancer image built: sqlancer:latest")
return
else:
dockerfile_path = "./sqlancer/Dockerfile"
context_dir = "./sqlancer"
script_log.info(f"Using default SQLancer Dockerfile: {dockerfile_path}")

if force_rebuild:
script_log.info("Rebuilding SQLancer image: sqlancer:latest ...")
run_command(["docker", "build", "--no-cache", "-t", "sqlancer:latest", "./sqlancer"], docker_log)
run_command(
["docker", "build", "--no-cache", "-f", dockerfile_path, "-t", "sqlancer:latest", context_dir],
docker_log
)
script_log.info("SQLancer image built: sqlancer:latest")
return

Expand All @@ -19,10 +38,16 @@ def build_sqlancer_image(script_log, docker_log, force_rebuild=False):
if "sqlancer:latest" in images:
script_log.info("SQLancer image exists: sqlancer:latest")
else:
script_log.info("Building SQLancer image from cache: sqlancer:latest...")
run_command(["docker", "build", "-t", "sqlancer:latest", "./sqlancer"], docker_log)
script_log.info("Building SQLancer image from cache: sqlancer:latest ...")
run_command(
["docker", "build", "-f", dockerfile_path, "-t", "sqlancer:latest", context_dir],
docker_log
)
script_log.info("SQLancer image built: sqlancer:latest")




def build_network(script_log, docker_log, network_name="sqlancer-net"):
try:
output = subprocess.check_output([
Expand Down Expand Up @@ -61,7 +86,7 @@ def build_db_image(cfg, use_cache, script_log, docker_log, custom=False, dockerf
def build_environment(cfg, use_cache, script_log, docker_log, custom=False, dockerfile_path=""):
script_log.info("==============================Building environment==============================")
build_network(script_log, docker_log)
build_sqlancer_image(script_log, docker_log, force_rebuild=not use_cache)
build_sqlancer_image(script_log, docker_log, cfg["embedded"], cfg["dbms"], force_rebuild=False)
if cfg["embedded"] == "no":
build_db_image(cfg, use_cache, script_log, docker_log, custom, dockerfile_path)
script_log.info("==============================Building environment==============================")
Expand Down
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"dbms_list": ["mysql", "postgres", "sqlite", "tidb", "cockroachdb"],
"dbms_list": ["mysql", "postgres", "sqlite", "tidb", "cockroachdb", "duckdb"],
"dbms": "mysql",
"container_name": "mysql-custom",
"image": "mysql-custom",
Expand Down
20 changes: 20 additions & 0 deletions duckdb/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y openjdk-17-jdk maven git jq netcat mysql-client && \
rm -rf /var/lib/apt/lists/*

WORKDIR /root/sqlancer

ARG DUCKDB_JDBC_VERSION=1.2.2.0

RUN git clone https://github.com/sqlancer/sqlancer.git . && \
mvn -q versions:use-dep-version \
-Dincludes=org.duckdb:duckdb_jdbc \
-DdepVersion=${DUCKDB_JDBC_VERSION} \
-DforceVersion=true && \
mvn -q clean package -DskipTests

COPY entrypoint.sh /root/entrypoint.sh
RUN chmod +x /root/entrypoint.sh
CMD ["/root/entrypoint.sh"]
Empty file added duckdb/__init__.py
Empty file.
10 changes: 10 additions & 0 deletions duckdb/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"embedded": "yes",
"dbms": "duckdb",
"username": "N/A",
"password": "N/A",
"container_name": "localhost",
"oracle": "NoREC",
"num_threads": 4,
"timeout_seconds": 60
}
1 change: 0 additions & 1 deletion sqlancer/Dockerfile
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure if we should make the DuckDB components in the SQLancer Dockerfile. i.e., if we have more DBs, we might make this file very messy. Perhaps alternatively, we can have a 'fork' of the SQLancer Dockerfile in the duckdb folder?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

add customized dockerfile to duckdb/

Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ RUN chmod +x /root/entrypoint.sh

CMD ["/root/entrypoint.sh"]


16 changes: 13 additions & 3 deletions sqlancer/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,22 @@ for i in {1..60}; do
sleep 1
done

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\""

# Show command to console + log file
CMD="java -jar sqlancer-*.jar --num-threads \"$SQLANCER_THREADS\" --timeout-seconds \"$SQLANCER_TIMEOUT\" --host \"$SQLANCER_HOST\" \"$SQLANCER_DBMS\" --oracle \"$SQLANCER_ORACLE\""


if [ "$(printf '%s' "${SQLANCER_USERNAME:-}" | tr '[:lower:]' '[:upper:]')" != "N/A" ]; then
CMD="$CMD --username \"$SQLANCER_USERNAME\""
fi


if [ "$(printf '%s' "${SQLANCER_PASSWORD:-}" | tr '[:lower:]' '[:upper:]')" != "N/A" ]; then
CMD="$CMD --password \"$SQLANCER_PASSWORD\""
fi


echo "Running: $CMD" | tee -a "$LOG_FILE"

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

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