From a9d08726f5a48eef77c04ea1acefc00d93ce7076 Mon Sep 17 00:00:00 2001 From: Shaun Smekel Date: Fri, 12 Aug 2016 08:24:11 +1000 Subject: Handle empty package list for install_packages Currently if the install_packages macro is run with an empty package list, it will add a yum or apt-get command with no packages listed. This bug fix aims to omit this line when no packages have been given, or, the operator wants to use the "_override" / "_remove" functionality to disable all packages being installed in a Dockerfile. Co-Authored-By: Paul Bourke Change-Id: Ifaaaebfccc3adb0f2f68a35ac08e59378bc87fdb Closes-bug: 1612446 --- docker/macros.j2 | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'docker/macros.j2') diff --git a/docker/macros.j2 b/docker/macros.j2 index 5cdb12b4c..494feb2f4 100644 --- a/docker/macros.j2 +++ b/docker/macros.j2 @@ -1,12 +1,14 @@ {% macro install_packages(packages) -%} -{% if base_distro in ['centos', 'fedora', 'oraclelinux', 'rhel'] -%} - yum -y install {{ packages | join(' ') }} && yum clean all -{%- elif base_distro in ['ubuntu', 'debian'] -%} - {#- - debian_package_install is a utility method to build up an appropriate - set of commands to install packages in a debian-based environment that - may include URL links to a .deb package (e.g, heka) - -#} - {{ debian_package_install(packages) }} +{% if packages is defined and packages|length > 0 -%} + {% if base_distro in ['centos', 'fedora', 'oraclelinux', 'rhel'] -%} + RUN yum -y install {{ packages | join(' ') }} && yum clean all + {%- elif base_distro in ['ubuntu', 'debian'] -%} + {#- + debian_package_install is a utility method to build up an appropriate + set of commands to install packages in a debian-based environment that + may include URL links to a .deb package (e.g, heka) + -#} + RUN {{ debian_package_install(packages) }} + {%- endif %} {%- endif %} {%- endmacro %} -- cgit v1.2.3