Skip to content

Commit

Permalink
Merge pull request saltstack#9119 from ticosax/add-timout-for-docker-…
Browse files Browse the repository at this point in the history
…build

Some images might take longer to build
  • Loading branch information
thatch45 committed Dec 9, 2013
2 parents cf73e91 + 028d25a commit 85ae120
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
17 changes: 11 additions & 6 deletions salt/modules/dockerio.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def valid(m, id=NOTSET, comment=VALID_RESPONSE, out=None):
return _set_status(m, status=True, id=id, comment=comment, out=out)


def _get_client(version=None):
def _get_client(version=None, timeout=None):
'''
Get a connection to a docker API (socket or URL)
based on config.get mechanism (pillar -> grains)
Expand All @@ -250,13 +250,15 @@ def _get_client(version=None):
'''
kwargs = {}
get = __salt__['config.get']
for k, p in {
'base_url': 'docker.url',
'version': 'docker.version',
}.items():
for k, p in (('base_url', 'docker.url'),
('version', 'docker.version')):
param = get(p, NOTSET)
if param is not NOTSET:
kwargs[k] = param
if timeout is not None:
# make sure we override default timeout of docker-py
# only if defined by user.
kwargs['timeout'] = timeout
client = docker.Client(**kwargs)
# force 1..5 API for registry login
if not version:
Expand Down Expand Up @@ -1362,6 +1364,7 @@ def build(path=None,
fileobj=None,
nocache=False,
rm=True,
timeout=None,
*args, **kwargs):
'''
Build a docker image from a dockerfile or an URL
Expand All @@ -1381,14 +1384,16 @@ def build(path=None,
do not use docker image cache
rm
remove intermediate commits
timeout
timeout is seconds before aborting
CLI Example:
.. code-block:: bash
salt '*' docker.build
'''
client = _get_client()
client = _get_client(timeout=timeout)
status = base_status.copy()
if path or fileobj:
try:
Expand Down
4 changes: 3 additions & 1 deletion salt/states/dockerio.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ def built(name,
nocache=False,
rm=True,
force=False,
timeout=None,
*args, **kwargs):
'''
Build a docker image from a dockerfile or an URL
Expand All @@ -258,7 +259,8 @@ def built(name,
path=path,
quiet=quiet,
nocache=nocache,
rm=rm
rm=rm,
timeout=timeout,
)
status = _ret_status(func(*a, **kw), name)
return status
Expand Down

0 comments on commit 85ae120

Please sign in to comment.