diff options
author | danielhanrahan <daniel.hanrahan@est.tech> | 2022-07-01 14:05:57 +0100 |
---|---|---|
committer | danielhanrahan <daniel.hanrahan@est.tech> | 2022-07-13 11:47:48 +0100 |
commit | bec30e3091fad4278cb29811b0d40d3375cd1565 (patch) | |
tree | c1055811cc3e0400f3e9a0c868fef76d70cd35ec /packages/policy-pap-docker/src/main | |
parent | b8d1daba56496ea03933090b1ccc46a79919684e (diff) |
Reduce size of docker images for PAP
Remove unused jar files from image (not needed since spring boot)
Avoid creating extra layers when extracting tarball
Reduce size of Alpine image by 73% (959MB to 259MB)
Reduce size of OpenSuse image by 62% (1.12GB to 423MB)
Issue-ID: POLICY-4266
Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech>
Change-Id: I5a0a3efc81b0cb8da899c12f65479fd2af935451
Diffstat (limited to 'packages/policy-pap-docker/src/main')
-rw-r--r-- | packages/policy-pap-docker/src/main/docker/Dockerfile | 21 | ||||
-rw-r--r-- | packages/policy-pap-docker/src/main/docker/suse.Dockerfile | 23 |
2 files changed, 24 insertions, 20 deletions
diff --git a/packages/policy-pap-docker/src/main/docker/Dockerfile b/packages/policy-pap-docker/src/main/docker/Dockerfile index e4a8ca3c..0b17b355 100644 --- a/packages/policy-pap-docker/src/main/docker/Dockerfile +++ b/packages/policy-pap-docker/src/main/docker/Dockerfile @@ -21,6 +21,11 @@ # ============LICENSE_END========================================================= #------------------------------------------------------------------------------- +FROM busybox AS tarball +RUN mkdir /packages /extracted +COPY /maven/lib/policy-pap.tar.gz /packages/ +RUN tar xvzf /packages/policy-pap.tar.gz --directory /extracted/ + FROM onap/policy-jre-alpine:2.4.3 LABEL maintainer="Policy Team" @@ -38,20 +43,16 @@ ARG POLICY_LOGS=/var/log/onap/policy/pap ENV POLICY_LOGS=$POLICY_LOGS ENV POLICY_HOME=$POLICY_HOME/pap -RUN mkdir -p $POLICY_HOME $POLICY_LOGS $POLICY_HOME/bin && \ - chown -R policy:policy $POLICY_HOME $POLICY_LOGS && \ - mkdir /packages -COPY /maven/lib/policy-pap.tar.gz /packages +RUN mkdir -p $POLICY_HOME $POLICY_LOGS && \ + chown -R policy:policy $POLICY_HOME $POLICY_LOGS -RUN tar xvfz /packages/policy-pap.tar.gz --directory $POLICY_HOME \ - && rm /packages/policy-pap.tar.gz +COPY --chown=policy:policy --from=tarball /extracted $POLICY_HOME WORKDIR $POLICY_HOME -COPY policy-pap.sh bin/. -COPY /maven/pap.jar /app - +COPY --chown=policy:policy policy-pap.sh bin/ +COPY --chown=policy:policy /maven/pap.jar /app/ -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/packages/policy-pap-docker/src/main/docker/suse.Dockerfile b/packages/policy-pap-docker/src/main/docker/suse.Dockerfile index 78fd57e2..0641ffbe 100644 --- a/packages/policy-pap-docker/src/main/docker/suse.Dockerfile +++ b/packages/policy-pap-docker/src/main/docker/suse.Dockerfile @@ -19,6 +19,11 @@ # ============LICENSE_END========================================================= #------------------------------------------------------------------------------- +FROM busybox AS tarball +RUN mkdir /packages /extracted +COPY /maven/lib/policy-pap.tar.gz /packages/ +RUN tar xvzf /packages/policy-pap.tar.gz --directory /extracted/ + FROM opensuse/leap:15.4 LABEL maintainer="Policy Team" @@ -38,22 +43,20 @@ ENV POLICY_HOME=/opt/app/policy/pap 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/policy-pap.tar.gz /packages -RUN tar xvfz /packages/policy-pap.tar.gz --directory $POLICY_HOME && \ - rm /packages/policy-pap.tar.gz + mkdir -p $POLICY_HOME $POLICY_LOGS && \ + chown -R policy:policy $POLICY_HOME $POLICY_LOGS + +COPY --chown=policy:policy --from=tarball /extracted $POLICY_HOME WORKDIR $POLICY_HOME -COPY policy-pap.sh bin/. -COPY /maven/pap.jar /app +COPY --chown=policy:policy policy-pap.sh bin/ +COPY --chown=policy:policy /maven/pap.jar /app/ -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 |