From d8e84004192dc0c617a9a0a6b9fb0b18aeaaa038 Mon Sep 17 00:00:00 2001 From: Derek Hammer Date: Sat, 13 Dec 2014 10:25:43 -0800 Subject: [PATCH 1/2] Allow for pull as an option to docker build Signed-off-by: Derek Hammer --- docker/client.py | 3 ++- docs/api.md | 1 + tests/test.py | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/docker/client.py b/docker/client.py index 936ab52c..8d312138 100644 --- a/docker/client.py +++ b/docker/client.py @@ -408,7 +408,7 @@ class Client(requests.Session): def build(self, path=None, tag=None, quiet=False, fileobj=None, nocache=False, rm=False, stream=False, timeout=None, - custom_context=False, encoding=None): + pull=False, custom_context=False, encoding=None): remote = context = headers = None if path is None and fileobj is None: raise TypeError("Either path or fileobj needs to be provided.") @@ -439,6 +439,7 @@ class Client(requests.Session): params = { 't': tag, 'remote': remote, + 'pull': pull, 'q': quiet, 'nocache': nocache, 'rm': rm diff --git a/docs/api.md b/docs/api.md index 6156ad95..50e4187c 100644 --- a/docs/api.md +++ b/docs/api.md @@ -56,6 +56,7 @@ correct value (e.g `gzip`). * stream (bool): Return a blocking generator you can iterate over to retrieve build output as it happens * timeout (int): HTTP timeout +* pull (bool): Downloads any updates to the FROM image in Dockerfiles * custom_context (bool): Optional if using `fileobj` * encoding (str): The encoding for a stream. Set to `gzip` for compressing diff --git a/tests/test.py b/tests/test.py index 38cbc2f3..fc14977e 100644 --- a/tests/test.py +++ b/tests/test.py @@ -1677,6 +1677,20 @@ class DockerClientTest(Cleanup, unittest.TestCase): except Exception as e: self.fail('Command should not raise exception: {0}'.format(e)) + def test_build_container_pull(self): + script = io.BytesIO('\n'.join([ + 'FROM busybox', + 'MAINTAINER docker-py', + 'RUN mkdir -p /tmp/test', + 'EXPOSE 8080', + 'ADD https://dl.dropboxusercontent.com/u/20637798/silence.tar.gz' + ' /tmp/silence.tar.gz' + ]).encode('ascii')) + try: + self.client.build(fileobj=script, pull=True) + except Exception as e: + self.fail('Command should not raise exception: {0}'.format(e)) + def test_build_container_stream(self): script = io.BytesIO('\n'.join([ 'FROM busybox', From 7426c52f0ee2b74d9736e0c255b1bfacb8f8f044 Mon Sep 17 00:00:00 2001 From: Derek Hammer Date: Mon, 15 Dec 2014 10:49:37 -0800 Subject: [PATCH 2/2] Fix the order of pull --- docker/client.py | 6 +++--- docs/api.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docker/client.py b/docker/client.py index 8d312138..bb27a145 100644 --- a/docker/client.py +++ b/docker/client.py @@ -408,7 +408,7 @@ class Client(requests.Session): def build(self, path=None, tag=None, quiet=False, fileobj=None, nocache=False, rm=False, stream=False, timeout=None, - pull=False, custom_context=False, encoding=None): + custom_context=False, encoding=None, pull=True): remote = context = headers = None if path is None and fileobj is None: raise TypeError("Either path or fileobj needs to be provided.") @@ -439,10 +439,10 @@ class Client(requests.Session): params = { 't': tag, 'remote': remote, - 'pull': pull, 'q': quiet, 'nocache': nocache, - 'rm': rm + 'rm': rm, + 'pull': pull } if context is not None: diff --git a/docs/api.md b/docs/api.md index 50e4187c..b49c0d59 100644 --- a/docs/api.md +++ b/docs/api.md @@ -56,9 +56,9 @@ correct value (e.g `gzip`). * stream (bool): Return a blocking generator you can iterate over to retrieve build output as it happens * timeout (int): HTTP timeout -* pull (bool): Downloads any updates to the FROM image in Dockerfiles * custom_context (bool): Optional if using `fileobj` * encoding (str): The encoding for a stream. Set to `gzip` for compressing +* pull (bool): Downloads any updates to the FROM image in Dockerfiles **Returns** (generator): A generator of the build output