|
| 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)" |
0 commit comments