# syntax=docker/dockerfile:1 # # Compile pg_search against the runtime distribution, independently of the host # runner OS. Only the extension is copied into the final released ParadeDB image. # The build context is the repository source at the selected revision. ARG BASE_IMAGE=paradedb/paradedb:latest-pg18 FROM ${BASE_IMAGE} AS base FROM base AS builder # Build tools stay in this stage; the runtime starts from the clean base image. # hadolint ignore=DL3002 USER 0 ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update && apt-get install -y --no-install-recommends \ postgresql-server-dev-18 build-essential ca-certificates curl git \ pkg-config libssl-dev libicu-dev clang llvm libclang-dev lld binutils libopenblas-dev && \ rm -rf /var/lib/apt/lists/* ENV CARGO_HOME=/opt/cargo RUSTUP_HOME=/opt/rustup ENV PATH="/opt/cargo/bin:/usr/lib/postgresql/18/bin:${PATH}" WORKDIR /versions COPY rust-toolchain.toml Cargo.toml ./ RUN rust=$(sed -nE 's/^channel = "([^"]+)"$/\1/p' rust-toolchain.toml) && \ pgrx=$(sed -nE 's/^pgrx = "=?([^"]+)"$/\1/p' Cargo.toml) && \ test -n "$rust" && test -n "$pgrx" && \ curl -fsSL --retry 5 --retry-all-errors https://sh.rustup.rs -o /tmp/rustup.sh && \ sh /tmp/rustup.sh -y --profile minimal --default-toolchain "$rust" && \ cargo install cargo-pgrx --version "$pgrx" --debug --locked && \ cargo pgrx init --pg18=/usr/lib/postgresql/18/bin/pg_config WORKDIR /build COPY . . # Scope SanitizerCoverage to the explicit target so host build scripts and # cargo-pgrx stay uninstrumented. Keep the release path identical for benchmarks. # DST runs currently use Antithesis instrumentation and require linux/amd64. ARG DST=false RUN /bin/bash <<'BUILD' set -euo pipefail args=(--package pg_search --profile release --pg-config /usr/lib/postgresql/18/bin/pg_config --out-dir /package) case "$DST" in false) ;; true) test "$(dpkg --print-architecture)" = amd64 args=(--package pg_search --profile dst --features dst --target x86_64-unknown-linux-gnu --pg-config /usr/lib/postgresql/18/bin/pg_config --out-dir /package) export CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS="-Ccodegen-units=1 -Cpasses=sancov-module -Cllvm-args=-sanitizer-coverage-level=3 -Cllvm-args=-sanitizer-coverage-trace-pc-guard -Clink-args=-Wl,--build-id" ;; *) echo "Invalid DST value: $DST" >&2; exit 1 ;; esac cargo pgrx package --no-assemble-unreleased --no-distrib-packages "${args[@]}" mkdir -p /artifacts/usr/lib/postgresql/18/lib /artifacts/usr/share/postgresql/18/extension find /package -type f -name 'pg_search*.so' -exec cp {} /artifacts/usr/lib/postgresql/18/lib/ \; find /package -type f -name 'pg_search*.control' -exec cp {} /artifacts/usr/share/postgresql/18/extension/ \; find /package -type f -name 'pg_search*.sql' -exec cp {} /artifacts/usr/share/postgresql/18/extension/ \; lib=/artifacts/usr/lib/postgresql/18/lib/pg_search.so test -s "$lib" test -s /artifacts/usr/share/postgresql/18/extension/pg_search.control # PostgreSQL C symbols may remain undefined; Rust symbols indicate a broken .so. undefined_rust=$(nm -D -u "$lib" | awk '{print $NF}' | grep -E '^_(ZN|R)' || true) if [ -n "$undefined_rust" ]; then echo "pg_search.so has unresolved Rust symbols: $undefined_rust" >&2 exit 1 fi if [ "$DST" = true ]; then # Check before stripping; fail rather than shipping uninstrumented code. nm "$lib" | grep 'antithesis_load_libvoidstar' > /dev/null readelf -S "$lib" | grep -i 'sancov' > /dev/null objcopy --only-keep-debug "$lib" "$lib.dbg" objcopy --strip-debug "$lib" objcopy --add-gnu-debuglink="$lib.dbg" "$lib" mkdir /artifacts/symbols ln -s /usr/lib/postgresql/18/lib/pg_search.so /artifacts/symbols/pg_search.so ln -s /usr/lib/postgresql/18/lib/pg_search.so.dbg /artifacts/symbols/pg_search.so.dbg fi BUILD FROM base AS runtime # Remove the released extension before installing the source build so old SQL # scripts cannot survive the overlay. CREATE EXTENSION then uses only the source # build. Runtime dependencies are supplied by the released base image. RUN rm -f /usr/lib/postgresql/18/lib/pg_search*.so /usr/lib/postgresql/18/lib/pg_search*.so.dbg \ /usr/share/postgresql/18/extension/pg_search*.control \ /usr/share/postgresql/18/extension/pg_search*.sql COPY --from=builder /artifacts/ / # Use the source revision's bootstrap rather than the released base image's. COPY docker/bootstrap.sh /docker-entrypoint-initdb.d/10_bootstrap_paradedb.sh # initdb loads the preloaded extensions, catching missing libraries or symbol # versions before a benchmark downloads its dataset or Cloud publishes an image. RUN gosu postgres initdb --no-sync --auth=trust -D /tmp/pg-search-smoke && \ rm -rf /tmp/pg-search-smoke