Skip to content

Commit

Permalink
Compile on host and copy the release-with-debug to container during b…
Browse files Browse the repository at this point in the history
…uild

This is so as to avoid OOM during builds on MacOS.
  • Loading branch information
gruuya committed Nov 6, 2024
1 parent adbdf16 commit 1e7753a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,5 @@ strip = true

[profile.release-with-debug]
debug = true
inherits = "release"
strip = false
inherits = "release"
39 changes: 10 additions & 29 deletions profile/Dockerfile.profile
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
16 changes: 10 additions & 6 deletions profile/justfile
Original file line number Diff line number Diff line change
@@ -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_*

0 comments on commit 1e7753a

Please sign in to comment.