From b0ea941bee32f0b870b2d7099f32170e2df0f64c Mon Sep 17 00:00:00 2001 From: CelestaLiu Date: Fri, 1 Aug 2025 02:17:35 +0000 Subject: [PATCH] support dockerfiles that build postgres from source code --- build.py | 2 +- postgres/Dockerfile | 39 +++++++++++++++++++++++++++++++++++++++ postgres/entrypoint.sh | 22 ++++++++++++++++++++++ start.py | 2 +- 4 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 postgres/Dockerfile create mode 100644 postgres/entrypoint.sh diff --git a/build.py b/build.py index c7b2b29..3cd0d8e 100644 --- a/build.py +++ b/build.py @@ -54,7 +54,7 @@ def build_db_image(cfg, use_cache, script_log, docker_log, custom=False, dockerf build_cmd.insert(2, "--no-cache") script_log.info("Building db image: %s ...", cfg["image"]) run_command(build_cmd, docker_log) - script_log.info("DB image pulled: %s ...", cfg["image"]) + script_log.info("DB image built: %s ...", cfg["image"]) else: script_log.info("DB image already exists: %s", cfg["image"]) diff --git a/postgres/Dockerfile b/postgres/Dockerfile new file mode 100644 index 0000000..c1fac49 --- /dev/null +++ b/postgres/Dockerfile @@ -0,0 +1,39 @@ +FROM ubuntu:22.04 + +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y \ + git build-essential libreadline-dev zlib1g-dev flex bison \ + libxml2-dev libxslt1-dev libssl-dev libicu-dev pkg-config \ + wget ca-certificates lsb-release pwgen && \ + apt-get clean + +ENV PG_VERSION=17 \ + PG_USER=postgres \ + PG_BASE=/usr/local/pgsql \ + PG_DATADIR=/var/lib/postgresql/data + +# Clone & build PostgreSQL from source +RUN git clone --depth 1 --branch REL_${PG_VERSION}_STABLE https://github.com/postgres/postgres.git /tmp/postgres && \ + cd /tmp/postgres && \ + ./configure --prefix=${PG_BASE} && \ + make -j"$(nproc)" && \ + make install && \ + rm -rf /tmp/postgres + +# Create user and directories +RUN useradd -r -s /bin/bash ${PG_USER} && \ + mkdir -p ${PG_DATADIR} /var/run/postgresql && \ + chown -R ${PG_USER}:${PG_USER} ${PG_DATADIR} /var/run/postgresql ${PG_BASE} + +# Copy entrypoint +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh + +# Update PATH +ENV PATH=${PG_BASE}/bin:$PATH + +# Expose PostgreSQL port +EXPOSE 5432 + +# Run PostgreSQL with init and config +ENTRYPOINT ["/entrypoint.sh"] diff --git a/postgres/entrypoint.sh b/postgres/entrypoint.sh new file mode 100644 index 0000000..202f2aa --- /dev/null +++ b/postgres/entrypoint.sh @@ -0,0 +1,22 @@ +#!/bin/bash +set -e + +echo ">> Initializing database at ${PG_DATADIR}" +if [ ! -s "${PG_DATADIR}/PG_VERSION" ]; then + su -s /bin/bash -c "${PG_BASE}/bin/initdb -D ${PG_DATADIR}" ${PG_USER} + + echo ">> Configuring postgresql.conf and pg_hba.conf" + + echo "listen_addresses='*'" >> ${PG_DATADIR}/postgresql.conf + echo "host all all 0.0.0.0/0 md5" >> ${PG_DATADIR}/pg_hba.conf + + # Start DB temporarily to run SQL setup + su -s /bin/bash -c "${PG_BASE}/bin/pg_ctl -D ${PG_DATADIR} -w start" ${PG_USER} + + echo "ALTER USER ${PG_USER} WITH PASSWORD '12345678';" | su -s /bin/bash -c "${PG_BASE}/bin/psql" ${PG_USER} + + su -s /bin/bash -c "${PG_BASE}/bin/pg_ctl -D ${PG_DATADIR} -m fast stop" ${PG_USER} +fi + +echo ">> Starting PostgreSQL..." +exec su -s /bin/bash -c "${PG_BASE}/bin/postgres -D ${PG_DATADIR}" ${PG_USER} diff --git a/start.py b/start.py index 139a536..4f51b1f 100644 --- a/start.py +++ b/start.py @@ -43,7 +43,7 @@ def main(): parser.error("Custom DBMS test requires --config") cfg = load_json(args.config) build_environment(cfg, use_cache, script_log, docker_log, True, args.dockerfile) - test_custom_dockerfile(args.dockerfile, cfg, script_log, docker_log, sqlancer_log, run_dir, use_cache) + test_single(cfg, script_log, docker_log, sqlancer_log, run_dir, use_cache) elif args.dbms == "all": for dbms in dbms_list: