diff --git a/docker/base/Dockerfile.j2 b/docker/base/Dockerfile.j2 index 22457700c0..31e222da88 100644 --- a/docker/base/Dockerfile.j2 +++ b/docker/base/Dockerfile.j2 @@ -53,9 +53,9 @@ RUN rpm --import https://yum.mariadb.org/RPM-GPG-KEY-MariaDB && \ {% if install_metatype in ['rdo', 'mixed'] %} -# These repos provide latest packages built from trunk master into RPMs -RUN curl http://trunk.rdoproject.org/centos7/current/delorean.repo -o /etc/yum.repos.d/delorean.repo -RUN curl http://trunk.rdoproject.org/centos7/delorean-deps.repo -o /etc/yum.repos.d/delorean-deps.repo +{% for cmd in rpm_setup %} +{{ cmd }} +{% endfor %} {% endif %} {# endif for repo setup for all RHEL except RHEL OSP #} diff --git a/etc/kolla/kolla-build.conf b/etc/kolla/kolla-build.conf index 9e57828533..02bdfc1374 100644 --- a/etc/kolla/kolla-build.conf +++ b/etc/kolla/kolla-build.conf @@ -48,6 +48,9 @@ # The registry host. The default registry host is Docker Hub. #registry = None +# Comma separated list of .rpm or .repo file(s) or URL(s) to install before +# building containers. +#rpm_setup_config = http://trunk.rdoproject.org/centos7/currrent/delorean.repo,http://trunk.rdoproject.org/centos7/delorean-deps.repo # Preset build profiles can be set here to easily build common sets of images [profiles] diff --git a/kolla/cmd/build.py b/kolla/cmd/build.py index 4624aafc00..6193fd5c9b 100755 --- a/kolla/cmd/build.py +++ b/kolla/cmd/build.py @@ -43,6 +43,10 @@ LOG.setLevel(logging.INFO) signal.signal(signal.SIGINT, signal.SIG_DFL) +RDO_MIRROR = "http://trunk.rdoproject.org/centos7" +DELOREAN = "{}/current/delorean.repo".format(RDO_MIRROR) +DELOREAN_DEPS = "{}/delorean-deps.repo".format(RDO_MIRROR) + class KollaDirNotFoundException(Exception): pass @@ -52,6 +56,10 @@ class KollaUnknownBuildTypeException(Exception): pass +class KollaRpmSetupUnknownConfig(Exception): + pass + + def docker_client(): docker_kwargs = docker.utils.kwargs_from_env() return docker.Client(version='auto', **docker_kwargs) @@ -282,6 +290,7 @@ def merge_args_and_config(settings_from_config_file): "push": False, "registry": None, "retries": 3, + "rpm_setup_config": '', "tag": get_kolla_version(), "threads": 8 } @@ -373,6 +382,10 @@ class KollaWorker(object): self.install_type = config['install_type'] self.tag = config['tag'] self.images = list() + rpm_setup_config = [cfg.strip() + for cfg in config['rpm_setup_config'].split(',') + if cfg] + self.rpm_setup = self.build_rpm_setup(rpm_setup_config) if self.install_type == 'binary': self.install_metatype = 'rdo' @@ -403,6 +416,40 @@ class KollaWorker(object): self.image_statuses_unmatched = dict() self.maintainer = config['maintainer'] + def build_rpm_setup(self, rpm_setup_config): + """Generates a list of docker commands based on provided configuration. + + :param rpm_setup_config: A list of .rpm or .repo paths or URLs + :return: A list of docker commands + """ + rpm_setup = list() + + if not rpm_setup_config: + rpm_setup_config = [DELOREAN, DELOREAN_DEPS] + + for config in rpm_setup_config: + if config.endswith('.rpm'): + # RPM files can be installed with yum from file path or url + cmd = "RUN yum -y install {}".format(config) + elif config.endswith('.repo'): + if config.startswith('http'): + # Curl http://url/etc.repo to /etc/yum.repos.d/etc.repo + name = config.split('/')[-1] + cmd = "RUN curl {} -o /etc/yum.repos.d/{}".format(config, + name) + else: + # Copy .repo file from filesystem + cmd = "COPY {} /etc/yum.repos.d/".format(config) + else: + raise KollaRpmSetupUnknownConfig( + 'RPM setup must be provided as .rpm or .repo files.' + ' Attempted configuration was {}'.format(config) + ) + + rpm_setup.append(cmd) + + return rpm_setup + def setup_working_dir(self): """Creates a working directory for use while building""" ts = time.time() @@ -433,7 +480,8 @@ class KollaWorker(object): 'namespace': self.namespace, 'tag': self.tag, 'maintainer': self.maintainer, - 'kolla_version': get_kolla_version()} + 'kolla_version': get_kolla_version(), + 'rpm_setup': self.rpm_setup} if self.include_header: with open(self.include_header, 'r') as f: values['include_header'] = f.read()