From 9b9172ab82d5693895cfdcdd66d9ad15e02d7c6a Mon Sep 17 00:00:00 2001 From: Ivan Folgueira Bande <128452529+Ivansete-status@users.noreply.github.com> Date: Tue, 25 Apr 2023 17:54:28 +0200 Subject: [PATCH] feat(mem-analysis): Adding Dockerfile_with_heaptrack (#1681) * Adding Dockerfile_with_heaptrack * build: merge heaptrack dockerfile with production dockerfile (#1682) * Avoid blindly copy /usr/lib/ and install only the needed libraries * Adding heaptracker options in the Makefile * Dockerfile simplification. (apk add libunwind) * Dockerfile, Makefile: ++heaptrack params to nim build & 'heaptrack_support' in Nim compiler * Dockerfile, Makefile: more convenient name for 'NIM_COMMIT' Docker arg * Making 'NIM_COMMIT' more explicit --------- Co-authored-by: Lorenzo Delgado --- Dockerfile | 36 +++++++++++++++++++++++++++++++++--- Makefile | 23 +++++++++++++++++++++++ 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index e4456cd533..6e8d86257f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,11 @@ -# BUILD IMAGE ------------------------------------------------------------------ +# BUILD NIM APP ---------------------------------------------------------------- FROM alpine:edge AS nim-build ARG NIMFLAGS ARG MAKE_TARGET=wakunode2 ARG EXPERIMENTAL=false +ARG NIM_COMMIT # Get build tools and required header files RUN apk add --no-cache bash git cargo build-base pcre-dev linux-headers @@ -16,10 +17,10 @@ COPY . . RUN git submodule update --init --recursive # Slowest build step for the sake of caching layers -RUN make -j$(nproc) deps +RUN make -j$(nproc) deps ${NIM_COMMIT} # Build the final node binary -RUN make -j$(nproc) $MAKE_TARGET NIMFLAGS="${NIMFLAGS}" EXPERIMENTAL="${EXPERIMENTAL}" +RUN make -j$(nproc) ${NIM_COMMIT} $MAKE_TARGET NIMFLAGS="${NIMFLAGS}" EXPERIMENTAL="${EXPERIMENTAL}" # PRODUCTION IMAGE ------------------------------------------------------------- @@ -52,5 +53,34 @@ COPY --from=nim-build /app/migrations/ /app/migrations/ 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"] + + +# DEBUG IMAGE ------------------------------------------------------------------ + +# Build debug tools: heaptrack +FROM alpine:edge AS heaptrack-build + +RUN apk update +RUN apk add -- gdb git g++ make cmake zlib-dev boost-dev libunwind-dev +RUN git clone https://github.com/KDE/heaptrack.git /heaptrack + +WORKDIR /heaptrack/build +RUN cmake -DCMAKE_BUILD_TYPE=Release .. +RUN make -j$(nproc) + + +# Debug image +FROM prod AS debug + +RUN apk add --no-cache gdb libunwind + +# 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"] diff --git a/Makefile b/Makefile index 98220e53c6..ef82e1ed85 100644 --- a/Makefile +++ b/Makefile @@ -56,11 +56,31 @@ clean: # must be included after the default target -include $(BUILD_SYSTEM_DIR)/makefiles/targets.mk +## Possible values: prod; debug +TARGET ?= prod ## Git version GIT_VERSION ?= $(shell git describe --abbrev=6 --always --tags) NIM_PARAMS := $(NIM_PARAMS) -d:git_version=\"$(GIT_VERSION)\" +## Heaptracker options +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 := debug + +ifeq ($(HEAPTRACKER_INJECT), 1) +# the Nim compiler will load 'libheaptrack_inject.so' +HEAPTRACK_PARAMS := -d:heaptracker -d:heaptracker_inject +else +# the Nim compiler will load 'libheaptrack_preload.so' +HEAPTRACK_PARAMS := -d:heaptracker +endif + +endif +## end of Heaptracker options ################## ## Dependencies ## @@ -250,6 +270,7 @@ docs: | build deps # -d:insecure - Necessary to enable Prometheus HTTP endpoint for metrics # -d:chronicles_colors:none - Necessary to disable colors in logs for Docker DOCKER_IMAGE_NIMFLAGS ?= -d:chronicles_colors:none -d:insecure +DOCKER_IMAGE_NIMFLAGS := $(DOCKER_IMAGE_NIMFLAGS) $(HEAPTRACK_PARAMS) # build a docker image for the fleet docker-image: MAKE_TARGET ?= wakunode2 @@ -260,7 +281,9 @@ docker-image: --build-arg="MAKE_TARGET=$(MAKE_TARGET)" \ --build-arg="NIMFLAGS=$(DOCKER_IMAGE_NIMFLAGS)" \ --build-arg="EXPERIMENTAL=$(EXPERIMENTAL)" \ + --build-arg="NIM_COMMIT=$(DOCKER_NIM_COMMIT)" \ --label="commit=$(GIT_VERSION)" \ + --target $(TARGET) \ --tag $(DOCKER_IMAGE_NAME) . docker-push: