Skip to content

Commit

Permalink
feat: Dynamically determine pgrx version in CI / Docker (paradedb#1655)
Browse files Browse the repository at this point in the history
  • Loading branch information
Weijun-H authored Sep 15, 2024
1 parent cef61c7 commit f9ea91b
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 14 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/benchmark-pg_search.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,14 @@ jobs:
sudo chown -R $(whoami) /usr/share/postgresql/${{ matrix.pg_version }}/ /usr/lib/postgresql/${{ matrix.pg_version }}/ /var/lib/postgresql/${{ matrix.pg_version }}/
echo "/usr/lib/postgresql/${{ matrix.pg_version }}/bin" >> $GITHUB_PATH
- name: Extract pgrx version
working-directory: pg_search/
run: echo "PGRX_VERSION=$(cargo tree --depth 1 -i pgrx -p pg_search | head -n 1 | cut -f2 -dv)" >> $GITHUB_ENV

- name: Install pgrx & pg_search
working-directory: pg_search/
run: |
cargo install -j $(nproc) --locked cargo-pgrx --version 0.12.4
cargo install -j $(nproc) --locked cargo-pgrx --version ${{ env.PGRX_VERSION }}
cargo pgrx init --pg${{ matrix.pg_version }}=/usr/lib/postgresql/${{ matrix.pg_version }}/bin/pg_config
cargo pgrx install --pg-config="/usr/lib/postgresql/${{ matrix.pg_version }}/bin/pg_config" --release
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/lint-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ jobs:
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
sudo apt-get update && sudo apt-get install -y postgresql-${{ matrix.pg_version }} postgresql-server-dev-${{ matrix.pg_version }}
- name: Extract pgrx version
working-directory: pg_search/
run: echo "PGRX_VERSION=$(cargo tree --depth 1 -i pgrx -p pg_search | head -n 1 | cut -f2 -dv )" >> $GITHUB_ENV

- name: Install pgrx
run: cargo install --locked cargo-pgrx --version 0.12.4
run: cargo install --locked cargo-pgrx --version ${{ env.PGRX_VERSION }}

- name: Initialize pgrx for Current PostgreSQL Version
run: cargo pgrx init --pg${{ matrix.pg_version }}=/usr/lib/postgresql/${{ matrix.pg_version }}/bin/pg_config
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/publish-pg_search.yml
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,12 @@ jobs:
# Install PostgreSQL:
sudo dnf install -y postgresql${{ matrix.pg_version }} postgresql${{ matrix.pg_version }}-server postgresql${{ matrix.pg_version }}-devel
- name: Extract pgrx version
working-directory: pg_search/
run: echo "PGRX_VERSION=$(cargo tree --depth 1 -i pgrx -p pg_search | head -n 1 | cut -f2 -dv)" >> $GITHUB_ENV

- name: Install pgrx
run: cargo install --locked cargo-pgrx --version 0.12.4
run: cargo install --locked cargo-pgrx --version ${{ env.PGRX_VERSION }}

# Note: We need to specify bash as the shell to ensure that it doesn't default to /bin/sh on Debian, which doesn't support the `[[` syntax
- name: Initialize pgrx for Current PostgreSQL Version
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/test-pg_search.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,14 @@ jobs:
sudo PG_CONFIG=/usr/lib/postgresql/${{ matrix.pg_version }}/bin/pg_config make -j
sudo PG_CONFIG=/usr/lib/postgresql/${{ matrix.pg_version }}/bin/pg_config make install -j
- name: Extract pgrx version
working-directory: pg_search/
run: echo "PGRX_VERSION=$(cargo tree --depth 1 -i pgrx -p pg_search | head -n 1 | cut -f2 -dv)" >> $GITHUB_ENV

- name: Install pgrx & llvm-tools-preview
if: steps.check_skip.outputs.skip_remaining_steps != 'true'
run: |
cargo install -j $(nproc) --locked cargo-pgrx --version 0.12.4
cargo install -j $(nproc) --locked cargo-pgrx --version ${{ env.PGRX_VERSION }}
rustup component add llvm-tools-preview
cargo pgrx init "--pg${{ matrix.pg_version }}=/usr/lib/postgresql/${{ matrix.pg_version }}/bin/pg_config"
Expand Down Expand Up @@ -279,10 +283,14 @@ jobs:
cache-all-crates: true
save-if: ${{ github.ref == 'refs/heads/dev' }}

- name: Extract pgrx version
working-directory: pg_search/
run: echo "PGRX_VERSION=$(grep '^pgrx = ' Cargo.toml | sed -E 's/pgrx = "(.*)"/\1/')" >> $GITHUB_ENV

- name: Install pgrx & llvm-tools-preview
if: steps.check_skip.outputs.skip_remaining_steps != 'true'
run: |
cargo install -j $(nproc) --locked cargo-pgrx --version 0.12.4
cargo install -j $(nproc) --locked cargo-pgrx --version ${{ env.PGRX_VERSION }}
rustup component add llvm-tools-preview
cargo pgrx init "--pg${{ matrix.pg_version }}=download"
Expand Down
29 changes: 20 additions & 9 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ FROM postgres:${PG_VERSION_MAJOR}-bookworm AS builder

ARG PG_VERSION_MAJOR=16
ARG RUST_VERSION=1.80.0
ARG PGRX_VERSION=0.12.4
ARG PGRX_VERSION_PG_VECTOR_SCALE=0.11.4

# Declare buildtime environment variables
ENV PG_VERSION_MAJOR=${PG_VERSION_MAJOR} \
RUST_VERSION=${RUST_VERSION} \
PGRX_VERSION=${PGRX_VERSION} \
PGRX_VERSION_PG_VECTOR_SCALE=${PGRX_VERSION_PG_VECTOR_SCALE}

SHELL ["/bin/bash", "-o", "pipefail", "-c", "-e"]
Expand All @@ -41,10 +38,18 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --defau
ENV PATH="/root/.cargo/bin:$PATH" \
PGX_HOME=/usr/lib/postgresql/${PG_VERSION_MAJOR}

# Copy Cargo.toml because we need to extract the pgrx version
WORKDIR /tmp
COPY pg_search/Cargo.toml ./

# Intall the pgrx version of pg_search and pg_analytics
RUN cargo install --locked cargo-pgrx --version "${PGRX_VERSION}" && \
RUN PGRX_VERSION=$(sed -n 's/^pgrx *= *"=*\([0-9.]*\)"/\1/p' Cargo.toml) && \
echo "PGRX_VERSION=$PGRX_VERSION" && \
cargo install --locked cargo-pgrx --version "${PGRX_VERSION}" && \
cargo pgrx init "--pg${PG_VERSION_MAJOR}=/usr/lib/postgresql/${PG_VERSION_MAJOR}/bin/pg_config"

RUN rm -rf /tmp/Cargo.toml

######################
# pg_search
######################
Expand Down Expand Up @@ -114,16 +119,22 @@ RUN export PG_CFLAGS="-Wall -Wextra -Werror -Wno-unused-parameter -Wno-sign-comp

FROM builder AS builder-pgvectorscale

# Intall the pgrx version of pgvectorscale
RUN cargo install --locked cargo-pgrx --version "${PGRX_VERSION_PG_VECTOR_SCALE}" && \
cargo pgrx init "--pg${PG_VERSION_MAJOR}=/usr/lib/postgresql/${PG_VERSION_MAJOR}/bin/pg_config"

ARG TARGETARCH

# Build the extension
SHELL ["/bin/bash", "-o", "pipefail", "-c", "-e"]

# Clone the pgvectorscale repository
WORKDIR /tmp
RUN git clone --branch 0.3.0 https://github.com/timescale/pgvectorscale.git
WORKDIR /tmp/pgvectorscale/pgvectorscale

# Intall the pgrx version of pgvectorscale
RUN PGRX_VERSION=$(cargo tree --depth 1 -i pgrx -p pgvectorscale | head -n 1 | cut -f2 -dv) && \
echo "PGRX_VERSION=$PGRX_VERSION" && \
cargo install --locked cargo-pgrx --version "${PGRX_VERSION}" && \
cargo pgrx init "--pg${PG_VERSION_MAJOR}=/usr/lib/postgresql/${PG_VERSION_MAJOR}/bin/pg_config"

# Build the extension
RUN if [ "$TARGETARCH" = "amd64" ]; then \
# Required for pgvectorscale to compile on x86_64/amd64
RUSTFLAGS="-C target-feature=+avx2,+fma" cargo pgrx package --pg-config "/usr/lib/postgresql/${PG_VERSION_MAJOR}/bin/pg_config"; \
Expand Down

0 comments on commit f9ea91b

Please sign in to comment.