From fa142ceaab9e79fcf836e3c5b99f035f6c3631d1 Mon Sep 17 00:00:00 2001 From: Felipe Lima Date: Thu, 5 Dec 2024 21:34:27 -0800 Subject: [PATCH] chore: Add Dockerfile and instructions for building ruby gem locally --- ruby-sdk/Cargo.lock | 42 ++++++++++++++++++----------- ruby-sdk/Dockerfile | 30 +++++++++++++++++++++ ruby-sdk/README.md | 12 +++++++++ ruby-sdk/build.sh | 11 ++++++++ ruby-sdk/ext/eppo_client/Cargo.toml | 2 +- 5 files changed, 80 insertions(+), 17 deletions(-) create mode 100644 ruby-sdk/Dockerfile create mode 100644 ruby-sdk/build.sh diff --git a/ruby-sdk/Cargo.lock b/ruby-sdk/Cargo.lock index 011fe2e2..4e5d6700 100644 --- a/ruby-sdk/Cargo.lock +++ b/ruby-sdk/Cargo.lock @@ -223,6 +223,12 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + [[package]] name = "core-foundation" version = "0.9.4" @@ -241,21 +247,14 @@ checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "derive_more" -version = "1.0.0" +version = "0.99.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a9b99b9cbbe49445b21764dc0625032a89b145a2642e67603e1c936f5458d05" -dependencies = [ - "derive_more-impl", -] - -[[package]] -name = "derive_more-impl" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" dependencies = [ + "convert_case", "proc-macro2", "quote", + "rustc_version", "syn", ] @@ -310,7 +309,7 @@ dependencies = [ [[package]] name = "eppo_client" -version = "3.3.0" +version = "3.3.1" dependencies = [ "env_logger", "eppo_core", @@ -325,6 +324,8 @@ dependencies = [ [[package]] name = "eppo_core" version = "4.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f847d078c379d2102582e483751dd1a4444fd3e1863e6f23e852fc99c52270e6" dependencies = [ "chrono", "derive_more", @@ -1261,6 +1262,15 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + [[package]] name = "rustix" version = "0.38.41" @@ -1642,18 +1652,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.3" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c006c85c7651b3cf2ada4584faa36773bd07bac24acfb39f3c431b36d7e667aa" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "2.0.3" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f077553d607adc1caf65430528a576c757a71ed73944b66ebb58ef2bbd243568" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", diff --git a/ruby-sdk/Dockerfile b/ruby-sdk/Dockerfile new file mode 100644 index 00000000..e72c1c9b --- /dev/null +++ b/ruby-sdk/Dockerfile @@ -0,0 +1,30 @@ +FROM ruby:3.3 + +ARG WORKDIR + +RUN apt-get update && apt-get install -y \ + curl \ + build-essential \ + libssl-dev \ + zlib1g-dev \ + && apt-get clean && rm -rf /var/lib/apt/lists/* + +RUN apt-get install ca-certificates curl +RUN install -m 0755 -d /etc/apt/keyrings +RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc +RUN chmod a+r /etc/apt/keyrings/docker.asc + +RUN echo \ + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \ + $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ + tee /etc/apt/sources.list.d/docker.list > /dev/null +RUN apt-get update +RUN apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin + +WORKDIR $WORKDIR + +RUN gem install rb_sys + +COPY build.sh ./ + +CMD ["/bin/bash", "./build.sh"] diff --git a/ruby-sdk/README.md b/ruby-sdk/README.md index 26245007..ec16b76f 100644 --- a/ruby-sdk/README.md +++ b/ruby-sdk/README.md @@ -43,3 +43,15 @@ Make sure you remove the override before updating `Cargo.lock`. Otherwise, the l * Bump versions in `ruby-sdk/lib/eppo_client/version.rb` and `ruby-sdk/ext/eppo_client/Cargo.toml` * Run `cargo update --workspace --verbose` to update `Cargo.lock` * Run `bundle` to update `Gemfile.lock` + + +## Building native libs + +``` +docker build --build-arg WORKDIR=$(pwd) -t ruby-sdk-builder . +mkdir -p rust/cargo/registry +docker run --rm -it \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v /tmp:/tmp -v \ + $(pwd)/rust:$(pwd)/rust ruby-sdk-builder +``` diff --git a/ruby-sdk/build.sh b/ruby-sdk/build.sh new file mode 100644 index 00000000..d9780e12 --- /dev/null +++ b/ruby-sdk/build.sh @@ -0,0 +1,11 @@ +set -e +export RUST_INSTALL_PATH=./rust +mkdir -p $RUST_INSTALL_PATH +export RUSTUP_HOME=$RUST_INSTALL_PATH/rustup +export CARGO_HOME=$RUST_INSTALL_PATH/cargo +export PATH=$CARGO_HOME/bin:$PATH +export RB_SYS_DOCK_CACHE_DIR=./cache +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y +rustup install stable +rustup default stable +rb-sys-dock --platform aarch64-linux-musl --mount-toolchains --ruby-versions 3.3 -V --build -V diff --git a/ruby-sdk/ext/eppo_client/Cargo.toml b/ruby-sdk/ext/eppo_client/Cargo.toml index 00115744..78dde360 100644 --- a/ruby-sdk/ext/eppo_client/Cargo.toml +++ b/ruby-sdk/ext/eppo_client/Cargo.toml @@ -12,7 +12,7 @@ crate-type = ["cdylib"] [dependencies] env_logger = { version = "0.11.3", features = ["unstable-kv"] } -eppo_core = { version = "=5.0.0", features = ["vendored"] } +eppo_core = { version = "=4.1.1", features = ["vendored"] } log = { version = "0.4.21", features = ["kv_serde"] } magnus = { version = "0.6.4" } serde = { version = "1.0.203", features = ["derive"] }