Skip to content
This repository has been archived by the owner on Mar 23, 2019. It is now read-only.

Commit

Permalink
Add conductor environment during build (#689)
Browse files Browse the repository at this point in the history
* Add conductor environment during build

* Add --with-variables to conductor image
  • Loading branch information
Chris Houseknecht committed Aug 10, 2017
1 parent 1cf02cc commit 527e514
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Bruce Becker <brucellino@gmail.com>
Jeff Geerling <geerlingguy@mac.com>
Marc Sensenich <marc-sensenich@users.noreply.github.com>
Evan Zeimet <evan.zeimet@cdw.com>
ekultails <ekultails@gmail.com>
John Matthews <jwmatthews@gmail.com>
Sean Summers <ssummer3@nd.edu>
Alex Yanchenko <alex@yanchenko.com>
Expand Down
19 changes: 16 additions & 3 deletions container/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,\
Expand Down Expand Up @@ -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'],
Expand All @@ -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.',
Expand Down
5 changes: 3 additions & 2 deletions container/docker/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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')

Expand Down
3 changes: 3 additions & 0 deletions container/docker/templates/conductor-dockerfile.j2
Original file line number Diff line number Diff line change
@@ -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 && \
Expand Down
2 changes: 1 addition & 1 deletion container/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 527e514

Please sign in to comment.