Skip to content

Commit 9f06bc7

Browse files
authored
support dockerfiles that build postgres from source code (#15)
1 parent 5a48ce3 commit 9f06bc7

4 files changed

Lines changed: 63 additions & 2 deletions

File tree

build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def build_db_image(cfg, use_cache, script_log, docker_log, custom=False, dockerf
5454
build_cmd.insert(2, "--no-cache")
5555
script_log.info("Building db image: %s ...", cfg["image"])
5656
run_command(build_cmd, docker_log)
57-
script_log.info("DB image pulled: %s ...", cfg["image"])
57+
script_log.info("DB image built: %s ...", cfg["image"])
5858
else:
5959
script_log.info("DB image already exists: %s", cfg["image"])
6060

postgres/Dockerfile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
FROM ubuntu:22.04
2+
3+
RUN apt-get update && \
4+
DEBIAN_FRONTEND=noninteractive apt-get install -y \
5+
git build-essential libreadline-dev zlib1g-dev flex bison \
6+
libxml2-dev libxslt1-dev libssl-dev libicu-dev pkg-config \
7+
wget ca-certificates lsb-release pwgen && \
8+
apt-get clean
9+
10+
ENV PG_VERSION=17 \
11+
PG_USER=postgres \
12+
PG_BASE=/usr/local/pgsql \
13+
PG_DATADIR=/var/lib/postgresql/data
14+
15+
# Clone & build PostgreSQL from source
16+
RUN git clone --depth 1 --branch REL_${PG_VERSION}_STABLE https://github.com/postgres/postgres.git /tmp/postgres && \
17+
cd /tmp/postgres && \
18+
./configure --prefix=${PG_BASE} && \
19+
make -j"$(nproc)" && \
20+
make install && \
21+
rm -rf /tmp/postgres
22+
23+
# Create user and directories
24+
RUN useradd -r -s /bin/bash ${PG_USER} && \
25+
mkdir -p ${PG_DATADIR} /var/run/postgresql && \
26+
chown -R ${PG_USER}:${PG_USER} ${PG_DATADIR} /var/run/postgresql ${PG_BASE}
27+
28+
# Copy entrypoint
29+
COPY entrypoint.sh /entrypoint.sh
30+
RUN chmod +x /entrypoint.sh
31+
32+
# Update PATH
33+
ENV PATH=${PG_BASE}/bin:$PATH
34+
35+
# Expose PostgreSQL port
36+
EXPOSE 5432
37+
38+
# Run PostgreSQL with init and config
39+
ENTRYPOINT ["/entrypoint.sh"]

postgres/entrypoint.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo ">> Initializing database at ${PG_DATADIR}"
5+
if [ ! -s "${PG_DATADIR}/PG_VERSION" ]; then
6+
su -s /bin/bash -c "${PG_BASE}/bin/initdb -D ${PG_DATADIR}" ${PG_USER}
7+
8+
echo ">> Configuring postgresql.conf and pg_hba.conf"
9+
10+
echo "listen_addresses='*'" >> ${PG_DATADIR}/postgresql.conf
11+
echo "host all all 0.0.0.0/0 md5" >> ${PG_DATADIR}/pg_hba.conf
12+
13+
# Start DB temporarily to run SQL setup
14+
su -s /bin/bash -c "${PG_BASE}/bin/pg_ctl -D ${PG_DATADIR} -w start" ${PG_USER}
15+
16+
echo "ALTER USER ${PG_USER} WITH PASSWORD '12345678';" | su -s /bin/bash -c "${PG_BASE}/bin/psql" ${PG_USER}
17+
18+
su -s /bin/bash -c "${PG_BASE}/bin/pg_ctl -D ${PG_DATADIR} -m fast stop" ${PG_USER}
19+
fi
20+
21+
echo ">> Starting PostgreSQL..."
22+
exec su -s /bin/bash -c "${PG_BASE}/bin/postgres -D ${PG_DATADIR}" ${PG_USER}

start.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def main():
4343
parser.error("Custom DBMS test requires --config")
4444
cfg = load_json(args.config)
4545
build_environment(cfg, use_cache, script_log, docker_log, True, args.dockerfile)
46-
test_custom_dockerfile(args.dockerfile, cfg, script_log, docker_log, sqlancer_log, run_dir, use_cache)
46+
test_single(cfg, script_log, docker_log, sqlancer_log, run_dir, use_cache)
4747

4848
elif args.dbms == "all":
4949
for dbms in dbms_list:

0 commit comments

Comments
 (0)