Skip to content

Commit

Permalink
feat(mem-analysis): Adding Dockerfile_with_heaptrack (#1681)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
Ivansete-status and Lorenzo Delgado authored Apr 25, 2023
1 parent c8081c8 commit 9b9172a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
36 changes: 33 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 -------------------------------------------------------------
Expand Down Expand Up @@ -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"]
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ##
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit 9b9172a

Please sign in to comment.