Make the yum repositories configurable in the base image

- Removed hardcoded yum repository configuration in favor of
  commands dynamically generated based on repo-url and repo-file
  arguments. We maintain a sane default set of repositories.
- Added generic rpm_setup_config parameter to add support for
  installing .rpm or .repo files before building containers.

Co-Authored-By: Ryan Hallisey <rhallise@redhat.com>
Implements: blueprint custom-repos
Change-Id: I1b3a7647a9e7239de3cd162cb6f464f05632bde1
This commit is contained in:
David Moreau Simard 2015-12-15 12:05:39 -05:00 committed by Martin André
parent d7095790a2
commit e8ad7488f6
3 changed files with 55 additions and 4 deletions

View File

@ -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 #}

View File

@ -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]

View File

@ -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()