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
2 changes: 1 addition & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand Down
39 changes: 39 additions & 0 deletions postgres/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
22 changes: 22 additions & 0 deletions postgres/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 1 addition & 1 deletion start.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down