diff options
author | Emma Foley <efoley@redhat.com> | 2021-05-31 19:45:04 +0100 |
---|---|---|
committer | Emma Foley <efoley@redhat.com> | 2021-07-05 12:54:16 +0100 |
commit | 7a731e7183eec2a242f28e6686ffe41250b8e5d6 (patch) | |
tree | 221890713f2aad2c77cfb0f73e0c7d181b65cb99 | |
parent | 9517cbdae0f9e7e6e6446bbc5b7ad8ae6a235de8 (diff) |
[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 <efoley@redhat.com>
-rw-r--r-- | docker/barometer-collectd-experimental/Dockerfile | 22 |
1 files changed, 18 insertions, 4 deletions
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"] |