diff options
| author | Abe Music <abe.music@gmail.com> | 2016-07-28 16:31:16 -0500 |
|---|---|---|
| committer | Abe Music <abe.music@gmail.com> | 2016-08-15 08:17:13 -0500 |
| commit | 29fcb04cf38de41276b2b23e69e86d898efe5afb (patch) | |
| tree | e97756d5165a4e879ea095000bec15066452e1bb /kolla/template/methods.py | |
| parent | 6ea99983fcaf13f90efff1c20a3aa20db0af92ba (diff) | |
| download | kolla-29fcb04cf38de41276b2b23e69e86d898efe5afb.tar.gz kolla-29fcb04cf38de41276b2b23e69e86d898efe5afb.zip | |
enhancements to install_packages macro
- Adds debian_package_install method to the jinja environment
that will return the necessary set of commands needed to
install packages via apt-get and/or URLs to .deb packages
- Updates install_packages macro to make use of the method
above
Change-Id: Ie9318a7def54b5034ba91375fd8fd3b589d18349
Partially-implements: blueprint third-party-plugin-support
Diffstat (limited to 'kolla/template/methods.py')
| -rw-r--r-- | kolla/template/methods.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/kolla/template/methods.py b/kolla/template/methods.py new file mode 100644 index 000000000..8e655f4c8 --- /dev/null +++ b/kolla/template/methods.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +def debian_package_install(packages): + """Jinja utility method for building debian-based package install command + + apt-get is not capable of installing .deb files from a URL and the + template logic to construct a series of steps to install regular packages + from apt repos as well as .deb files that need to be downloaded, manually + installed, and cleaned up is complicated. This method will contruct the + proper string required to install all packages in a way that's a bit + easier to follow + + :param packages: a list of strings that are either packages to install + from an apt repo, or URLs to .deb files + :type packages: list + + :returns: string suitable to provide to RUN command in a Dockerfile that + will install the given packages + :rtype: string + """ + cmds = [] + + # divide the list into two groups, one for regular packages and one for + # URL packages + reg_packages, url_packages = [], [] + for package in packages: + if package.startswith('http'): + url_packages.append(package) + else: + reg_packages.append(package) + + # handle the apt-get install + if reg_packages: + cmds.append('apt-get -y install --no-install-recommends {}'.format( + ' '.join(reg_packages) + )) + cmds.append('apt-get clean') + + # handle URL packages + for url in url_packages: + # the path portion should be the file name + name = url[url.rfind('/') + 1:] + cmds.extend([ + 'curl --location {} -o {}'.format(url, name), + 'dpkg -i {}'.format(name), + 'rm -rf {}'.format(name), + ]) + + # return the list of commands + return ' && '.join(cmds) |
