Skip to content

Commit e8c0b57

Browse files
committed
test(postgres): build the debug image with no-optimization flag
1 parent 06727f2 commit e8c0b57

File tree

3 files changed

+115
-3
lines changed

3 files changed

+115
-3
lines changed

docker/postgresql/Dockerfile.debug

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,19 @@ RUN apt-get update && apt-get install -y \
1717
&& echo "deb-src http://deb.debian.org/debian ${VERSION_CODENAME} main" > /etc/apt/sources.list.d/debian-src.list \
1818
&& apt-get update && apt-get install -y \
1919
build-essential \
20+
bison \
2021
dpkg-dev \
22+
flex \
2123
gdb \
24+
libicu-dev \
25+
libreadline-dev \
2226
libasan8 \
27+
libssl-dev \
2328
postgresql-server-dev-17 \
2429
postgresql-17-dbgsym \
2530
git \
2631
make \
32+
zlib1g-dev \
2733
&& apt-get source postgresql-17 \
2834
&& mkdir -p /usr/src/postgresql-17 \
2935
&& srcdir="$(find . -maxdepth 1 -type d -name 'postgresql-17*' | head -n 1)" \
@@ -33,6 +39,16 @@ RUN apt-get update && apt-get install -y \
3339
# Create directory for extension source
3440
WORKDIR /tmp/cloudsync
3541

42+
# Build PostgreSQL from source without optimizations for better gdb visibility
43+
RUN set -eux; \
44+
cd /usr/src/postgresql-17; \
45+
./configure --enable-debug --enable-cassert --without-icu CFLAGS="-O0 -g3 -fno-omit-frame-pointer"; \
46+
make -j"$(nproc)"; \
47+
make install
48+
49+
ENV PATH="/usr/local/pgsql/bin:${PATH}"
50+
ENV LD_LIBRARY_PATH="/usr/local/pgsql/lib:${LD_LIBRARY_PATH}"
51+
3652
# Copy entire source tree (needed for includes and makefiles)
3753
COPY src/ ./src/
3854
COPY docker/ ./docker/
@@ -49,11 +65,11 @@ RUN set -eux; \
4965
make postgres-build PG_DEBUG=1 \
5066
PG_CFLAGS="-fPIC -Wall -Wextra -Wno-unused-parameter -std=c11 -g -O0 -fno-omit-frame-pointer ${ASAN_CFLAGS}" \
5167
PG_LDFLAGS="-shared ${ASAN_LDFLAGS}" \
52-
PG_CPPFLAGS="-I$(pg_config --includedir-server) -Isrc -Isrc/postgresql -DCLOUDSYNC_POSTGRESQL_BUILD -D_POSIX_C_SOURCE=200809L -D_GNU_SOURCE -DMEMORY_CONTEXT_CHECKING" && \
68+
PG_CPPFLAGS="-I$(pg_config --includedir-server) -Isrc -Isrc/postgresql -DCLOUDSYNC_POSTGRESQL_BUILD -D_POSIX_C_SOURCE=200809L -D_GNU_SOURCE" && \
5369
make postgres-install PG_DEBUG=1 \
5470
PG_CFLAGS="-fPIC -Wall -Wextra -Wno-unused-parameter -std=c11 -g -O0 -fno-omit-frame-pointer ${ASAN_CFLAGS}" \
5571
PG_LDFLAGS="-shared ${ASAN_LDFLAGS}" \
56-
PG_CPPFLAGS="-I$(pg_config --includedir-server) -Isrc -Isrc/postgresql -DCLOUDSYNC_POSTGRESQL_BUILD -D_POSIX_C_SOURCE=200809L -D_GNU_SOURCE -DMEMORY_CONTEXT_CHECKING" && \
72+
PG_CPPFLAGS="-I$(pg_config --includedir-server) -Isrc -Isrc/postgresql -DCLOUDSYNC_POSTGRESQL_BUILD -D_POSIX_C_SOURCE=200809L -D_GNU_SOURCE" && \
5773
make postgres-clean
5874

5975
# Verify installation
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# PostgreSQL Docker image with CloudSync extension (debug build)
2+
FROM postgres:17
3+
4+
# Enable ASAN build flags when requested (used by docker-compose.asan.yml).
5+
ARG ENABLE_ASAN=0
6+
7+
# Install build dependencies and debug symbols
8+
RUN apt-get update && apt-get install -y \
9+
ca-certificates \
10+
gnupg \
11+
wget \
12+
&& . /etc/os-release \
13+
&& echo "deb http://apt.postgresql.org/pub/repos/apt ${VERSION_CODENAME}-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
14+
&& echo "deb-src http://apt.postgresql.org/pub/repos/apt ${VERSION_CODENAME}-pgdg main" > /etc/apt/sources.list.d/pgdg-src.list \
15+
&& wget -qO- https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg \
16+
&& echo "deb http://deb.debian.org/debian-debug ${VERSION_CODENAME}-debug main" > /etc/apt/sources.list.d/debian-debug.list \
17+
&& echo "deb-src http://deb.debian.org/debian ${VERSION_CODENAME} main" > /etc/apt/sources.list.d/debian-src.list \
18+
&& apt-get update && apt-get install -y \
19+
build-essential \
20+
bison \
21+
dpkg-dev \
22+
flex \
23+
gdb \
24+
libicu-dev \
25+
libreadline-dev \
26+
libasan8 \
27+
libssl-dev \
28+
postgresql-server-dev-17 \
29+
postgresql-17-dbgsym \
30+
git \
31+
make \
32+
zlib1g-dev \
33+
&& apt-get source postgresql-17 \
34+
&& mkdir -p /usr/src/postgresql-17 \
35+
&& srcdir="$(find . -maxdepth 1 -type d -name 'postgresql-17*' | head -n 1)" \
36+
&& if [ -n "$srcdir" ]; then cp -a "$srcdir"/. /usr/src/postgresql-17/; fi \
37+
&& rm -rf /var/lib/apt/lists/*
38+
39+
# Create directory for extension source
40+
WORKDIR /tmp/cloudsync
41+
42+
# Build PostgreSQL from source without optimizations for better gdb visibility
43+
RUN set -eux; \
44+
cd /usr/src/postgresql-17; \
45+
./configure --enable-debug --enable-cassert --without-icu CFLAGS="-O0 -g3 -fno-omit-frame-pointer"; \
46+
make -j"$(nproc)"; \
47+
make install
48+
49+
ENV PATH="/usr/local/pgsql/bin:${PATH}"
50+
ENV LD_LIBRARY_PATH="/usr/local/pgsql/lib:${LD_LIBRARY_PATH}"
51+
52+
# Copy entire source tree (needed for includes and makefiles)
53+
COPY src/ ./src/
54+
COPY docker/ ./docker/
55+
COPY Makefile .
56+
57+
# Build and install the CloudSync extension with debug flags
58+
RUN set -eux; \
59+
ASAN_CFLAGS=""; \
60+
ASAN_LDFLAGS=""; \
61+
if [ "${ENABLE_ASAN}" = "1" ]; then \
62+
ASAN_CFLAGS="-fsanitize=address"; \
63+
ASAN_LDFLAGS="-fsanitize=address"; \
64+
fi; \
65+
make postgres-build PG_DEBUG=1 \
66+
PG_CFLAGS="-fPIC -Wall -Wextra -Wno-unused-parameter -std=c11 -g -O0 -fno-omit-frame-pointer ${ASAN_CFLAGS}" \
67+
PG_LDFLAGS="-shared ${ASAN_LDFLAGS}" \
68+
PG_CPPFLAGS="-I$(pg_config --includedir-server) -Isrc -Isrc/postgresql -DCLOUDSYNC_POSTGRESQL_BUILD -D_POSIX_C_SOURCE=200809L -D_GNU_SOURCE" && \
69+
make postgres-install PG_DEBUG=1 \
70+
PG_CFLAGS="-fPIC -Wall -Wextra -Wno-unused-parameter -std=c11 -g -O0 -fno-omit-frame-pointer ${ASAN_CFLAGS}" \
71+
PG_LDFLAGS="-shared ${ASAN_LDFLAGS}" \
72+
PG_CPPFLAGS="-I$(pg_config --includedir-server) -Isrc -Isrc/postgresql -DCLOUDSYNC_POSTGRESQL_BUILD -D_POSIX_C_SOURCE=200809L -D_GNU_SOURCE" && \
73+
make postgres-clean
74+
75+
# Verify installation
76+
RUN echo "Verifying CloudSync extension installation..." && \
77+
ls -la $(pg_config --pkglibdir)/cloudsync.so && \
78+
ls -la $(pg_config --sharedir)/extension/cloudsync* && \
79+
echo "CloudSync extension installed successfully"
80+
81+
# Set default PostgreSQL credentials
82+
ENV POSTGRES_PASSWORD=postgres
83+
ENV POSTGRES_DB=cloudsync_test
84+
85+
# Expose PostgreSQL port
86+
EXPOSE 5432
87+
88+
# Copy initialization script (creates CloudSync metadata tables)
89+
COPY docker/postgresql/init.sql /docker-entrypoint-initdb.d/
90+
91+
# Return to root directory
92+
WORKDIR /
93+
94+
# Add label with extension version
95+
LABEL org.sqliteai.cloudsync.version="1.0" \
96+
org.sqliteai.cloudsync.description="PostgreSQL with CloudSync CRDT extension (debug)"

docker/postgresql/docker-compose.debug.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ services:
22
postgres:
33
build:
44
context: ../..
5-
dockerfile: docker/postgresql/Dockerfile.debug
5+
dockerfile: docker/postgresql/Dockerfile.debug-no-optimization
66
container_name: cloudsync-postgres
77
environment:
88
POSTGRES_USER: postgres

0 commit comments

Comments
 (0)