From 7a731e7183eec2a242f28e6686ffe41250b8e5d6 Mon Sep 17 00:00:00 2001 From: Emma Foley Date: Mon, 31 May 2021 19:45:04 +0100 Subject: [docker][experimental] Split the build Split the container build into two stages: * builder Builds collectd and containers all the build artifacts * final Containers collectd binary and all the dependencies needed to run. Does not contain build artifacts, which contribute to a very large container size. The main advantage is that the final container is much smaller (~700MB vs 1.2GB). Change-Id: Ia75734096233b7ecab9d81df06084c24bde2bf90 Signed-off-by: Emma Foley --- docker/barometer-collectd-experimental/Dockerfile | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'docker') diff --git a/docker/barometer-collectd-experimental/Dockerfile b/docker/barometer-collectd-experimental/Dockerfile index 8622a63c..0a6d9806 100644 --- a/docker/barometer-collectd-experimental/Dockerfile +++ b/docker/barometer-collectd-experimental/Dockerfile @@ -14,7 +14,7 @@ # limitations under the License. # -FROM centos:8 +FROM centos:8 as builder ARG COLLECTD_FLAVOR=experimental ARG COLLECTD_PULL_REQUESTS @@ -30,11 +30,25 @@ COPY . ${repos_dir}/barometer WORKDIR ${repos_dir}/barometer/systems RUN ./build_base_machine.sh && \ - dnf clean all && rm -rf /var/cache/dnf && \ - useradd -ms /bin/bash collectd_exec && \ - echo "collectd_exec ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers + dnf clean all && rm -rf /var/cache/dnf + +FROM centos:8 COPY docker/barometer-collectd-experimental/run_collectd.sh /run_collectd.sh RUN chmod +x /run_collectd.sh +RUN useradd -ms /bin/bash collectd_exec && \ + echo "collectd_exec ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers + +COPY --from=builder /opt/collectd /opt/collectd +COPY --from=builder /usr/local/src /usr/local/src +COPY --from=builder /usr/share/snmp/mibs /usr/share/snmp/mibs +COPY --from=builder /opt/collectd/share/collectd/types.db /usr/share/collectd/types.db + +RUN dnf install -y 'dnf-command(builddep)' centos-release-opstools && \ + dnf config-manager --set-enabled powertools && \ + dnf builddep -y https://raw.githubusercontent.com/centos-opstools/collectd/master/collectd.spec && \ + dnf install -y jansson && \ + dnf clean all && rm -rf /var/cache/dnf + ENTRYPOINT ["/run_collectd.sh"] -- cgit 1.2.3-korg