Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: use prebuilt librocksdb in github actions #2316

Merged
merged 28 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6e95aa0
build(github): move all tests to free runners
lklimek Nov 6, 2024
ca00d6e
feat(github): action to install librocksdb
lklimek Nov 6, 2024
25abfd6
fix: add checkout
lklimek Nov 6, 2024
dafc311
fix: don't rebuild cache every time
lklimek Nov 6, 2024
9b093df
build(docker): Prebuild dependencies image
lklimek Nov 6, 2024
39eb45c
chore: fix docker caching job
lklimek Nov 6, 2024
249f8b5
fix(docker): rm fails
lklimek Nov 6, 2024
488a7ae
feat(github): use prebuilt rocksdb everywhere
lklimek Nov 6, 2024
8ccb067
chore: remove librocksdb from formatting step
lklimek Nov 6, 2024
e608408
build(docker): move tests to amd64
lklimek Nov 6, 2024
eafa040
build(docker): fix rocksdb build
lklimek Nov 6, 2024
98f0af6
Merge branch 'v1.6-dev' into build/optimize-memory
lklimek Nov 6, 2024
49ee181
Merge remote-tracking branch 'origin/build/optimize-memory' into buil…
lklimek Nov 6, 2024
9a57f6f
build: adjust -j flag
lklimek Nov 6, 2024
355e344
chore(github): remove docker-deps from tests.yml, we will trust layer…
lklimek Nov 6, 2024
0239693
build: add job to prebuild deps on push to master
lklimek Nov 6, 2024
0a73edc
chore: self-review
lklimek Nov 6, 2024
8318995
chore: librocksdb cached in s3 instead of gh cache
lklimek Nov 8, 2024
97bcd47
chore: rename rust-deps step
lklimek Nov 8, 2024
40e8ad5
chore: fix cache key
lklimek Nov 8, 2024
9b8e0c2
chore: remove weekly rebuild
lklimek Nov 8, 2024
d3b6c8a
Merge remote-tracking branch 'origin/v1.6-dev' into build/optimize-me…
lklimek Nov 8, 2024
fcd3d6a
chore: set aws region and secrets
lklimek Nov 8, 2024
169a655
chore: move docker changes to another pr
lklimek Nov 8, 2024
c939f44
chore: fix
lklimek Nov 8, 2024
dd18c7d
chore: rebuild cached deps
lklimek Nov 8, 2024
39e9c41
chore: switch to ubuntu 24.04
lklimek Nov 8, 2024
691afb2
chore: actions/checkout v4
lklimek Nov 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/actions/librocksdb/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
name: "librocksdb"
description: "Build and install librocksdb"
inputs:
runs-on:
description: Target platform
required: false
default: linux-24.04
lklimek marked this conversation as resolved.
Show resolved Hide resolved

version:
description: RocksDB version, eg. "8.10.2"
required: false
default: "8.10.2"
runs:
using: composite
steps:
- name: Load cached librocksdb
id: librocksdb-cache
uses: actions/cache@v3
with:
path: /opt/rocksdb
key: librocksdb-${{ runner.os }}-${{ inputs.version }}

- if: ${{ steps.librocksdb-cache.outputs.cache-hit != 'true' }}
shell: bash
name: Build librocksdb
run: |
set -ex
WORKDIR=/tmp/rocksdb-build
mkdir -p ${WORKDIR}/rocksdb
mkdir -p /opt/rocksdb/usr/local/lib/
pushd ${WORKDIR}/rocksdb

# building rocksdb
[[ -d .git ]] || git clone https://github.com/facebook/rocksdb.git -b v${{ inputs.version }} --depth 1 .
make -j$(nproc) static_lib
make DESTDIR=/opt/rocksdb install-static
set +x
lklimek marked this conversation as resolved.
Show resolved Hide resolved

echo Done.
echo Configuration:
echo
echo "ROCKSDB_STATIC='/opt/rocksdb/usr/local/lib/librocksdb.a'"
echo "ROCKSDB_LIB_DIR='/opt/rocksdb/usr/local/lib'"

popd
21 changes: 21 additions & 0 deletions .github/workflows/prebuild-deps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
## This workflow is used to prebuild and cache some dependencies for the build process.
name: Prebuild dependencies
on:
push:
branches:
- master
- build/optimize-memory # todo: remove this line before merging
schedule:
- cron: "30 4 * * 0"
jobs:
deps-rocksdb:
name: Prebuild and cache librocksdb
runs-on: ubuntu-24.04
steps:
- name: Checkout
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We must switch to AWS cache otherwise it's not going to work https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/caching-dependencies-to-speed-up-workflows#matching-a-cache-key

Another option is bring back build on merging PRs to default branch (or scheduled run). But it make sense only if we switch completely to default runners.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switched to s3

uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Precompile librocksdb
uses: ./.github/actions/librocksdb
5 changes: 3 additions & 2 deletions .github/workflows/tests-build-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ on:
jobs:
build-image:
name: Build ${{ inputs.name }} image
runs-on: ["self-hosted", "linux", "arm64", "ubuntu-platform"]
# runs-on: ["self-hosted", "linux", "arm64", "ubuntu-platform"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How much slower it become? If much slower then let's revert it for now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved docker to #2318

runs-on: ubuntu-24.04
steps:
- name: Check out repo
uses: actions/checkout@v4
Expand All @@ -41,7 +42,7 @@ jobs:
image_name: ${{ inputs.image_name }}
image_org: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com
target: ${{ inputs.target }}
platform: linux/arm64
platform: linux/amd64
push_tags: true
dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }}
dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN }}
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/tests-rs-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ jobs:
with:
components: clippy

- name: Install librocksdb
uses: ./.github/actions/librocksdb

- uses: clechasseur/rs-clippy-check@v3
with:
args: --package ${{ inputs.package }} --all-features --locked -- --no-deps
Expand All @@ -50,6 +53,8 @@ jobs:
SCCACHE_BUCKET: multi-runner-cache-x1xibo9c
SCCACHE_REGION: ${{ secrets.AWS_REGION }}
SCCACHE_S3_KEY_PREFIX: ${{ runner.os }}/sccache/${{ runner.arch }}/linux-gnu
ROCKSDB_STATIC: "/opt/rocksdb/usr/local/lib/librocksdb.a"
ROCKSDB_LIB_DIR: "/opt/rocksdb/usr/local/lib"

formatting:
name: Formatting
Expand All @@ -65,7 +70,14 @@ jobs:
components: rustfmt
cache: false

# This step doesn't need librocksdb, so we don't install it

- name: Check formatting
env:
RUSTC_WRAPPER: sccache
SCCACHE_BUCKET: multi-runner-cache-x1xibo9c
SCCACHE_REGION: ${{ secrets.AWS_REGION }}
SCCACHE_S3_KEY_PREFIX: ${{ runner.os }}/sccache/${{ runner.arch }}/linux-gnu
run: cargo fmt --check --package=${{ inputs.package }}

unused_deps:
Expand All @@ -89,6 +101,9 @@ jobs:
- name: Setup Rust
uses: ./.github/actions/rust

- name: Install librocksdb
uses: ./.github/actions/librocksdb

- name: Get crate ${{ inputs.package }} info
id: crate_info
uses: ./.github/actions/crate_info
Expand All @@ -102,6 +117,8 @@ jobs:
SCCACHE_BUCKET: multi-runner-cache-x1xibo9c
SCCACHE_REGION: ${{ secrets.AWS_REGION }}
SCCACHE_S3_KEY_PREFIX: ${{ runner.os }}/sccache/${{ runner.arch }}/linux-gnu
ROCKSDB_STATIC: "/opt/rocksdb/usr/local/lib/librocksdb.a"
ROCKSDB_LIB_DIR: "/opt/rocksdb/usr/local/lib"
with:
args: ${{ steps.crate_info.outputs.cargo_manifest_dir }}

Expand Down Expand Up @@ -184,13 +201,18 @@ jobs:
- name: Setup Rust
uses: ./.github/actions/rust

- name: Install librocksdb
uses: ./.github/actions/librocksdb

- name: Run tests
run: cargo test --package=${{ inputs.package }} --all-features --locked
env:
RUSTC_WRAPPER: sccache
SCCACHE_BUCKET: multi-runner-cache-x1xibo9c
SCCACHE_REGION: ${{ secrets.AWS_REGION }}
SCCACHE_S3_KEY_PREFIX: ${{ runner.os }}/sccache/${{ runner.arch }}/linux-gnu
ROCKSDB_STATIC: "/opt/rocksdb/usr/local/lib/librocksdb.a"
ROCKSDB_LIB_DIR: "/opt/rocksdb/usr/local/lib"

check_each_feature:
name: Check each feature
Expand All @@ -211,6 +233,9 @@ jobs:
- name: Setup Rust
uses: ./.github/actions/rust

- name: Install librocksdb
uses: ./.github/actions/librocksdb

- name: Get crate ${{ runner.arch }} info
id: crate_info
uses: ./.github/actions/crate_info
Expand All @@ -223,6 +248,8 @@ jobs:
SCCACHE_BUCKET: multi-runner-cache-x1xibo9c
SCCACHE_REGION: ${{ secrets.AWS_REGION }}
SCCACHE_S3_KEY_PREFIX: ${{ runner.os }}/sccache/${{ runner.arch }}/linux-gnu
ROCKSDB_STATIC: "/opt/rocksdb/usr/local/lib/librocksdb.a"
ROCKSDB_LIB_DIR: "/opt/rocksdb/usr/local/lib"
run: |
echo Verify all features disabled
set -ex
Expand Down
22 changes: 18 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ jobs:
changes:
name: Determine changed packages
if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || !github.event.pull_request.draft }}
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
lklimek marked this conversation as resolved.
Show resolved Hide resolved
outputs:
js-packages: ${{ steps.filter-js.outputs.changes }}
rs-packages: ${{ steps.filter-rs.outputs.changes }}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

Expand All @@ -42,6 +42,17 @@ jobs:
with:
filters: .github/package-filters/rs-packages.yml

rust-deps:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

build-rust-deps

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

name: Prebuild and cache some Rust dependencies
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Precompile librocksdb
uses: ./.github/actions/librocksdb

build-js:
name: Build JS packages
if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || !github.event.pull_request.draft }}
Expand Down Expand Up @@ -75,6 +86,7 @@ jobs:
name: Rust packages
needs:
- changes
- rust-deps
secrets: inherit
strategy:
fail-fast: false
Expand All @@ -85,9 +97,11 @@ jobs:
package: ${{ matrix.rs-package }}
# lint-runner: ${{ contains(fromJSON('["drive-abci", "drive"]'), matrix.rs-package) && '[ "self-hosted", "linux", "arm64", "ubuntu-platform" ]' || '"ubuntu-22.04"' }}
# FIXME: Clippy fails on github hosted runners, most likely due to RAM usage. Using self-hosted runners for now.
lint-runner: '[ "self-hosted", "linux", "arm64", "ubuntu-platform" ]'
# lint-runner: '[ "self-hosted", "linux", "arm64", "ubuntu-platform" ]'
lint-runner: '["ubuntu-24.04"]'
# Run drive tests on self-hosted 4x
test-runner: '[ "self-hosted", "linux", "arm64", "ubuntu-platform" ]'
# test-runner: '[ "self-hosted", "linux", "arm64", "ubuntu-platform" ]'
test-runner: '["ubuntu-24.04"]'
check-each-feature: ${{ contains(fromJSON('["dash-sdk","rs-dapi-client","dapi-grpc","dpp","drive-abci"]'), matrix.rs-package) }}

rs-crates-security:
Expand Down
35 changes: 34 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,20 @@ ARG AWS_ACCESS_KEY_ID
ARG AWS_SECRET_ACCESS_KEY

#
# BUILD ROCKSDB STATIC LIBRARY
#
FROM deps-${RUSTC_WRAPPER:-base} AS rocksdb

RUN mkdir -p /tmp/rocksdb
WORKDIR /tmp/rocksdb
RUN git clone https://github.com/facebook/rocksdb.git -b v8.10.2 --depth 1 . && \
make -j$(nproc) static_lib && \
mkdir -p /opt/rocksdb/usr/local/lib && \
cp librocksdb.a /opt/rocksdb/usr/local/lib/ && \
cp -r include /opt/rocksdb/usr/local/lib/ && \
cd / && \
rm -rf /tmp/rocksdb

# DEPS: FULL DEPENDENCIES LIST
#
# This is separate from `deps` to use sccache for caching
Expand All @@ -154,6 +168,14 @@ FROM deps-${RUSTC_WRAPPER:-base} AS deps
ARG SCCACHE_S3_KEY_PREFIX
ENV SCCACHE_S3_KEY_PREFIX=${SCCACHE_S3_KEY_PREFIX}/${TARGETARCH}/linux-musl

# Install prebuilt rocksdb library

COPY --from=rocksdb /opt/rocksdb /opt/rocksdb
# Set env variables so that Rust's rocksdb-sys will not build rocksdb from scratch

ENV ROCKSDB_STATIC=/opt/rocksdb/usr/local/lib/librocksdb.a
ENV ROCKSDB_LIB_DIR=/opt/rocksdb/usr/local/lib

WORKDIR /platform

# Install wasm-bindgen-cli in the same profile as other components, to sacrifice some performance & disk space to gain
Expand All @@ -171,12 +193,17 @@ RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOM
# Meanwhile if you want to update wasm-bindgen you also need to update version in:
# - packages/wasm-dpp/Cargo.toml
# - packages/wasm-dpp/scripts/build-wasm.sh
cargo install --profile "$CARGO_BUILD_PROFILE" [email protected] [email protected] --locked
cargo install --profile "$CARGO_BUILD_PROFILE" [email protected] [email protected] --locked


#
# Rust build planner to speed up builds
#
FROM deps AS build-planner

ENV ROCKSDB_STATIC=/opt/rocksdb/usr/local/lib/librocksdb.a
ENV ROCKSDB_LIB_DIR=/opt/rocksdb/usr/local/lib

WORKDIR /platform
COPY . .
RUN source $HOME/.cargo/env && \
Expand All @@ -196,6 +223,9 @@ SHELL ["/bin/bash", "-o", "pipefail","-e", "-x", "-c"]
ARG SCCACHE_S3_KEY_PREFIX
ENV SCCACHE_S3_KEY_PREFIX=${SCCACHE_S3_KEY_PREFIX}/${TARGETARCH}/linux-musl

ENV ROCKSDB_STATIC=/opt/rocksdb/usr/local/lib/librocksdb.a
ENV ROCKSDB_LIB_DIR=/opt/rocksdb/usr/local/lib

WORKDIR /platform

COPY --from=build-planner /platform/recipe.json recipe.json
Expand Down Expand Up @@ -251,6 +281,9 @@ FROM deps AS build-js
ARG SCCACHE_S3_KEY_PREFIX
ENV SCCACHE_S3_KEY_PREFIX=${SCCACHE_S3_KEY_PREFIX}/wasm/wasm32

ENV ROCKSDB_STATIC=/opt/rocksdb/usr/local/lib/librocksdb.a
ENV ROCKSDB_LIB_DIR=/opt/rocksdb/usr/local/lib

WORKDIR /platform

COPY --from=build-planner /platform/recipe.json recipe.json
Expand Down
Loading