From 91885fb9e4ab51f29109294bb9a1b4b14923b235 Mon Sep 17 00:00:00 2001 From: NagyZoltanPeter <113987313+NagyZoltanPeter@users.noreply.github.com> Date: Wed, 28 May 2025 19:07:07 +0200 Subject: [PATCH] chore: heaptrack support build for Nim v2.0.12 builds (#3424) * fix heaptrack build for Nim v2.0.12 builds, fixed docker image creation and local image with copying * fix Dockerfile.bn.amd64 to support nwaku-compose * Fix heaptrack image build with jenkins.release * Fix NIM_COMMIT for heaptrack support in jenkins.release * Remove leftover echo Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix dockerfile naming * Fix assignment of NIM_COMMIT in Makefile --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- Dockerfile | 2 +- Makefile | 12 ++++-- ci/Jenkinsfile.release | 38 ++++++++++++----- docker/binaries/Dockerfile.bn.amd64 | 2 +- docker/binaries/Dockerfile.bn.local | 63 +++++++++++++++++++++++++++++ 5 files changed, 100 insertions(+), 17 deletions(-) create mode 100644 docker/binaries/Dockerfile.bn.local diff --git a/Dockerfile b/Dockerfile index 8a1a743c9..b1f6b3c6a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -78,7 +78,7 @@ RUN make -j$(nproc) # Debug image -FROM prod AS debug +FROM prod AS debug-with-heaptrack RUN apk add --no-cache gdb libunwind diff --git a/Makefile b/Makefile index d15668673..ae57852a5 100644 --- a/Makefile +++ b/Makefile @@ -82,15 +82,18 @@ HEAPTRACKER ?= 0 HEAPTRACKER_INJECT ?= 0 ifeq ($(HEAPTRACKER), 1) # Needed to make nimbus-build-system use the Nim's 'heaptrack_support' branch -DOCKER_NIM_COMMIT := NIM_COMMIT=heaptrack_support -TARGET := heaptrack-build +DOCKER_NIM_COMMIT := NIM_COMMIT=heaptrack_support_v2.0.12 +TARGET := debug-with-heaptrack +NIM_COMMIT := heaptrack_support_v2.0.12 ifeq ($(HEAPTRACKER_INJECT), 1) # the Nim compiler will load 'libheaptrack_inject.so' HEAPTRACK_PARAMS := -d:heaptracker -d:heaptracker_inject +NIM_PARAMS := $(NIM_PARAMS) -d:heaptracker -d:heaptracker_inject else # the Nim compiler will load 'libheaptrack_preload.so' HEAPTRACK_PARAMS := -d:heaptracker +NIM_PARAMS := $(NIM_PARAMS) -d:heaptracker endif endif @@ -209,6 +212,7 @@ testwaku: | build deps anvil librln wakunode2: | build deps librln echo -e $(BUILD_MSG) "build/$@" && \ + \ $(ENV_SCRIPT) nim wakunode2 $(NIM_PARAMS) waku.nims benchmarks: | build deps librln @@ -343,12 +347,12 @@ docker-image: docker-quick-image: MAKE_TARGET ?= wakunode2 docker-quick-image: DOCKER_IMAGE_TAG ?= $(MAKE_TARGET)-$(GIT_VERSION) docker-quick-image: DOCKER_IMAGE_NAME ?= wakuorg/nwaku:$(DOCKER_IMAGE_TAG) -docker-quick-image: NIM_PARAMS := $(NIM_PARAMS) -d:chronicles_colors:none -d:insecure -d:postgres --passL:$(LIBRLN_FILE) --passL:-lm docker-quick-image: | build deps librln wakunode2 docker build \ --build-arg="MAKE_TARGET=$(MAKE_TARGET)" \ --tag $(DOCKER_IMAGE_NAME) \ - --file docker/binaries/Dockerfile.bn.amd64 \ + --target $(TARGET) \ + --file docker/binaries/Dockerfile.bn.local \ . docker-push: diff --git a/ci/Jenkinsfile.release b/ci/Jenkinsfile.release index 1a2125402..5d18d32aa 100644 --- a/ci/Jenkinsfile.release +++ b/ci/Jenkinsfile.release @@ -69,17 +69,33 @@ pipeline { stages { stage('Build') { steps { script { - image = docker.build( - "${params.IMAGE_NAME}:${params.IMAGE_TAG ?: env.GIT_COMMIT.take(8)}", - "--label=build='${env.BUILD_URL}' " + - "--label=commit='${git.commit()}' " + - "--label=version='${git.describe('--tags')}' " + - "--build-arg=MAKE_TARGET='${params.MAKE_TARGET}' " + - "--build-arg=NIMFLAGS='${params.NIMFLAGS} -d:postgres ' " + - "--build-arg=LOG_LEVEL='${params.LOWEST_LOG_LEVEL_ALLOWED}' " + - "--build-arg=DEBUG='${params.DEBUG ? "1" : "0"} ' " + - "--target=${params.HEAPTRACK ? "heaptrack-build" : "prod"} ." - ) + if (params.HEAPTRACK) { + echo 'Building with heaptrack support' + image = docker.build( + "${params.IMAGE_NAME}:${params.IMAGE_TAG ?: env.GIT_COMMIT.take(8)}", + "--label=build='${env.BUILD_URL}' " + + "--label=commit='${git.commit()}' " + + "--label=version='${git.describe('--tags')}' " + + "--build-arg=MAKE_TARGET='${params.MAKE_TARGET}' " + + "--build-arg=NIMFLAGS='${params.NIMFLAGS} -d:postgres -d:heaptracker ' " + + "--build-arg=LOG_LEVEL='${params.LOWEST_LOG_LEVEL_ALLOWED}' " + + "--build-arg=DEBUG='${params.DEBUG ? "1" : "0"} ' " + + "--build-arg=NIM_COMMIT='NIM_COMMIT=heaptrack_support_v2.0.12' " + + "--target='debug-with-heaptrack' ." + ) + } else { + image = docker.build( + "${params.IMAGE_NAME}:${params.IMAGE_TAG ?: env.GIT_COMMIT.take(8)}", + "--label=build='${env.BUILD_URL}' " + + "--label=commit='${git.commit()}' " + + "--label=version='${git.describe('--tags')}' " + + "--build-arg=MAKE_TARGET='${params.MAKE_TARGET}' " + + "--build-arg=NIMFLAGS='${params.NIMFLAGS} -d:postgres ' " + + "--build-arg=LOG_LEVEL='${params.LOWEST_LOG_LEVEL_ALLOWED}' " + + "--build-arg=DEBUG='${params.DEBUG ? "1" : "0"} ' " + + "--target='prod' ." + ) + } } } } diff --git a/docker/binaries/Dockerfile.bn.amd64 b/docker/binaries/Dockerfile.bn.amd64 index d32cf9342..c8dc0ffeb 100644 --- a/docker/binaries/Dockerfile.bn.amd64 +++ b/docker/binaries/Dockerfile.bn.amd64 @@ -13,7 +13,7 @@ EXPOSE 30303 60000 8545 # Referenced in the binary RUN apt-get update &&\ - apt-get install -y libpcre3 libpq-dev curl iproute2 wget &&\ + apt-get install -y libpcre3 libpq-dev curl iproute2 wget dnsutils &&\ apt-get clean && rm -rf /var/lib/apt/lists/* # Fix for 'Error loading shared library libpcre.so.3: No such file or directory' diff --git a/docker/binaries/Dockerfile.bn.local b/docker/binaries/Dockerfile.bn.local new file mode 100644 index 000000000..79445d14f --- /dev/null +++ b/docker/binaries/Dockerfile.bn.local @@ -0,0 +1,63 @@ +# Dockerfile to build a distributable container image from pre-existing binaries +# FROM debian:stable-slim AS prod +FROM ubuntu:24.04 AS prod + +ARG MAKE_TARGET=wakunode2 + +LABEL maintainer="vaclav@status.im" +LABEL source="https://github.com/waku-org/nwaku" +LABEL description="Wakunode: Waku client" +LABEL commit="unknown" + +# DevP2P, LibP2P, and JSON RPC ports +EXPOSE 30303 60000 8545 + +# Referenced in the binary +RUN apt-get update &&\ + apt-get install -y libpcre3 libpq-dev curl iproute2 wget jq dnsutils &&\ + apt-get clean && rm -rf /var/lib/apt/lists/* + +# Fix for 'Error loading shared library libpcre.so.3: No such file or directory' +RUN ln -s /usr/lib/libpcre.so /usr/lib/libpcre.so.3 + +# Copy to separate location to accomodate different MAKE_TARGET values +ADD ./build/$MAKE_TARGET /usr/local/bin/ + +# Copy migration scripts for DB upgrades +ADD ./migrations/ /app/migrations/ + +# Symlink the correct wakunode binary +RUN ln -sv /usr/local/bin/$MAKE_TARGET /usr/bin/wakunode + +ENTRYPOINT ["/usr/bin/wakunode"] + +# By default just show help if called without arguments +CMD ["--help"] + +# Build debug tools: heaptrack +FROM ubuntu:24.04 AS heaptrack-build + +RUN apt update +RUN apt install -y gdb git g++ make cmake zlib1g-dev libboost-all-dev libunwind-dev +RUN git clone https://github.com/KDE/heaptrack.git /heaptrack + +WORKDIR /heaptrack/build +# going to a commit that builds properly. We will revisit this for new releases +RUN git reset --hard f9cc35ebbdde92a292fe3870fe011ad2874da0ca +RUN cmake -DCMAKE_BUILD_TYPE=Release .. +RUN make -j$(nproc) + + +# Debug image +FROM prod AS debug-with-heaptrack + +RUN apt update +RUN apt install -y gdb libunwind8 + +# Add heaptrack +COPY --from=heaptrack-build /heaptrack/build/ /heaptrack/build/ + +ENV LD_LIBRARY_PATH=/heaptrack/build/lib/heaptrack/ +RUN ln -s /heaptrack/build/bin/heaptrack /usr/local/bin/heaptrack + +ENTRYPOINT ["/heaptrack/build/bin/heaptrack", "/usr/bin/wakunode"]