From 0c555fc4f393294dc9b006fb768065bde8017b8a Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 26 Dec 2025 11:46:26 +0000 Subject: [PATCH 1/5] Use ENV directives instead of .bashrc for environment variables Replace the anti-pattern of setting environment variables via .bashrc with proper Docker ENV directives. This ensures: - Environment variables are available in all RUN commands - No need to source .bashrc in build steps - More reliable and Docker-native approach - Cleaner and more maintainable Dockerfile Variables moved to ENV: - PATH: Includes PostgreSQL bin directory - LD_LIBRARY_PATH: Includes PostgreSQL lib directory - PG_CONFIG: Points to pg_config binary This simplifies the Spock build step significantly. --- tests/docker/Dockerfile-step-1.el9 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/docker/Dockerfile-step-1.el9 b/tests/docker/Dockerfile-step-1.el9 index 5a9b4bc5..53f309c1 100644 --- a/tests/docker/Dockerfile-step-1.el9 +++ b/tests/docker/Dockerfile-step-1.el9 @@ -3,6 +3,9 @@ FROM ghcr.io/pgedge/base-test-image:latest ARG PGVER ENV PGVER=$PGVER +ENV PATH="/home/pgedge/pgedge/pg${PGVER}/bin:${PATH}" +ENV LD_LIBRARY_PATH="/home/pgedge/pgedge/pg${PGVER}/lib:${LD_LIBRARY_PATH}" +ENV PG_CONFIG="/home/pgedge/pgedge/pg${PGVER}/bin/pg_config" COPY . /home/pgedge/spock WORKDIR /home/pgedge @@ -37,12 +40,9 @@ RUN options="'--prefix=/home/pgedge/pgedge/pg$PGVER' '--disable-rpath' '--with-z WORKDIR /home/pgedge -RUN echo "export LD_LIBRARY_PATH=/home/pgedge/pgedge/pg$PGVER/lib/:$LD_LIBRARY_PATH" >> /home/pgedge/.bashrc -RUN echo "export PATH=/home/pgedge/pgedge/pg$PGVER/bin:$PATH" >> /home/pgedge/.bashrc - RUN echo "==========Recompiling Spock==========" WORKDIR /home/pgedge/spock -RUN . /home/pgedge/.bashrc && export PG_CONFIG=/home/pgedge/pgedge/pg$PGVER/bin/pg_config && export PATH=/home/pgedge/pgedge/pg$PGVER/bin:$PATH && make clean && make -j16 && make install +RUN make clean && make -j16 && make install RUN echo "==========Built Spock==========" From 76261795fd8c665dde3ec7cccaaad64e8374c428 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 26 Dec 2025 11:46:59 +0000 Subject: [PATCH 2/5] Improve PostgreSQL configure command readability Reformat the configure command from a single unreadable line with eval and quoted options to a clean multi-line format. Changes: - Remove unnecessary eval (potential security concern) - Remove shell variable with quoted options pattern - Use direct ./configure with multi-line arguments - Each option on its own line for easy review - Improved maintainability for future option changes This makes it much easier to: - Review which features are enabled - Add or remove configure options - Understand the build configuration at a glance --- tests/docker/Dockerfile-step-1.el9 | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/docker/Dockerfile-step-1.el9 b/tests/docker/Dockerfile-step-1.el9 index 53f309c1..48a2068f 100644 --- a/tests/docker/Dockerfile-step-1.el9 +++ b/tests/docker/Dockerfile-step-1.el9 @@ -36,7 +36,33 @@ RUN for patchfile in /home/pgedge/spock/patches/${PGVER}/*; do \ done RUN echo "==========Compiling Modified PostgreSQL==========" -RUN options="'--prefix=/home/pgedge/pgedge/pg$PGVER' '--disable-rpath' '--with-zstd' '--with-lz4' '--with-icu' '--with-libxslt' '--with-libxml' '--with-uuid=ossp' '--with-gssapi' '--with-ldap' '--with-pam' '--enable-debug' '--enable-dtrace' '--with-llvm' '--with-openssl' '--with-systemd' '--enable-tap-tests' '--with-python' '--enable-cassert' 'PYTHON=/usr/bin/python3.9' 'BITCODE_CFLAGS=-gdwarf-5 -O0 -fforce-dwarf-frame' 'CFLAGS=-g -O0'" && eval ./configure $options && make -j4 && make -C contrib -j4 && make install && make -C contrib install +RUN ./configure \ + --prefix="/home/pgedge/pgedge/pg${PGVER}" \ + --disable-rpath \ + --with-zstd \ + --with-lz4 \ + --with-icu \ + --with-libxslt \ + --with-libxml \ + --with-uuid=ossp \ + --with-gssapi \ + --with-ldap \ + --with-pam \ + --enable-debug \ + --enable-dtrace \ + --with-llvm \ + --with-openssl \ + --with-systemd \ + --enable-tap-tests \ + --with-python \ + --enable-cassert \ + PYTHON=/usr/bin/python3.9 \ + BITCODE_CFLAGS="-gdwarf-5 -O0 -fforce-dwarf-frame" \ + CFLAGS="-g -O0" && \ + make -j4 && \ + make -C contrib -j4 && \ + make install && \ + make -C contrib install WORKDIR /home/pgedge From 1e64e806d4ed089314fcd54ad4f487bdc64fd6d9 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 26 Dec 2025 11:48:10 +0000 Subject: [PATCH 3/5] Combine RUN layers to reduce image size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Merge multiple RUN commands into single layers to reduce the number of layers in the final Docker image. This optimization: - Reduces image size by combining related operations - Improves build efficiency - Better utilizes Docker layer caching - Follows Dockerfile best practices Changes: - PostgreSQL clone + chmod: 2 RUN → 1 RUN - pgedge setup: 3 RUN → 1 RUN - PostgreSQL compile: 2 RUN → 1 RUN - Spock compile: 3 RUN → 1 RUN - Added descriptive comments for each build stage - Removed duplicate WORKDIR directive Total reduction: ~6 fewer layers --- tests/docker/Dockerfile-step-1.el9 | 35 +++++++++++++++--------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/tests/docker/Dockerfile-step-1.el9 b/tests/docker/Dockerfile-step-1.el9 index 48a2068f..690100f6 100644 --- a/tests/docker/Dockerfile-step-1.el9 +++ b/tests/docker/Dockerfile-step-1.el9 @@ -10,7 +10,7 @@ ENV PG_CONFIG="/home/pgedge/pgedge/pg${PGVER}/bin/pg_config" COPY . /home/pgedge/spock WORKDIR /home/pgedge -RUN echo "Determine PostgreSQL tag" +# Determine PostgreSQL version and clone repository RUN LATEST_TAG=$(git ls-remote --tags https://github.com/postgres/postgres.git | \ grep "refs/tags/REL_${PGVER}_" | \ sed 's|.*refs/tags/||' | \ @@ -18,16 +18,14 @@ RUN LATEST_TAG=$(git ls-remote --tags https://github.com/postgres/postgres.git | sort -V | \ tail -n 1 | \ tr '.' '_') && \ - echo "Using tag $LATEST_TAG" && \ - git clone --branch $LATEST_TAG --depth 1 https://github.com/postgres/postgres /home/pgedge/postgres + echo "Using PostgreSQL tag: $LATEST_TAG" && \ + git clone --branch $LATEST_TAG --depth 1 https://github.com/postgres/postgres /home/pgedge/postgres && \ + chmod -R a+w /home/pgedge/postgres - -RUN sudo chmod -R a+w ~/postgres - -RUN echo "Setting up pgedge..." -WORKDIR /home/pgedge -RUN curl -fsSL https://pgedge-download.s3.amazonaws.com/REPO/install.py > /home/pgedge/install.py -RUN sudo -u pgedge python3 /home/pgedge/install.py +# Install pgedge +RUN echo "Setting up pgedge..." && \ + curl -fsSL https://pgedge-download.s3.amazonaws.com/REPO/install.py -o /home/pgedge/install.py && \ + sudo -u pgedge python3 /home/pgedge/install.py WORKDIR /home/pgedge/postgres @@ -35,8 +33,9 @@ RUN for patchfile in /home/pgedge/spock/patches/${PGVER}/*; do \ patch -p1 --verbose < $patchfile; \ done -RUN echo "==========Compiling Modified PostgreSQL==========" -RUN ./configure \ +# Compile PostgreSQL +RUN echo "==========Compiling Modified PostgreSQL==========" && \ + ./configure \ --prefix="/home/pgedge/pgedge/pg${PGVER}" \ --disable-rpath \ --with-zstd \ @@ -64,13 +63,13 @@ RUN ./configure \ make install && \ make -C contrib install -WORKDIR /home/pgedge - -RUN echo "==========Recompiling Spock==========" +# Compile Spock WORKDIR /home/pgedge/spock -RUN make clean && make -j16 && make install - -RUN echo "==========Built Spock==========" +RUN echo "==========Compiling Spock==========" && \ + make clean && \ + make -j16 && \ + make install && \ + echo "==========Spock build complete==========" #----------------------------------------- COPY tests/docker/*.sh /home/pgedge/ From 6b2da0419ccb007d75d934280d874f9cdb66cc60 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 26 Dec 2025 11:48:47 +0000 Subject: [PATCH 4/5] Add configurable build parallelism with MAKE_JOBS Introduce a build argument to control the number of parallel make jobs instead of using hardcoded values that differed between PostgreSQL and Spock builds. Changes: - Add ARG MAKE_JOBS=4 (default value) - Replace hardcoded -j4 (PostgreSQL) with -j${MAKE_JOBS} - Replace hardcoded -j16 (Spock) with -j${MAKE_JOBS} - Ensures consistent parallelism across all builds Benefits: - Can override at build time: --build-arg MAKE_JOBS=16 - Consistent behavior between PostgreSQL and Spock - Easy to tune for different build environments - Default of 4 is conservative and works on most systems The previous inconsistency (j4 vs j16) is now eliminated. --- tests/docker/Dockerfile-step-1.el9 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/docker/Dockerfile-step-1.el9 b/tests/docker/Dockerfile-step-1.el9 index 690100f6..b03ad9b1 100644 --- a/tests/docker/Dockerfile-step-1.el9 +++ b/tests/docker/Dockerfile-step-1.el9 @@ -1,6 +1,7 @@ FROM ghcr.io/pgedge/base-test-image:latest ARG PGVER +ARG MAKE_JOBS=4 ENV PGVER=$PGVER ENV PATH="/home/pgedge/pgedge/pg${PGVER}/bin:${PATH}" @@ -58,8 +59,8 @@ RUN echo "==========Compiling Modified PostgreSQL==========" && \ PYTHON=/usr/bin/python3.9 \ BITCODE_CFLAGS="-gdwarf-5 -O0 -fforce-dwarf-frame" \ CFLAGS="-g -O0" && \ - make -j4 && \ - make -C contrib -j4 && \ + make -j${MAKE_JOBS} && \ + make -C contrib -j${MAKE_JOBS} && \ make install && \ make -C contrib install @@ -67,7 +68,7 @@ RUN echo "==========Compiling Modified PostgreSQL==========" && \ WORKDIR /home/pgedge/spock RUN echo "==========Compiling Spock==========" && \ make clean && \ - make -j16 && \ + make -j${MAKE_JOBS} && \ make install && \ echo "==========Spock build complete==========" From db1eb56e6352a9e3ed38fe63fc27bcad3ba4ec76 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 26 Dec 2025 11:49:12 +0000 Subject: [PATCH 5/5] Use COPY --chmod instead of separate chmod layer Replace the two-step pattern of COPY + RUN chmod with the modern COPY --chmod directive available in BuildKit. Changes: - COPY --chmod=755 instead of COPY + RUN sudo chmod +x - Eliminates one RUN layer - Removes unnecessary sudo usage Benefits: - One fewer layer in the final image - Cleaner and more concise Dockerfile - Uses modern Docker/BuildKit features - Atomic operation (no window where files lack execute permission) This is the recommended approach in modern Dockerfiles. --- tests/docker/Dockerfile-step-1.el9 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/docker/Dockerfile-step-1.el9 b/tests/docker/Dockerfile-step-1.el9 index b03ad9b1..8511747c 100644 --- a/tests/docker/Dockerfile-step-1.el9 +++ b/tests/docker/Dockerfile-step-1.el9 @@ -73,8 +73,7 @@ RUN echo "==========Compiling Spock==========" && \ echo "==========Spock build complete==========" #----------------------------------------- -COPY tests/docker/*.sh /home/pgedge/ -RUN sudo chmod +x /home/pgedge/*.sh +COPY --chmod=755 tests/docker/*.sh /home/pgedge/ WORKDIR /home/pgedge/ USER pgedge