From 527e5141c50faf263ebdd6366f5126437369b5a3 Mon Sep 17 00:00:00 2001 From: Chris Houseknecht Date: Thu, 10 Aug 2017 10:43:25 -0400 Subject: [PATCH] Add conductor environment during build (#689) * Add conductor environment during build * Add --with-variables to conductor image --- AUTHORS | 1 + container/core.py | 19 ++++++++++++++++--- container/docker/engine.py | 5 +++-- .../docker/templates/conductor-dockerfile.j2 | 3 +++ container/engine.py | 2 +- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/AUTHORS b/AUTHORS index 0e23d30e..c1edaf54 100644 --- a/AUTHORS +++ b/AUTHORS @@ -42,6 +42,7 @@ Bruce Becker Jeff Geerling Marc Sensenich Evan Zeimet +ekultails John Matthews Sean Summers Alex Yanchenko diff --git a/container/core.py b/container/core.py index 284da6bf..e4521ce0 100644 --- a/container/core.py +++ b/container/core.py @@ -28,6 +28,8 @@ from pipes import quote import requests + +from six import iteritems from six.moves.urllib.parse import urljoin from .exceptions import AnsibleContainerAlreadyInitializedException,\ @@ -125,8 +127,7 @@ def hostcmd_init(base_path, project=None, force=False, **kwargs): @host_only -def hostcmd_build(base_path, project_name, engine_name, vars_files=None, - **kwargs): +def hostcmd_build(base_path, project_name, engine_name, vars_files=None, **kwargs): conductor_cache = kwargs['cache'] and kwargs['conductor_cache'] config = get_config(base_path, vars_files=vars_files, engine_name=engine_name, project_name=project_name) engine_obj = load_engine(['BUILD', 'RUN'], @@ -141,10 +142,22 @@ def hostcmd_build(base_path, project_name, engine_name, vars_files=None, if conductor_image_id is None or not kwargs.get('devel'): #TODO once we get a conductor running, figure out how to know it's running if engine_obj.CAP_BUILD_CONDUCTOR: + env_vars = [] + if config.get('settings', {}).get('conductor', {}).get('environment', {}): + environment = config['settings']['conductor']['environment'] + if isinstance(environment, dict): + for key, value in iteritems(environment): + env_vars.append('{}={}'.format(key, value)) + else: + env_vars = environment + if kwargs.get('with_variables'): + env_vars += kwargs['with_variables'] + engine_obj.build_conductor_image( base_path, config.conductor_base, - cache=conductor_cache + cache=conductor_cache, + environment=env_vars ) else: logger.warning(u'%s does not support building the Conductor image.', diff --git a/container/docker/engine.py b/container/docker/engine.py index 0b43b366..427d7e46 100644 --- a/container/docker/engine.py +++ b/container/docker/engine.py @@ -825,7 +825,7 @@ def push(self, image_id, service_name, tag=None, namespace=None, url=None, usern @log_runs @host_only - def build_conductor_image(self, base_path, base_image, cache=True): + def build_conductor_image(self, base_path, base_image, cache=True, environment=[]): with utils.make_temp_dir() as temp_dir: logger.info('Building Docker Engine context...') tarball_path = os.path.join(temp_dir, 'context.tar') @@ -874,7 +874,8 @@ def build_conductor_image(self, base_path, base_image, cache=True): 'conductor-dockerfile.j2', temp_dir, 'Dockerfile', conductor_base=base_image, - docker_version=DOCKER_VERSION) + docker_version=DOCKER_VERSION, + environment=environment) tarball.add(os.path.join(temp_dir, 'Dockerfile'), arcname='Dockerfile') diff --git a/container/docker/templates/conductor-dockerfile.j2 b/container/docker/templates/conductor-dockerfile.j2 index f291129d..4e111bb8 100644 --- a/container/docker/templates/conductor-dockerfile.j2 +++ b/container/docker/templates/conductor-dockerfile.j2 @@ -1,6 +1,9 @@ FROM {{ conductor_base }} ENV ANSIBLE_CONTAINER=1 {% set distro = conductor_base.split(':')[0] %} +{% for envar in environment %} +ENV {{ envar }} +{% endfor %} {% if distro in ["fedora"] %} RUN dnf update -y && \ dnf install -y make gcc git python2 python2-devel curl rsync libffi-devel openssl-devel redhat-rpm-config python2-dnf tar redhat-rpm-config && \ diff --git a/container/engine.py b/container/engine.py index 6ce0676f..15db4b5e 100644 --- a/container/engine.py +++ b/container/engine.py @@ -176,7 +176,7 @@ def push(self, image_id, service_name, **kwargs): raise NotImplementedError() @host_only - def build_conductor_image(self, base_path, base_image, cache=True): + def build_conductor_image(self, base_path, base_image, cache=True, environment=[]): raise NotImplementedError() def get_runtime_volume_id(self, mount_point):