From 919ebce0960f5001e5e4d2dcaebdbb2eca5b388e Mon Sep 17 00:00:00 2001 From: Keming Date: Fri, 1 Nov 2024 23:46:56 +0800 Subject: [PATCH] use pgrx docker image to accelerate the dev-build/clippy/test Signed-off-by: Keming --- .github/workflows/rust.yml | 35 ++++++++++++----------------------- docker/pgrx.Dockerfile | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 23 deletions(-) create mode 100644 docker/pgrx.Dockerfile diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index fd2abe4..67c11cc 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -40,41 +40,30 @@ jobs: strategy: matrix: arch: ["x86_64", "aarch64"] + env: + PGRX_IMAGE: "kemingy/pgrx:0.12.6" steps: - uses: actions/checkout@v4 - - name: Set up Rust - uses: dtolnay/rust-toolchain@stable - - name: Set up dev environment - run: | - sudo apt-get remove -y '^postgres.*' '^libpq.*' '^clang.*' '^llvm.*' '^libclang.*' '^libllvm.*' '^mono-llvm.*' - sudo apt-get purge -y '^postgres.*' '^libpq.*' '^clang.*' '^llvm.*' '^libclang.*' '^libllvm.*' '^mono-llvm.*' - sudo apt-get update - sudo apt-get install -y build-essential crossbuild-essential-arm64 clang - sudo apt-get install -y libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt-dev libssl-dev libxml2-utils xsltproc ccache pkg-config - sudo apt-get install -y qemu-user-static - touch ~/.cargo/config.toml - 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 - rustup target add x86_64-unknown-linux-gnu - rustup target add aarch64-unknown-linux-gnu - name: Cache uses: mozilla-actions/sccache-action@v0.0.6 - - name: Set up pgrx + - name: Set up docker images and permissions run: | - cargo install cargo-pgrx --locked - cargo pgrx init + docker pull $PGRX_IMAGE + echo "Default user: $(id -u):$(id -g)" + sudo chown -R 1000:1000 . + - name: Clippy run: | - for v in {12..17}; do - cargo clippy --target ${{ matrix.arch }}-unknown-linux-gnu --features "pg$v" -- -D warnings + for v in {14..17}; do + docker run --rm -v .:/workspace $PGRX_IMAGE clippy --target ${{ matrix.arch }}-unknown-linux-gnu --features "pg$v" -- -D warnings done - name: Build run: | - for v in {12..17}; do - cargo build --lib --target ${{ matrix.arch }}-unknown-linux-gnu --features "pg$v" + for v in {14..17}; do + docker run --rm -v .:/workspace $PGRX_IMAGE build --lib --target ${{ matrix.arch }}-unknown-linux-gnu --features "pg$v" done - name: Test run: | # pg agnostic tests - cargo test --no-fail-fast --target $ARCH-unknown-linux-gnu --features pg17 + docker run --rm -v .:/workspace $PGRX_IMAGE test --no-fail-fast --target $ARCH-unknown-linux-gnu --features pg17 diff --git a/docker/pgrx.Dockerfile b/docker/pgrx.Dockerfile new file mode 100644 index 0000000..01bbc92 --- /dev/null +++ b/docker/pgrx.Dockerfile @@ -0,0 +1,34 @@ +FROM ubuntu:22.04 + +ARG PGRX_VERSION=0.12.6 +ARG RUSTC_WRAPPER=sccache + +ENV DEBIAN_FRONTEND=noninteractive \ + LANG=en_US.UTF-8 \ + LC_ALL=en_US.UTF-8 \ + RUSTC_WRAPPER=${RUSTC_WRAPPER} \ + RUSTFLAGS="-Dwarnings" + +RUN apt update && \ + apt install -y --no-install-recommends \ + curl \ + ca-certificates \ + build-essential \ + crossbuild-essential-arm64 \ + qemu-user-static \ + libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt-dev libssl-dev libxml2-utils xsltproc ccache pkg-config \ + clang && \ + rm -rf /var/lib/apt/lists/* + +USER ubuntu +ENV PATH="$PATH:/home/ubuntu/.cargo/bin" +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain=none -y + +WORKDIR /workspace +COPY rust-toolchain.toml /workspace/rust-toolchain.toml +RUN rustup target add x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu + +RUN cargo install cargo-pgrx --locked --version=${PGRX_VERSION} && \ + cargo pgrx init + +ENTRYPOINT [ "cargo" ]