From 5570ed3eafc17ca427d86c984755785c539be3b7 Mon Sep 17 00:00:00 2001 From: danielhanrahan Date: Fri, 8 Jul 2022 17:23:55 +0100 Subject: Reduce size of docker images for models-simulator Avoid creating extra layers when extracting tarball Remove redundant chown/chmod commands Reduce size of Alpine image by 48% (593MB to 307MB) Reduce size of OpenSuse image by 38% (761MB to 470MB) Issue-ID: POLICY-4271 Signed-off-by: danielhanrahan Change-Id: I773c92fe64015f5de25d6152853529315df7ca30 --- .../src/main/docker/Dockerfile | 17 +++++++++-------- .../src/main/docker/suse.Dockerfile | 19 ++++++++++--------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/models-sim/packages/models-simulator-docker/src/main/docker/Dockerfile b/models-sim/packages/models-simulator-docker/src/main/docker/Dockerfile index c5832bfd7..773ab357b 100644 --- a/models-sim/packages/models-simulator-docker/src/main/docker/Dockerfile +++ b/models-sim/packages/models-simulator-docker/src/main/docker/Dockerfile @@ -21,6 +21,10 @@ # SPDX-License-Identifier: Apache-2.0 # ============LICENSE_END========================================================= # +FROM busybox AS tarball +RUN mkdir /packages /extracted +COPY /maven/lib/models-simulator.tar.gz /packages/ +RUN tar xvzf /packages/models-simulator.tar.gz --directory /extracted/ FROM onap/policy-jre-alpine:2.4.3 @@ -39,18 +43,15 @@ ARG POLICY_LOGS=/var/log/onap/policy/simulators ENV POLICY_LOGS=$POLICY_LOGS ENV POLICY_HOME=$POLICY_HOME/simulators -RUN mkdir -p $POLICY_HOME $POLICY_LOGS $POLICY_HOME/bin && \ - chown -R policy:policy $POLICY_HOME $POLICY_LOGS && \ - mkdir /packages -COPY /maven/lib/models-simulator.tar.gz /packages +RUN mkdir -p $POLICY_HOME $POLICY_LOGS && \ + chown -R policy:policy $POLICY_HOME $POLICY_LOGS -RUN tar xvfz /packages/models-simulator.tar.gz --directory ${POLICY_HOME} \ - && rm /packages/models-simulator.tar.gz +COPY --chown=policy:policy --from=tarball /extracted $POLICY_HOME WORKDIR $POLICY_HOME -COPY simulators.sh bin/. +COPY --chown=policy:policy simulators.sh bin/ -RUN chown -R policy:policy * && chmod 755 bin/*.sh && chown -R policy:policy /app +RUN chmod 755 bin/*.sh USER policy WORKDIR $POLICY_HOME/bin diff --git a/models-sim/packages/models-simulator-docker/src/main/docker/suse.Dockerfile b/models-sim/packages/models-simulator-docker/src/main/docker/suse.Dockerfile index f7bd5eed7..d751e6dab 100644 --- a/models-sim/packages/models-simulator-docker/src/main/docker/suse.Dockerfile +++ b/models-sim/packages/models-simulator-docker/src/main/docker/suse.Dockerfile @@ -19,6 +19,10 @@ # SPDX-License-Identifier: Apache-2.0 # ============LICENSE_END========================================================= # +FROM busybox AS tarball +RUN mkdir /packages /extracted +COPY /maven/lib/models-simulator.tar.gz /packages/ +RUN tar xvzf /packages/models-simulator.tar.gz --directory /extracted/ FROM opensuse/leap:15.4 @@ -39,22 +43,19 @@ ENV POLICY_HOME=/opt/app/policy/simulators ENV LANG=en_US.UTF-8 LANGUAGE=en_US:en LC_ALL=en_US.UTF-8 ENV JAVA_HOME=/usr/lib64/jvm/java-11-openjdk-11 -RUN zypper -n -q install --no-recommends gzip java-11-openjdk-headless netcat-openbsd tar && \ +RUN zypper -n -q install --no-recommends java-11-openjdk-headless netcat-openbsd && \ zypper -n -q update; zypper -n -q clean --all && \ groupadd --system policy && \ useradd --system --shell /bin/sh -G policy policy && \ - mkdir -p /app $POLICY_LOGS $POLICY_HOME $POLICY_HOME/bin && \ - chown -R policy:policy /app $POLICY_HOME $POLICY_LOGS && \ - mkdir /packages -COPY /maven/lib/models-simulator.tar.gz /packages + mkdir -p $POLICY_HOME $POLICY_LOGS && \ + chown -R policy:policy $POLICY_HOME $POLICY_LOGS -RUN tar xvfz /packages/models-simulator.tar.gz --directory ${POLICY_HOME} \ - && rm /packages/models-simulator.tar.gz +COPY --chown=policy:policy --from=tarball /extracted $POLICY_HOME WORKDIR $POLICY_HOME -COPY simulators.sh bin/. +COPY --chown=policy:policy simulators.sh bin/ -RUN chown -R policy:policy * && chmod 755 bin/*.sh && chown -R policy:policy /app +RUN chmod 755 bin/*.sh USER policy WORKDIR $POLICY_HOME/bin -- cgit 1.2.3-korg