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 <lorenzo@status.im>
This commit is contained in:
Ivan Folgueira Bande 2023-04-25 17:54:28 +02:00 committed by GitHub
parent c8081c8859
commit 9b9172ab82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 3 deletions

View File

@ -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"]

View File

@ -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: