From 1e7753aa689a45d214d56d48976d500d0ce15684 Mon Sep 17 00:00:00 2001 From: Marko Grujic Date: Wed, 6 Nov 2024 12:33:11 +0100 Subject: [PATCH] Compile on host and copy the release-with-debug to container during build This is so as to avoid OOM during builds on MacOS. --- Cargo.toml | 2 +- profile/Dockerfile.profile | 39 ++++++++++---------------------------- profile/justfile | 16 ++++++++++------ 3 files changed, 21 insertions(+), 36 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2bb728df..11fff04a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -166,5 +166,5 @@ strip = true [profile.release-with-debug] debug = true -inherits = "release" strip = false +inherits = "release" diff --git a/profile/Dockerfile.profile b/profile/Dockerfile.profile index 952f0214..7a8982a1 100644 --- a/profile/Dockerfile.profile +++ b/profile/Dockerfile.profile @@ -2,46 +2,27 @@ # memory allocations for profiling # # To build run just the bytehound layer run -# docker build --target bytehound -f Dockerfile.profile -t splitgraph/bytehound . +# DOCKER_BUILDKIT=1 docker build --target bytehound -f Dockerfile.profile -t splitgraph/bytehound . # # To build the full image run -# docker build -f Dockerfile.profile -t splitgraph/seafowl:profile .. +# DOCKER_BUILDKIT=1 docker build -f Dockerfile.profile -t splitgraph/seafowl:profile .. FROM rust:slim AS bytehound RUN apt-get update && \ apt-get install -y git protobuf-compiler ca-certificates npm && \ - npm install -g yarn - -# Fetch bytehound source and compile -RUN git clone https://github.com/koute/bytehound.git && \ + npm install -g yarn && \ + git clone https://github.com/koute/bytehound.git && \ cd bytehound && \ cargo build --release -p bytehound-preload && \ cargo build --release -p bytehound-cli -FROM bytehound AS profile - -RUN rustup default nightly-2024-10-30 - -# Compile an empty project, so as to cache the compiled deps and avoid unneeded re-compilation. -# Adapted from https://gist.github.com/noelbundick/6922d26667616e2ba5c3aff59f0824cd -RUN cargo new seafowl -WORKDIR seafowl -COPY Cargo.toml Cargo.lock build.rs . -COPY clade clade -COPY datafusion_remote_tables datafusion_remote_tables -COPY migrations migrations -COPY object_store_factory object_store_factory -RUN --mount=type=cache,target=/usr/local/cargo/registry cargo build --profile release-with-debug - -# Copy the rest of the code now and update timestamps to force a new build only for it -COPY src src -RUN --mount=type=cache,target=/usr/local/cargo/registry set -e && \ - touch src/lib.rs src/main.rs && \ - cargo build --profile release-with-debug +FROM ubuntu AS profile -RUN cd .. && mkdir seafowl-data +RUN mkdir profiles && mkdir seafowl-data +COPY target/aarch64-unknown-linux-gnu/release-with-debug/seafowl seafowl +COPY --from=bytehound /bytehound/target/release/libbytehound.so libbytehound.so ENV MEMORY_PROFILER_OUTPUT=profiles/memory-profiling_%e_%t_%p.dat -ENV LD_PRELOAD=/bytehound/target/release/libbytehound.so -ENTRYPOINT [ "./target/release-with-debug/seafowl" ] +ENV LD_PRELOAD=./libbytehound.so +ENTRYPOINT [ "./seafowl" ] diff --git a/profile/justfile b/profile/justfile index 3b8953a7..869d33bd 100644 --- a/profile/justfile +++ b/profile/justfile @@ -1,19 +1,23 @@ build-bytehound: - docker build --target bytehound -f Dockerfile.profile -t splitgraph/bytehound . + DOCKER_BUILDKIT=1 docker build --target bytehound -f Dockerfile.profile -t splitgraph/bytehound . +# TODO: generailze to support amd64 build-profiler: - docker build -f Dockerfile.profile -t splitgraph/seafowl:profile .. + CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc + cargo build --target aarch64-unknown-linux-gnu --profile release-with-debug + DOCKER_BUILDKIT=1 docker build -f Dockerfile.profile -t splitgraph/seafowl:profile .. profile: docker run \ -p 8080:8080 -p 47470:47470 \ - -v .:/seafowl/profiles \ + -v .:/profiles \ -v `realpath ../seafowl.toml`:/seafowl.toml \ + -v `realpath ../../seafowl-data`:/seafowl-data \ splitgraph/seafowl:profile -c /seafowl.toml -view: - docker run -p 8888:8888 -v .:/profiles -w /profiles splitgraph/bytehound \ - /bytehound/target/release/bytehound server -i 0.0.0.0 -p 8888 memory-profiling_* +view *files='memory-profiling_*': + docker run -p 9999:9999 -v .:/profiles -w /profiles \splitgraph/bytehound \ + /bytehound/target/release/bytehound server -i 0.0.0.0 -p 9999 {{files}} clean: rm -rf memory-profiling_*