You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2020/09/07 19:50:03 UTC

[GitHub] [nifi-minifi-cpp] arpadboda commented on a change in pull request #882: MINIFICPP-1343 Create a minimal docker image target

arpadboda commented on a change in pull request #882:
URL: https://github.com/apache/nifi-minifi-cpp/pull/882#discussion_r484554812



##########
File path: docker/Dockerfile
##########
@@ -16,113 +16,144 @@
 # under the License.
 #
 
-# First stage: the build environment
-# Edge required for rocksdb
-FROM alpine:3.8 AS builder
-MAINTAINER Apache NiFi <de...@nifi.apache.org>
+# First stage: the common build environment dependencies
+FROM alpine:3.12 AS build_deps
+LABEL maintainer="Apache NiFi <de...@nifi.apache.org>"
 
-ARG UID
-ARG GID
 ARG MINIFI_VERSION
 ARG MINIFI_SOURCE_CODE
+ARG UID=1000
+ARG GID=1000
 
 # Install the system dependencies needed for a build
 RUN apk --update --no-cache upgrade && apk --update --no-cache add gcc \
-	g++ \
-	make \
-	bison \
-	flex \
-	flex-dev \
-	maven \
-	openjdk8-jre-base \
-	openjdk8 \
-	autoconf \
-	libtool \
-	wget \
-	gdb \
-	musl-dev \
-	boost-dev \
-	vim \
-	util-linux-dev \
-	curl-dev \
-	cmake \
-	git \
-	nss \
-	nss-dev \
-	unzip \
-	gpsd-dev \
-	libressl-dev \
-	zlib-dev \
-	bzip2-dev \
-	python3-dev
+  g++ \
+  make \
+  bison \
+  flex \
+  flex-dev \
+  maven \
+  openjdk8-jre-base \
+  openjdk8 \
+  autoconf \
+  libtool \
+  wget \
+  gdb \
+  musl-dev \
+  boost-dev \
+  vim \
+  util-linux-dev \
+  curl-dev \
+  cmake \
+  git \
+  nss \
+  nss-dev \
+  unzip \
+  gpsd-dev \
+  libressl-dev \
+  zlib-dev \
+  bzip2-dev \
+  python3-dev \
+  patch \
+  doxygen
 
 ENV USER minificpp
 ENV MINIFI_BASE_DIR /opt/minifi
+ENV JAVA_HOME /usr/lib/jvm/default-jvm
+ENV PATH ${PATH}:/usr/lib/jvm/default-jvm/bin
+ENV MINIFI_HOME $MINIFI_BASE_DIR/nifi-minifi-cpp-${MINIFI_VERSION}
 
 # Setup minificpp user
 RUN addgroup -g ${GID} ${USER} && adduser -u ${UID} -D -G ${USER} -g "" ${USER}
-RUN mkdir -p ${MINIFI_BASE_DIR}
-ENV JAVA_HOME /usr/lib/jvm/default-jvm
-ENV PATH ${PATH}:/usr/lib/jvm/default-jvm/bin
 
-ADD ${MINIFI_SOURCE_CODE} ${MINIFI_BASE_DIR}
-RUN chown -R ${USER}:${USER} ${MINIFI_BASE_DIR}
+RUN install -d -o ${USER} -g ${USER} ${MINIFI_BASE_DIR}
+COPY --chown=${USER}:${USER} ${MINIFI_SOURCE_CODE} ${MINIFI_BASE_DIR}
 
 USER ${USER}
 
-ENV MINIFI_HOME $MINIFI_BASE_DIR/nifi-minifi-cpp-${MINIFI_VERSION}
 
-# Perform the build
+# Build stage of the minimal image
+FROM build_deps AS build_minimal
 RUN cd ${MINIFI_BASE_DIR} \
-	&& mkdir build \
-	&& cd build \
-	&& cmake -DDISABLE_JEMALLOC=ON -DSTATIC_BUILD= -DSKIP_TESTS=true -DENABLE_JNI=ON -DENABLE_LIBRDKAFKA=ON .. \
-	&& make -j8 package \
-	&& tar -xzvf ${MINIFI_BASE_DIR}/build/nifi-minifi-cpp-${MINIFI_VERSION}-bin.tar.gz -C ${MINIFI_BASE_DIR}
+  && mkdir build \
+  && cd build \
+  && cmake -DDISABLE_LIBARCHIVE=ON -DDISABLE_SCRIPTING=ON -DENABLE_LIBRDKAFKA=ON -DSKIP_TESTS=true -DCMAKE_BUILD_TYPE=MinSizeRel .. \
+  && make -j$(nproc) package \
+  && tar -xzvf ${MINIFI_BASE_DIR}/build/nifi-minifi-cpp-${MINIFI_VERSION}-bin.tar.gz -C ${MINIFI_BASE_DIR}
 
-# Second stage: the runtime image
+
+# Build stage of normal image
+FROM build_deps AS build_release
+RUN cd ${MINIFI_BASE_DIR} \
+  && mkdir build \
+  && cd build \
+  && cmake -DDISABLE_JEMALLOC=ON -DSTATIC_BUILD= -DSKIP_TESTS=true -DENABLE_JNI=ON -DENABLE_LIBRDKAFKA=ON .. \
+  && make -j$(nproc) package \
+  && tar -xzvf ${MINIFI_BASE_DIR}/build/nifi-minifi-cpp-${MINIFI_VERSION}-bin.tar.gz -C ${MINIFI_BASE_DIR}
+
+
+# Common runtime image dependencies
 # Edge required for rocksdb
-FROM alpine:3.8
+FROM alpine:3.12 AS common_runtime_deps
 
-ARG UID
-ARG GID
+ARG UID=1000
+ARG GID=1000
 ARG MINIFI_VERSION
 ARG MINIFI_SOURCE_CODE
 
 # Add testing repo for rocksdb
 RUN echo 'http://dl-cdn.alpinelinux.org/alpine/edge/testing' >> /etc/apk/repositories
 
-RUN apk --update --no-cache upgrade && apk add --update --no-cache \
-	util-linux \
-	curl \
-	unzip \
-	gpsd \
-	openjdk8-jre-base \
-	openjdk8 \
-	nss \
-	nss-dev \
-	libressl \
-	python3 \
-	zlib
-
 ENV USER minificpp
 ENV MINIFI_BASE_DIR /opt/minifi
 ENV MINIFI_HOME ${MINIFI_BASE_DIR}/minifi-current
 ENV MINIFI_VERSIONED_HOME ${MINIFI_BASE_DIR}/nifi-minifi-cpp-${MINIFI_VERSION}
-
 ENV JAVA_HOME /usr/lib/jvm/default-jvm
 ENV PATH ${PATH}:/usr/lib/jvm/default-jvm/bin
 
 RUN addgroup -g ${GID} ${USER} && adduser -u ${UID} -D -G ${USER} -g "" ${USER}
-RUN mkdir -p ${MINIFI_BASE_DIR} \
-    && ln -s ${MINIFI_VERSIONED_HOME} ${MINIFI_HOME}
+RUN install -d -o ${USER} -g ${USER} ${MINIFI_BASE_DIR} \
+  && ln -s ${MINIFI_VERSIONED_HOME} ${MINIFI_HOME}
+
+
+# Final stage of the minimal image
+FROM common_runtime_deps AS minimal
+
+RUN apk --update --no-cache upgrade && apk add --update --no-cache libstdc++
+RUN install -d -o ${USER} -g ${USER} ${MINIFI_VERSIONED_HOME}/bin \
+  && install -d -o ${USER} -g ${USER} ${MINIFI_VERSIONED_HOME}/conf && chown ${USER}:${USER} ${MINIFI_HOME}
 
 # Copy built minifi distribution from builder
-COPY --from=builder ${MINIFI_VERSIONED_HOME} ${MINIFI_HOME}
-RUN chown -R ${USER}:${USER} /opt/minifi
+COPY --from=build_minimal --chown=${USER}:${USER} ${MINIFI_VERSIONED_HOME}/bin/minifi ${MINIFI_HOME}/bin/minifi
+COPY --from=build_minimal --chown=${USER}:${USER} ${MINIFI_VERSIONED_HOME}/bin/minifi.sh ${MINIFI_HOME}/bin/minifi.sh
+COPY --from=build_minimal --chown=${USER}:${USER} ${MINIFI_VERSIONED_HOME}/conf ${MINIFI_HOME}/conf
 
 USER ${USER}
+WORKDIR ${MINIFI_HOME}
+
+# Start MiNiFi CPP in the foreground
+CMD ./bin/minifi.sh run
 
+
+# Final stage of release image
+FROM common_runtime_deps AS release
+RUN apk --update --no-cache upgrade && apk add --update --no-cache \
+  util-linux \
+  curl \
+  unzip \
+  gpsd \
+  openjdk8-jre-base \

Review comment:
       I think in case the minimal release is built without jni, we shouldn't need openjdk/jre and python. 
   Or do I missunderstand something? 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org