Skip to content

Commit

Permalink
feat: build multiarch pgrx image (#153)
Browse files Browse the repository at this point in the history
- `sqllogictest-rs ` doesn't have Linux ARM64 release, tracked
[here](risinglightdb/sqllogictest-rs#240)
- add rust-toolchain channel to image tag
- use arm64 runner for clippy/build & release

---------

Signed-off-by: Keming <[email protected]>
  • Loading branch information
kemingy authored Dec 27, 2024
1 parent 107c111 commit 01835f0
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 39 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/pgrx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ on:
description: 'pgrx version'
required: true
type: string
toolchain:
description: 'additional rust toolchain'
required: true
type: string

concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
Expand All @@ -21,9 +25,11 @@ permissions:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubicloud-standard-8
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to ghcr.io
Expand All @@ -38,6 +44,10 @@ jobs:
context: .
file: ./docker/pgrx.Dockerfile
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: "linux/amd64,linux/arm64"
build-args: |
PGRX_VERSION=${{ github.event.inputs.version }}
tags: ${{ env.IMAGE_NAME }}:${{ github.event.inputs.version }}
RUST_TOOLCHAIN=${{ github.event.inputs.toolchain }}
tags: ${{ env.IMAGE_NAME }}:${{ github.event.inputs.version }}-${{ github.event.inputs.toolchain }}
16 changes: 8 additions & 8 deletions .github/workflows/psql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ env:

jobs:
test:
runs-on: ubuntu-latest
runs-on: ${{ matrix.runner }}
strategy:
matrix:
version: ["14", "15", "16", "17"]
arch: ["x86_64"]
runner: ["ubuntu-latest"]
env:
PGRX_IMAGE: "ghcr.io/tensorchord/vectorchord-pgrx:0.12.9"
PGRX_IMAGE: "ghcr.io/tensorchord/vectorchord-pgrx:0.12.9-nightly-2024-12-25"
SQLLOGICTEST: "0.22.0"
ARCH: "x86_64"
PLATFORM: "amd64"

steps:
- uses: actions/checkout@v4
Expand All @@ -69,18 +71,16 @@ jobs:
env:
SEMVER: "0.0.0"
VERSION: ${{ matrix.version }}
ARCH: ${{ matrix.arch }}
PLATFORM: "amd64"
PROFILE: "opt"
run: |
docker run --rm -v .:/workspace $CACHE_ENVS $PGRX_IMAGE build --lib --features pg${{ matrix.version }} --target ${{ matrix.arch }}-unknown-linux-gnu --profile $PROFILE
docker run --rm -v .:/workspace $CACHE_ENVS --entrypoint bash $PGRX_IMAGE ./tools/schema.sh --features pg${{ matrix.version }} --target ${{ matrix.arch }}-unknown-linux-gnu --profile $PROFILE
docker run --rm -v .:/workspace $CACHE_ENVS $PGRX_IMAGE cargo build --lib --features pg${{ matrix.version }} --target $ARCH-unknown-linux-gnu --profile $PROFILE
docker run --rm -v .:/workspace $CACHE_ENVS $PGRX_IMAGE ./tools/schema.sh --features pg${{ matrix.version }} --target $ARCH-unknown-linux-gnu --profile $PROFILE
./tools/package.sh
docker build -t vchord:pg${{ matrix.version }} --build-arg PG_VERSION=${{ matrix.version }} -f ./docker/Dockerfile .
- name: Setup SQL Logic Test
run: |
curl -fsSL -o sqllogictest.tar.gz https://github.com/risinglightdb/sqllogictest-rs/releases/download/v${SQLLOGICTEST}/sqllogictest-bin-v${SQLLOGICTEST}-${{ matrix.arch }}-unknown-linux-musl.tar.gz
curl -fsSL -o sqllogictest.tar.gz https://github.com/risinglightdb/sqllogictest-rs/releases/download/v${SQLLOGICTEST}/sqllogictest-bin-v${SQLLOGICTEST}-$ARCH-unknown-linux-musl.tar.gz
tar -xzf sqllogictest.tar.gz
mv sqllogictest /usr/local/bin/
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@ jobs:
core.setOutput('SEMVER', tag);
build:
runs-on: ubuntu-latest
runs-on: ${{ matrix.runner }}
needs: ["semver"]
strategy:
matrix:
version: ["14", "15", "16", "17"]
arch: ["x86_64", "aarch64"]
runner: ["ubicloud-standard-4", "ubicloud-standard-4-arm"]
env:
PGRX_IMAGE: "ghcr.io/tensorchord/vectorchord-pgrx:0.12.9"
PGRX_IMAGE: "ghcr.io/tensorchord/vectorchord-pgrx:0.12.9-nightly-2024-12-25"
SEMVER: ${{ needs.semver.outputs.SEMVER }}
ARCH: ${{ matrix.runner == 'ubicloud-standard-4' && 'x86_64' || 'aarch64' }}
PLATFORM: ${{ matrix.runner == 'ubicloud-standard-4' && 'amd64' || 'arm64' }}

steps:
- uses: actions/checkout@v4
Expand All @@ -64,13 +66,11 @@ jobs:
- name: Build
env:
VERSION: ${{ matrix.version }}
ARCH: ${{ matrix.arch }}
PLATFORM: ${{ matrix.arch == 'x86_64' && 'amd64' || 'arm64' }}
PROFILE: "release"
GH_TOKEN: ${{ github.token }}
run: |
docker run --rm -v .:/workspace $CACHE_ENVS $PGRX_IMAGE build --lib --features pg${{ matrix.version }} --target ${{ matrix.arch }}-unknown-linux-gnu --profile $PROFILE
docker run --rm -v .:/workspace $CACHE_ENVS --entrypoint bash -e SEMVER=${SEMVER} $PGRX_IMAGE ./tools/schema.sh --features pg${{ matrix.version }} --target ${{ matrix.arch }}-unknown-linux-gnu --profile $PROFILE
docker run --rm -v .:/workspace $CACHE_ENVS $PGRX_IMAGE cargo build --lib --features pg$VERSION --profile $PROFILE
docker run --rm -v .:/workspace $CACHE_ENVS -e SEMVER=${SEMVER} $PGRX_IMAGE ./tools/schema.sh --features pg$VERSION --profile $PROFILE
./tools/package.sh
ls ./build
gh release upload --clobber $SEMVER ./build/vchord-pg${VERSION}_${SEMVER}_${PLATFORM}.deb
Expand Down
16 changes: 10 additions & 6 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ concurrency:

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
arch: ["x86_64", "aarch64"]
include:
- runner: "ubicloud-standard-4"
arch: "x86_64"
- runner: "ubicloud-standard-4-arm"
arch: "aarch64"
runs-on: ${{ matrix.runner }}
env:
PGRX_IMAGE: "ghcr.io/tensorchord/vectorchord-pgrx:0.12.9"
PGRX_IMAGE: "ghcr.io/tensorchord/vectorchord-pgrx:0.12.9-nightly-2024-12-25"

steps:
- uses: actions/checkout@v4
Expand All @@ -56,14 +60,14 @@ jobs:
- name: Clippy
run: |
for v in {14..17}; do
docker run --rm -v .:/workspace $CACHE_ENVS $PGRX_IMAGE clippy --target ${{ matrix.arch }}-unknown-linux-gnu --features "pg$v" -- -D warnings
docker run --rm -v .:/workspace $CACHE_ENVS $PGRX_IMAGE cargo clippy --target ${{ matrix.arch }}-unknown-linux-gnu --features "pg$v" -- -D warnings
done
- name: Build
run: |
for v in {14..17}; do
docker run --rm -v .:/workspace $CACHE_ENVS $PGRX_IMAGE build --lib --target ${{ matrix.arch }}-unknown-linux-gnu --features "pg$v"
docker run --rm -v .:/workspace $CACHE_ENVS $PGRX_IMAGE cargo build --lib --target ${{ matrix.arch }}-unknown-linux-gnu --features "pg$v"
done
- name: Test
run: |
# pg agnostic tests
docker run --rm -v .:/workspace $CACHE_ENVS $PGRX_IMAGE test --no-fail-fast --target ${{ matrix.arch }}-unknown-linux-gnu --features pg17
docker run --rm -v .:/workspace $CACHE_ENVS $PGRX_IMAGE cargo test --no-fail-fast --target ${{ matrix.arch }}-unknown-linux-gnu --features pg17
27 changes: 11 additions & 16 deletions docker/pgrx.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# CNPG only support Debian 12 (Bookworm)
FROM ubuntu:22.04

ARG PGRX_VERSION=0.12.8
ARG SCCACHE_VERSION=0.8.2
ARG PGRX_VERSION
ARG RUST_TOOLCHAIN
ARG TARGETARCH

ENV DEBIAN_FRONTEND=noninteractive \
LANG=en_US.UTF-8 \
LC_ALL=en_US.UTF-8 \
RUSTFLAGS="-Dwarnings" \
RUST_BACKTRACE=1 \
CARGO_TERM_COLOR=always
CARGO_TERM_COLOR=always \
SCCACHE_VERSION=0.9.0

RUN set -eux; \
apt update; \
Expand All @@ -18,17 +20,16 @@ RUN set -eux; \
ca-certificates \
build-essential \
postgresql-common gnupg \
crossbuild-essential-arm64 \
qemu-user-static \
libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt-dev libssl-dev libxml2-utils xsltproc ccache pkg-config

RUN apt -y install lsb-release wget software-properties-common gnupg; \
RUN set -eux; \
apt -y install lsb-release wget software-properties-common gnupg; \
curl --proto '=https' --tlsv1.2 -sSf https://apt.llvm.org/llvm.sh | bash -s -- 18; \
update-alternatives --install /usr/bin/clang clang $(which clang-18) 255

# set up sccache
RUN set -ex; \
curl -fsSL -o sccache.tar.gz https://github.com/mozilla/sccache/releases/download/v${SCCACHE_VERSION}/sccache-v${SCCACHE_VERSION}-x86_64-unknown-linux-musl.tar.gz; \
curl -fsSL -o sccache.tar.gz https://github.com/mozilla/sccache/releases/download/v${SCCACHE_VERSION}/sccache-v${SCCACHE_VERSION}-$(uname -m)-unknown-linux-musl.tar.gz; \
tar -xzf sccache.tar.gz --strip-components=1; \
rm sccache.tar.gz; \
mv sccache /usr/local/bin/
Expand All @@ -47,16 +48,10 @@ RUN chown -R ubuntu:ubuntu /usr/share/postgresql/ /usr/lib/postgresql/
USER ubuntu
ENV PATH="$PATH:/home/ubuntu/.cargo/bin"
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
RUN rustup target add x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu

WORKDIR /workspace
COPY rust-toolchain.toml /workspace/rust-toolchain.toml
RUN rustup target add x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu

# ref: https://github.com/pgcentralfoundation/pgrx/blob/develop/docs/src/extension/build/cross-compile.md
RUN set -ex; \
echo 'target.aarch64-unknown-linux-gnu.linker = "aarch64-linux-gnu-gcc"' >> ~/.cargo/config.toml; \
echo 'target.aarch64-unknown-linux-gnu.runner = ["qemu-aarch64-static", "-L", "/usr/aarch64-linux-gnu"]' >> ~/.cargo/config.toml
RUN rustup toolchain install ${RUST_TOOLCHAIN}
RUN rustup target add $(uname -m)-unknown-linux-gnu

RUN cargo install cargo-pgrx --locked --version=${PGRX_VERSION}

Expand All @@ -65,4 +60,4 @@ RUN set -ex; \
cargo pgrx init --pg$v=/usr/lib/postgresql/$v/bin/pg_config; \
done;

ENTRYPOINT [ "cargo" ]
CMD [ "/bin/bash" ]

0 comments on commit 01835f0

Please sign in to comment.