Skip to content

Commit

Permalink
Completes port of collector image to RHEL UBI8; fixes and improves bu…
Browse files Browse the repository at this point in the history
…ild for modules and collector; added hooks for multi-stage builds with intermediate stage caching; Closes sysflow-telemetry/sysflow#20
  • Loading branch information
araujof committed Feb 4, 2020
1 parent fa3f34a commit d9c260e
Show file tree
Hide file tree
Showing 10 changed files with 231 additions and 100 deletions.
130 changes: 83 additions & 47 deletions Dockerfile.collector.amd64
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,48 @@
# See the License for the specific language governing permissions and
# limitations under the License.

ARG TAG=latest

#-----------------------
# Stage: builder
#-----------------------
FROM sfcollector-ubi:latest AS builder
FROM sysflowtelemetry/sf-collector:${TAG}-mods AS builder

ENV LIBRARY_PATH=/lib64
ARG gllogtostderr=1
ENV GLOG_logtostderr=$gllogtostderr
# environment and build args
ARG BUILD_NUMBER=0

ARG glv=
ENV GLOG_v=$glv
ARG INSTALL_PATH=/usr/local/sysflow

ARG BUILD_NUMBER=0
ARG MODPREFIX=${INSTALL_PATH}/modules

## build sysporter
ENV LIBRARY_PATH=/lib64

# build sysporter
COPY ./src/ /build/src/
RUN cd /build/src && make SYSFLOW_BUILD_NUMBER=$BUILD_NUMBER
RUN cd /build/src && \
make SYSFLOW_BUILD_NUMBER=$BUILD_NUMBER \
LIBLOCALPREFIX=${MODPREFIX} \
SDLOCALLIBPREFIX=${MODPREFIX}/lib \
SDLOCALINCPREFIX=${MODPREFIX}/include/sysdig \
AVRLOCALLIBPREFIX=${MODPREFIX}/lib \
AVRLOCALINCPREFIX=${MODPREFIX}/include \
SFLOCALINCPREFIX=${MODPREFIX}/include/sysflow/c++ \
FSLOCALINCPREFIX=${MODPREFIX}/include/filesystem \
SCHLOCALPREFIX=${MODPREFIX}/conf \
install && \
make clean && \
rm -rf /build

##-----------------------
## Stage: Runtime
##-----------------------
FROM sfcollector-ubi:latest as runtime
#-----------------------
# Stage: Runtime
#-----------------------
FROM sysflowtelemetry/sf-collector:base-${TAG} AS runtime

## environment variables
# environment variables
ARG interval=30
ENV INTERVAL=$interval

ARG filter=""
ARG filter=
ENV FILTER=$filter

ARG exporterid="local"
Expand All @@ -54,55 +67,78 @@ ENV EXPORTER_ID=$exporterid
ARG output=/mnt/data/
ENV OUTPUT=$output

## copy dependencies
COPY --from=builder /build/src/sysporter /usr/local/sysflow/bin/
COPY --from=builder /build/modules/sysflow/avro/avsc/SysFlow.avsc /usr/local/sysflow/conf/
RUN ln -s /usr/local/sysflow/modules/lib/libcrypto.so /usr/local/sysflow/modules/lib/libcrypto.so.1.0.0
RUN ln -s /usr/local/sysflow/modules/lib/libssl.so /usr/local/sysflow/modules/lib/libssl.so.1.0.0
ARG cripath=
ENV CRI_PATH=$cripath

ARG critimeout=
ENV CRI_TIMEOUT=$critimeout

ARG debug=
ENV DEBUG=$debug

ARG gllogtostderr=1
ENV GLOG_logtostderr=$gllogtostderr

ARG glv=
ENV GLOG_v=$glv

ARG INSTALL_PATH=/usr/local/sysflow

ARG MODPREFIX=${INSTALL_PATH}/modules

## entrypoint
# copy dependencies
COPY --from=builder /usr/local/lib/ /usr/local/lib/
COPY --from=builder ${MODPREFIX}/lib/*.so* ${MODPREFIX}/lib/
COPY --from=builder ${MODPREFIX}/bin/sysdig-probe-loader ${MODPREFIX}/bin/
RUN ln -s ${INSTALL_PATH}/bin/sysdig-probe-loader /usr/bin/sysdig-probe-loader
COPY --from=builder ${INSTALL_PATH}/conf/ ${INSTALL_PATH}/conf/
COPY --from=builder ${INSTALL_PATH}/bin/sysporter ${INSTALL_PATH}/bin/

# entrypoint
WORKDIR /usr/local/sysflow/bin/
CMD /usr/local/sysflow/bin/sysporter -G $INTERVAL -w $OUTPUT -e "$EXPORTER_ID" -f "$FILTER"

##-----------------------
## Stage: Testing
##-----------------------
FROM runtime as testing
CMD /usr/local/sysflow/bin/sysporter \
${INTERVAL:+-G} $INTERVAL \
${OUTPUT:+-w} $OUTPUT \
${EXPORTER_ID:+-e} "$EXPORTER_ID" \
${FILTER:+-f} "$FILTER" \
${CRI_PATH:+-p} ${CRI_PATH} \
${CRI_TIMEOUT:+-t} ${CRI_TIMEOUT} \
${DEBUG:+-d}

#-----------------------
# Stage: Testing
#-----------------------
FROM runtime AS testing

# environment and build args
ARG BATS_VERSION=1.1.0

ARG wdir=/usr/local/sysflow
ENV WDIR=$wdir

## dependencies
# Install Python environment
ARG INSTALL_PATH=/usr/local/sysflow

# dependencies
RUN dnf install -y --disableplugin=subscription-manager \
python3 \
python3 \
python3-wheel && \
mkdir -p /usr/local/lib/python3.6/site-packages && \
ln -s /usr/bin/easy_install-3 /usr/bin/easy_install && \
ln -s /usr/bin/python3 /usr/bin/python && \
ln -s /usr/bin/pip3 /usr/bin/pip && \
dnf -y clean all && rm -rf /var/cache/dnf
#RUN apt-get update -yqq && \
# apt-get --no-install-recommends --fix-broken install -yqq && \
# apt-get install -yqq \
# apt-utils \
# git \
# locales \
# valgrind \
# python3 \
# python3-pip && \
# locale-gen en_US.UTF-8 && \
# apt-get clean -yqq && \
# rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /var/lib/apt/archive/*

## copy dependencies
COPY --from=builder /build/modules/sysflow/py3 /usr/local/sysflow/utils/

RUN mkdir /tmp/bats && cd /tmp/bats && \
wget https://github.com/bats-core/bats-core/archive/v${BATS_VERSION}.tar.gz && \
tar -xzf v${BATS_VERSION}.tar.gz && rm -rf v${BATS_VERSION}.tar.gz && \
cd bats-core-${BATS_VERSION} && ./install.sh /usr/local && rm -rf /tmp/bats

# install APIs
COPY modules/sysflow/py3 ${INSTALL_PATH}/utils

RUN cd /usr/local/sysflow/utils && \
python3 setup.py install

RUN mkdir /bats && git clone https://github.com/bats-core/bats-core.git /bats && \
cd /bats && ./install.sh /usr/local && rm -r /bats

WORKDIR $wdir
ENTRYPOINT ["/usr/local/bin/bats"]
85 changes: 60 additions & 25 deletions Dockerfile.ubi.amd64
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,75 @@
# limitations under the License.

#-----------------------
# Stage: deps
# Stage: base
#-----------------------
FROM registry.access.redhat.com/ubi8/ubi:latest AS deps
FROM registry.access.redhat.com/ubi8/ubi AS base

ENV LIBRARY_PATH=/lib64
# dependencies
RUN dnf install -y --disableplugin=subscription-manager \
http://mirror.centos.org/centos/8/BaseOS/x86_64/os/Packages/centos-gpg-keys-8.1-1.1911.0.8.el8.noarch.rpm \
http://mirror.centos.org/centos/8/BaseOS/x86_64/os/Packages/centos-repos-8.1-1.1911.0.8.el8.x86_64.rpm && \
dnf update -y --disableplugin=subscription-manager && \
dnf install -y --disableplugin=subscription-manager --disableexcludes=all --enablerepo=PowerTools \
kernel-devel \
kernel-headers \
gcc \
gcc-c++ \
make \
cmake \
lua-devel \
pkgconfig \
autoconf \
wget \
automake \
libtool \
patch \
binutils \
bzip2 \
perl \
flex \
bison \
libstdc++-static \
glibc-static \
diffutils \
kmod \
epel-release \
xz \
boost-devel \
elfutils-libelf-devel \
apr-devel \
apr-util-devel \
sparsehash-devel \
ncurses-devel \
openssl-devel \
glog-devel && \
dnf update -y --disableplugin=subscription-manager && \
dnf install -y --disableplugin=subscription-manager --disableexcludes=all --enablerepo=PowerTools dkms && \
dnf -y clean all && rm -rf /var/cache/dnf

ENV SYSDIG_HOST_ROOT=/host
#-----------------------
# Stage: mods
#-----------------------
FROM base AS mods

ENV PATH="$PATH:/usr/local/sysflow/modules/bin"
# environment and args
ARG INSTALL_PATH=/usr/local/sysflow

ENV HOME=/root
ENV PATH="$PATH:"${INSTALL_PATH}"/modules/bin"

ARG gllogtostderr=1
ENV GLOG_logtostderr=$gllogtostderr

ARG glv=
ENV GLOG_v=$glv
ENV LIBRARY_PATH=/lib64

## dependencies
ARG INSTALL_PKGS="kernel-devel kernel-headers gcc gcc-c++ make cmake lua-devel pkgconfig autoconf wget automake libtool patch binutils bzip2 perl make flex bison libstdc++-static glibc-static diffutils kmod epel-release"
RUN dnf install -y --disableplugin=subscription-manager http://mirror.centos.org/centos/8/BaseOS/x86_64/os/Packages/centos-gpg-keys-8.1-1.1911.0.8.el8.noarch.rpm http://mirror.centos.org/centos/8/BaseOS/x86_64/os/Packages/centos-repos-8.1-1.1911.0.8.el8.x86_64.rpm && \
dnf update -y --disableplugin=subscription-manager && \
dnf install -y --disableplugin=subscription-manager --disableexcludes=all --enablerepo=PowerTools ${INSTALL_PKGS} \
xz boost-devel elfutils-libelf-devel apr-devel apr-util apr-util-devel sparsehash-devel ncurses-devel openssl-devel glog-devel && \
dnf update -y --disableplugin=subscription-manager && \
dnf install -y --disableplugin=subscription-manager --disableexcludes=all --enablerepo=PowerTools dkms
ENV SYSDIG_HOST_ROOT=/host

ENV HOME=/root

## build dependencies
#RUN mkdir /build
COPY ./modules /build/modules
COPY ./makefile.* /build/
RUN cd /build/modules && make install
# build modules
COPY ./modules /build/modules
COPY ./makefile.* /build/
COPY ./docker-entry-ubi.sh /usr/local/sysflow/modules/bin/
RUN cp /usr/local/sysflow/modules/bin/sysdig-probe-loader /usr/bin/
RUN cd /build/modules && \
make INSTALL_PATH=${INSTALL_PATH} install && \
ln -s ${INSTALL_PATH}/bin/sysdig-probe-loader /usr/bin/sysdig-probe-loader && \
make clean && rm -rf /build/modules

ENTRYPOINT ["/usr/local/sysflow/modules/bin/docker-entry-ubi.sh"]
19 changes: 19 additions & 0 deletions hooks/build
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,26 @@ echo "[***] Build hook running"
make -C modules init

# Multi-stage build
docker build \
--cache-from $IMAGE_NAME-base \
--target base \
-f Dockerfile.ubi.amd64 \
-t $IMAGE_NAME-base .

docker build \
--cache-from $IMAGE_NAME-mods \
--target mods \
-f Dockerfile.ubi.amd64 \
-t $IMAGE_NAME-mods .

docker build \
--build-arg TAG=$DOCKER_TAG \
--cache-from $IMAGE_NAME-builder \
--target builder \
-t $IMAGE_NAME-builder .

docker build \
--build-arg BUILD_NUMBER=$(git rev-parse --short HEAD) \
--cache-from $IMAGE_NAME \
--target runtime \
-t $IMAGE_NAME .
8 changes: 8 additions & 0 deletions hooks/post_push
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

echo "[***] Post-push hook running"

docker push $IMAGE_NAME-base
docker push $IMAGE_NAME-mods
docker push $IMAGE_NAME-builder
docker push $IMAGE_NAME-testing
8 changes: 8 additions & 0 deletions hooks/pre_build
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

echo "[***] Pre-build hook running"

docker pull $IMAGE_NAME-base
docker pull $IMAGE_NAME-mods
docker pull $IMAGE_NAME-builder
docker pull $IMAGE_NAME
4 changes: 3 additions & 1 deletion hooks/pre_test
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
echo "[***] Pre-test hook running"

# Build test container
docker pull $IMAGE_NAME-testing

docker build \
--cache-from $IMAGE_NAME \
--cache-from $IMAGE_NAME-testing \
--target testing \
-t $IMAGE_NAME-testing .
7 changes: 5 additions & 2 deletions makefile.env.inc
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

PREFIX=/usr/local/sysflow
MODPREFIX=$(PREFIX)/modules
INSTALL_PATH?=/usr/local/sysflow
MODPREFIX=$(INSTALL_PATH)/modules
LIBPREFIX=$(MODPREFIX)/lib
BINPREFIX=$(MODPREFIX)/bin
CONFPREFIX=$(MODPREFIX)/conf
DRIVERPREFIX=/usr/src/sysdig-
SDINCPREFIX=$(MODPREFIX)/include/sysdig
AVRINCPREFIX=$(MODPREFIX)/include/avro
SFINCPREFIX=$(MODPREFIX)/include/sysflow
FSINCPREFIX=$(MODPREFIX)/include/filesystem
Loading

0 comments on commit d9c260e

Please sign in to comment.