diff options
author | danielhanrahan <daniel.hanrahan@est.tech> | 2022-07-08 17:12:40 +0100 |
---|---|---|
committer | danielhanrahan <daniel.hanrahan@est.tech> | 2022-07-13 12:28:53 +0100 |
commit | 930ea6e2f48a3975eb573b80b28ce573f10c3a62 (patch) | |
tree | 4f0ac363427a542c1a093fcc95d49b6f7824d6e8 | |
parent | f820c8b9c3a140c73570b2fafe7482d39477e7f8 (diff) |
Reduce size of docker images for distribution
Avoid creating extra layers when extracting tarball
Remove redundant chown commands
Reduce size of Alpine image by 37% (357MB to 226MB)
Reduce size of OpenSuse image by 26% (525MB to 389MB)
Issue-ID: POLICY-4276
Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech>
Change-Id: Ieb4faceef2264059dd868ecd04581e29b436c75a
-rw-r--r-- | packages/policy-distribution-docker/src/main/docker/Dockerfile | 18 | ||||
-rw-r--r-- | packages/policy-distribution-docker/src/main/docker/suse.Dockerfile | 20 |
2 files changed, 21 insertions, 17 deletions
diff --git a/packages/policy-distribution-docker/src/main/docker/Dockerfile b/packages/policy-distribution-docker/src/main/docker/Dockerfile index 85c90f82..3d161577 100644 --- a/packages/policy-distribution-docker/src/main/docker/Dockerfile +++ b/packages/policy-distribution-docker/src/main/docker/Dockerfile @@ -20,6 +20,11 @@ # ============LICENSE_END========================================================= #------------------------------------------------------------------------------- +FROM busybox AS tarball +RUN mkdir /packages /extracted +COPY /maven/lib/policy-distribution.tar.gz /packages/ +RUN tar xvzf /packages/policy-distribution.tar.gz --directory /extracted/ + FROM onap/policy-jre-alpine:2.4.3 LABEL maintainer="Policy Team" @@ -37,17 +42,14 @@ ARG POLICY_LOGS=/var/log/onap/policy/distribution ENV POLICY_LOGS=$POLICY_LOGS ENV POLICY_HOME=$POLICY_HOME/distribution -RUN mkdir -p $POLICY_HOME $POLICY_LOGS $POLICY_HOME/bin && \ - chown -R policy:policy $POLICY_HOME $POLICY_LOGS &&\ - mkdir /packages +RUN mkdir -p $POLICY_HOME $POLICY_LOGS && \ + chown -R policy:policy $POLICY_HOME $POLICY_LOGS -COPY /maven/* /packages -RUN tar xvfz /packages/policy-distribution.tar.gz --directory $POLICY_HOME \ - && rm /packages/policy-distribution.tar.gz +COPY --chown=policy:policy --from=tarball /extracted $POLICY_HOME WORKDIR $POLICY_HOME -COPY policy-dist.sh bin/. -RUN chown -R policy:policy * && chmod 755 bin/*.sh +COPY --chown=policy:policy policy-dist.sh bin/ +RUN chmod 755 bin/*.sh USER policy WORKDIR $POLICY_HOME/bin diff --git a/packages/policy-distribution-docker/src/main/docker/suse.Dockerfile b/packages/policy-distribution-docker/src/main/docker/suse.Dockerfile index 0690bb24..f709c336 100644 --- a/packages/policy-distribution-docker/src/main/docker/suse.Dockerfile +++ b/packages/policy-distribution-docker/src/main/docker/suse.Dockerfile @@ -19,6 +19,11 @@ # ============LICENSE_END========================================================= #------------------------------------------------------------------------------- +FROM busybox AS tarball +RUN mkdir /packages /extracted +COPY /maven/lib/policy-distribution.tar.gz /packages/ +RUN tar xvzf /packages/policy-distribution.tar.gz --directory /extracted/ + FROM opensuse/leap:15.4 LABEL maintainer="Policy Team" @@ -38,21 +43,18 @@ ENV POLICY_HOME=/opt/app/policy/distribution 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 $POLICY_LOGS $POLICY_HOME $POLICY_HOME/bin && \ - chown -R policy:policy $POLICY_HOME $POLICY_LOGS && \ - mkdir /packages + mkdir -p $POLICY_HOME $POLICY_LOGS && \ + chown -R policy:policy $POLICY_HOME $POLICY_LOGS -COPY /maven/* /packages -RUN tar xvfz /packages/policy-distribution.tar.gz --directory $POLICY_HOME \ - && rm /packages/policy-distribution.tar.gz +COPY --chown=policy:policy --from=tarball /extracted $POLICY_HOME WORKDIR $POLICY_HOME -COPY policy-dist.sh bin/. -RUN chown -R policy:policy * && chmod 755 bin/*.sh +COPY --chown=policy:policy policy-dist.sh bin/ +RUN chmod 755 bin/*.sh USER policy WORKDIR $POLICY_HOME/bin |