Reduce image size of containers 93/79593/1
authorSylvain Desbureaux <sylvain.desbureaux@orange.com>
Mon, 4 Mar 2019 07:45:37 +0000 (08:45 +0100)
committerSylvain Desbureaux <sylvain.desbureaux@orange.com>
Mon, 4 Mar 2019 07:56:00 +0000 (08:56 +0100)
CIA project goal is to reduce image size of container and make the
container multi architecture.

Portal images are already multi architecure ready and portal-wms and
portal-db are also done in an efficient way.

Portal-app and portal-sdk although can be shrinked, using multi stage
docker builds.

This commit allow a noticeable shrink for both of them:

from 708Mb to 298Mb for portal-app and from 388Mb to 257Mb for
portal-sdk.

Change-Id: Id5cca8b78d0d9ee1724259dab40b7ccff910c628
Issue-ID: INT-939
Issue-ID: INT-922
Issue-ID: INT-881
Issue-ID: INT-925
Issue-ID: INT-936
Signed-off-by: Sylvain Desbureaux <sylvain.desbureaux@orange.com>
deliveries/Dockerfile.portal
deliveries/Dockerfile.sdk

index 847fdd9..b4c759f 100644 (file)
@@ -1,5 +1,23 @@
 # Dockerfile for image with ONAP Portal
 
+# Multistage to be able to have SDK war content and not war itself
+FROM busybox:latest AS war-decompress
+
+# Arguments are supplied by build.sh script
+# the defaults below only support testing
+ARG PORTAL_WAR=build/ecompportal-be-os.war
+ARG FE_DIR=build/public
+
+# Just variables, never passed in
+ARG PORTALCONTEXT=ONAPPORTAL
+
+RUN mkdir ${PORTALCONTEXT}
+
+# Portal has many parts
+COPY $PORTAL_WAR ${PORTALCONTEXT}
+RUN cd ${PORTALCONTEXT} && unzip -q *.war && rm *.war
+COPY ${FE_DIR} ${PORTALCONTEXT}/public
+
 # Yields an image 823 MB
 FROM openjdk:8-alpine
 # Yields an image 1.4 GB
@@ -14,7 +32,8 @@ ARG HTTPS_PROXY
 # ARG PORTAL_CERT=truststoreONAPall.jks
 
 # Just variables, never passed in
-ARG TOMCAT=apache-tomcat-8.0.37
+ARG TOMCAT_VERSION=8.0.37
+ARG TOMCAT=apache-tomcat-${TOMCAT_VERSION}
 ARG TOMCATTAR=${TOMCAT}.tar.gz
 ARG TOMCATHOME=/opt/${TOMCAT}
 ARG PORTALCONTEXT=ONAPPORTAL
@@ -26,22 +45,14 @@ RUN if [ ! -z ${HTTP_PROXY} ]; then echo "Acquire::http::proxy  \"${HTTP_PROXY}\
 
 # Install Tomcat.  This image already has curl.
 WORKDIR /tmp
-RUN wget -q http://archive.apache.org/dist/tomcat/tomcat-8/v8.0.37/bin/apache-tomcat-8.0.37.tar.gz
-RUN tar -xzf ${TOMCATTAR}
-RUN rm ${TOMCATTAR}
-# Remove manager and sample apps
-RUN rm -fr ${TOMCAT}/webapps/*
-RUN mkdir -p /opt
-COPY ${SERVERXML} ${TOMCAT}/conf
-RUN mv ${TOMCAT} /opt
-
-WORKDIR ${TOMCATHOME}/webapps
-RUN mkdir ${PORTALCONTEXT}
+RUN wget -q http://archive.apache.org/dist/tomcat/tomcat-8/v${TOMCAT_VERSION}/bin/${TOMCATTAR} && \
+    tar -xzf ${TOMCATTAR} && \
+    rm ${TOMCATTAR} &&\
+    rm -fr ${TOMCAT}/webapps/* &&\
+    mkdir -p /opt &&\
+    mv ${TOMCAT} /opt
 
-# Portal has many parts
-COPY $PORTAL_WAR ${PORTALCONTEXT}
-RUN cd ${PORTALCONTEXT} && unzip -q *.war && rm *.war
-COPY ${FE_DIR} ${PORTALCONTEXT}/public
+COPY --from=war-decompress /${PORTALCONTEXT} ${TOMCATHOME}/webapps/${PORTALCONTEXT}/
 
 VOLUME ${TOMCATHOME}/logs
 
index 3ae9c4a..6afbb6c 100644 (file)
@@ -1,43 +1,54 @@
 # Dockerfile for image with ONAP Portal SDK demo app
 
+# Multistage to be able to have SDK war content and not war itself
+FROM busybox:latest AS war-decompress
+
+# Arguments are supplied by build.sh script
+# the defaults below only support testing
+ARG SDK_WAR=build/epsdk-app-os.war
+
+# Just variables, never passed in
+ARG SDKCONTEXT=ONAPPORTALSDK
+
+RUN mkdir ${SDKCONTEXT}
+
+# SDK app has only a war
+COPY $SDK_WAR ${SDKCONTEXT}
+RUN cd ${SDKCONTEXT} && unzip -q *.war && rm *.war
+
+
 # Yields an image 823 MB
 FROM openjdk:8-alpine
 # Yields an image 1.4 GB
 # FROM openjdk:8-jdk
-
-# Arguments are supplied by build.sh script
-# the defaults below only support testing
 ARG SDK_WAR=build/epsdk-app-os.war
 ARG HTTP_PROXY
 ARG HTTPS_PROXY
 
 # Just variables, never passed in
-ARG TOMCAT=apache-tomcat-8.0.37
+ARG TOMCAT_VERSION=8.0.37
+ARG TOMCAT=apache-tomcat-${TOMCAT_VERSION}
 ARG TOMCATTAR=${TOMCAT}.tar.gz
 ARG TOMCATHOME=/opt/${TOMCAT}
 ARG SDKCONTEXT=ONAPPORTALSDK
 
+
 ENV http_proxy $HTTP_PROXY
 ENV https_proxy $HTTPS_PROXY
 RUN if [ ! -z ${HTTP_PROXY} ]; then echo "Acquire::http::proxy  \"${HTTP_PROXY}\";" >> /etc/apt/apt.conf; fi && \
     if [ ! -z ${HTTPS_PROXY} ]; then echo "Acquire::https::proxy \"${HTTPS_PROXY}\";" >> /etc/apt/apt.conf; fi
 
 # Install Tomcat.  This image already has curl.
-WORKDIR /tmp
-RUN wget -q http://archive.apache.org/dist/tomcat/tomcat-8/v8.0.37/bin/apache-tomcat-8.0.37.tar.gz
-RUN tar -xzf ${TOMCATTAR}
-RUN rm ${TOMCATTAR}
 # Remove manager and sample apps
-RUN rm -fr ${TOMCAT}/webapps/[a-z]*
-RUN mkdir -p /opt
-RUN mv ${TOMCAT} /opt
-
-WORKDIR ${TOMCATHOME}/webapps
-RUN mkdir ${SDKCONTEXT}
+WORKDIR /tmp
+RUN wget -q http://archive.apache.org/dist/tomcat/tomcat-8/v${TOMCAT_VERSION}/bin/${TOMCATTAR} && \
+    tar -xzf ${TOMCATTAR} && \
+    rm ${TOMCATTAR} &&\
+    rm -fr ${TOMCAT}/webapps/[a-z]* &&\
+    mkdir -p /opt &&\
+    mv ${TOMCAT} /opt
 
-# SDK app has only a war
-COPY $SDK_WAR ${SDKCONTEXT}
-RUN cd ${SDKCONTEXT} && unzip -q *.war && rm *.war
+COPY --from=war-decompress /${SDKCONTEXT} ${TOMCATHOME}/webapps/${SDKCONTEXT}/
 
 VOLUME ${TOMCATHOME}/logs