summaryrefslogtreecommitdiffstats
path: root/packages/policy-api-docker/src
diff options
context:
space:
mode:
authordanielhanrahan <daniel.hanrahan@est.tech>2022-06-29 13:51:39 +0100
committerdanielhanrahan <daniel.hanrahan@est.tech>2022-07-13 11:35:32 +0100
commita5dd0e0e1dc12c693b338ca94212b2bf5f32c53b (patch)
tree0576cf4fb5b8480b277185685f08916982ff7434 /packages/policy-api-docker/src
parentfdd186004f61cd22688116515a27a2efd4550072 (diff)
Reduce size of docker images for API
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% (956MB to 259MB) Reduce size of OpenSuse image by 62% (1.12GB to 423MB) Issue-ID: POLICY-4265 Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech> Change-Id: I321cd42ade294a8af40c64612037d3ca1cf58341
Diffstat (limited to 'packages/policy-api-docker/src')
-rw-r--r--packages/policy-api-docker/src/main/docker/Dockerfile22
-rw-r--r--packages/policy-api-docker/src/main/docker/suse.Dockerfile24
2 files changed, 27 insertions, 19 deletions
diff --git a/packages/policy-api-docker/src/main/docker/Dockerfile b/packages/policy-api-docker/src/main/docker/Dockerfile
index 7fd6da9b..8ac777c3 100644
--- a/packages/policy-api-docker/src/main/docker/Dockerfile
+++ b/packages/policy-api-docker/src/main/docker/Dockerfile
@@ -20,6 +20,12 @@
# SPDX-License-Identifier: Apache-2.0
# ============LICENSE_END=========================================================
#-------------------------------------------------------------------------------
+
+FROM busybox AS tarball
+RUN mkdir /packages /extracted
+COPY /maven/lib/policy-api.tar.gz /packages/
+RUN tar xvzf /packages/policy-api.tar.gz --directory /extracted/
+
FROM onap/policy-jre-alpine:2.4.3
LABEL maintainer="Policy Team"
@@ -37,18 +43,16 @@ ARG POLICY_LOGS=/var/log/onap/policy/api
ENV POLICY_LOGS=$POLICY_LOGS
ENV POLICY_HOME=$POLICY_HOME/api
-RUN mkdir -p $POLICY_LOGS $POLICY_HOME $POLICY_HOME/bin && \
- chown -R policy:policy $POLICY_HOME $POLICY_LOGS && \
- mkdir /packages
-COPY /maven/lib/policy-api.tar.gz /packages
-RUN tar xvfz /packages/policy-api.tar.gz --directory $POLICY_HOME && \
- rm /packages/policy-api.tar.gz
+RUN 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-api.sh bin/.
-COPY /maven/api.jar /app
+COPY --chown=policy:policy policy-api.sh bin/
+COPY --chown=policy:policy /maven/api.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-api-docker/src/main/docker/suse.Dockerfile b/packages/policy-api-docker/src/main/docker/suse.Dockerfile
index 712daad6..e3c42bf9 100644
--- a/packages/policy-api-docker/src/main/docker/suse.Dockerfile
+++ b/packages/policy-api-docker/src/main/docker/suse.Dockerfile
@@ -18,6 +18,12 @@
# SPDX-License-Identifier: Apache-2.0
# ============LICENSE_END=========================================================
#-------------------------------------------------------------------------------
+
+FROM busybox AS tarball
+RUN mkdir /packages /extracted
+COPY /maven/lib/policy-api.tar.gz /packages/
+RUN tar xvzf /packages/policy-api.tar.gz --directory /extracted/
+
FROM opensuse/leap:15.4
LABEL maintainer="Policy Team"
@@ -37,22 +43,20 @@ ENV POLICY_HOME=/opt/app/policy/api
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-api.tar.gz /packages
-RUN tar xvfz /packages/policy-api.tar.gz --directory $POLICY_HOME && \
- rm /packages/policy-api.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-api.sh bin/.
-COPY /maven/api.jar /app
+COPY --chown=policy:policy policy-api.sh bin/
+COPY --chown=policy:policy /maven/api.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