[docker][experimental] Split the build 90/72590/6
authorEmma Foley <efoley@redhat.com>
Mon, 31 May 2021 18:45:04 +0000 (19:45 +0100)
committerEmma Foley <efoley@redhat.com>
Mon, 5 Jul 2021 11:54:16 +0000 (12:54 +0100)
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 <efoley@redhat.com>
docker/barometer-collectd-experimental/Dockerfile

index 8622a63..0a6d980 100644 (file)
@@ -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"]