Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Reduce the size of tracer-node docker image
Browse files Browse the repository at this point in the history
Introduce two-stage build of the tracer-node docker image. That
significantly reduces the image size.

Signed-off-by: Tzvetomir Stoyanov (VMware) <[email protected]>
  • Loading branch information
tzstoyanov committed Feb 5, 2023
1 parent bf7022b commit 64f3f37
Showing 1 changed file with 47 additions and 28 deletions.
75 changes: 47 additions & 28 deletions cmd/tracer-node/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,47 +1,66 @@
# SPDX-License-Identifier: GPL-2.0-or-later
#
# Copyright 2022 VMware Inc, June Knauth (VMware) <[email protected]>
# Copyright 2023 VMware, Inc. Tzvetomir Stoyanov (VMware) <[email protected]>

FROM golang:1.18-bullseye as build

FROM golang:1.18-bullseye
# Install APT and pip dependencies
RUN apt update \
&& apt install build-essential git cmake \
libjson-c-dev libpython3-dev cython3 \
python3-numpy python3-pip flex valgrind \
binutils-dev libzstd-dev libaudit-dev pkg-config \
swig curl -y \
&& pip3 install pkgconfig GitPython
# Download the git-snapshot tool from the trace-cruncher GitHub and
# use it to download a snapshot of trace-cruncher dependencies (defined in repos)
&& pip3 install pkgconfig GitPython

WORKDIR /tracer
COPY . ./
RUN make tracer

WORKDIR /build
ARG TRACE_CRUNCER_URL=https://github.com/vmware/trace-cruncher
ARG TRACE_CRUNCER_VER=tracecruncher
RUN git clone ${TRACE_CRUNCER_URL} --branch ${TRACE_CRUNCER_VER} \
&& cp ./trace-cruncher/scripts/git-snapshot/* . && bash ./git-snapshot.sh -f ./repos

RUN cd libtraceevent && make && make install \
&& cd ../libtracefs && make && make install \
&& cd ../trace-cmd && make && make install_libs \
&& cd ../kernel-shark/build && cmake .. && make && make install \
&& cd ../../trace-cruncher && make

####

FROM debian:stable-slim

# Install APT and pip dependencies
RUN apt update \
&& apt install make cmake \
libjson-c-dev cython3 libzstd-dev \
python3-numpy python3-pip \
pkg-config -y \
&& pip3 install pkgconfig GitPython

WORKDIR /build
RUN git clone ${TRACE_CRUNCER_URL} --branch ${TRACE_CRUNCER_VER}
RUN cp ./trace-cruncher/scripts/git-snapshot/* . && bash ./git-snapshot.sh -f ./repos

# Build kernel tracing libs
RUN cd libtraceevent && make && make install
RUN cd libtracefs && make && make install
RUN cd trace-cmd && make && make install_libs
RUN cd kernel-shark/build && cmake .. && make && make install
# Install trace-cruncher
RUN cd trace-cruncher && make && make install

WORKDIR container-tracer
COPY . ./
RUN make tracer
COPY --from=build /build .

WORKDIR /tracer
COPY trace-hooks trace-hooks
RUN cp /build/container-tracer/cmd/tracer-node/tracer-node .
RUN cd libtraceevent && make -t && make install \
&& cd ../libtracefs && make -t && make install \
&& cd ../trace-cmd && make -t && make install_libs \
&& cd ../kernel-shark/build && make -t && make install \
&& cd ../../trace-cruncher && make -t && make install

WORKDIR /tracer
# Remove build dependencies; run build with --squash to reduce image size
RUN rm -rf /build /root/go /go /usr/local/go /root/.cache/*
RUN pip3 uninstall pkgconfig -y \
&& apt remove build-essential git cmake python3-pip libpython3-dev flex valgrind \
binutils-dev libzstd-dev libaudit-dev pkg-config swig curl -y \
&& apt autoremove -y
&& apt remove make cmake libzstd-dev \
pkg-config -y \
&& apt remove python3-pip -y \
&& apt autoremove -y \
&& rm -rf /build /root/.cache/*

COPY --from=build /tracer/cmd/tracer-node/tracer-node .
COPY --from=build /tracer/trace-hooks .

EXPOSE 8080/tcp
WORKDIR /tracer
ENTRYPOINT ["./tracer-node"]

0 comments on commit 64f3f37

Please sign in to comment.