From ab21746d8f988af474f251792a39fcccd98839cc Mon Sep 17 00:00:00 2001 From: Ronald van Zantvoort Date: Sat, 24 Feb 2018 13:07:29 +0100 Subject: build_prune Signed-off-by: Ronald van Zantvoort --- docker/api/build.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'docker/api/build.py') diff --git a/docker/api/build.py b/docker/api/build.py index 56f1fcf..62b92c9 100644 --- a/docker/api/build.py +++ b/docker/api/build.py @@ -292,3 +292,19 @@ class BuildApiMixin(object): ) else: log.debug('No auth config found') + + @utils.minimum_version('1.31') + def prune_build(self): + """ + Delete builder cache + + Returns: + (dict): A dict containing + the amount of disk space reclaimed in bytes. + + Raises: + :py:class:`docker.errors.APIError` + If the server returns an error. + """ + url = self._url("/build/prune") + return self._result(self._post(url), True) -- cgit v1.2.1 From c88db80f01ebef002d3bf9aca49ce273b46c6928 Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Thu, 22 Mar 2018 09:51:10 +0100 Subject: Add isolation param to build Signed-off-by: Joffrey F --- docker/api/build.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'docker/api/build.py') diff --git a/docker/api/build.py b/docker/api/build.py index e136a6e..3067c10 100644 --- a/docker/api/build.py +++ b/docker/api/build.py @@ -18,7 +18,7 @@ class BuildApiMixin(object): forcerm=False, dockerfile=None, container_limits=None, decode=False, buildargs=None, gzip=False, shmsize=None, labels=None, cache_from=None, target=None, network_mode=None, - squash=None, extra_hosts=None, platform=None): + squash=None, extra_hosts=None, platform=None, isolation=None): """ Similar to the ``docker build`` command. Either ``path`` or ``fileobj`` needs to be set. ``path`` can be a local path (to a directory @@ -100,6 +100,8 @@ class BuildApiMixin(object): extra_hosts (dict): Extra hosts to add to /etc/hosts in building containers, as a mapping of hostname to IP address. platform (str): Platform in the format ``os[/arch[/variant]]`` + isolation (str): Isolation technology used during build. + Default: `None`. Returns: A generator for the build output. @@ -232,6 +234,13 @@ class BuildApiMixin(object): ) params['platform'] = platform + if isolation is not None: + if utils.version_lt(self._version, '1.24'): + raise errors.InvalidVersion( + 'isolation was only introduced in API version 1.24' + ) + params['isolation'] = isolation + if context is not None: headers = {'Content-Type': 'application/tar'} if encoding: -- cgit v1.2.1 From 081b78f15e9a7d3702dd61fa9f01c3babf61a819 Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Mon, 26 Mar 2018 13:36:45 -0700 Subject: Support building with Dockerfile outside of context Signed-off-by: Joffrey F --- docker/api/build.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'docker/api/build.py') diff --git a/docker/api/build.py b/docker/api/build.py index 3067c10..2a22759 100644 --- a/docker/api/build.py +++ b/docker/api/build.py @@ -1,6 +1,7 @@ import json import logging import os +import random from .. import auth from .. import constants @@ -148,6 +149,15 @@ class BuildApiMixin(object): lambda x: x != '' and x[0] != '#', [l.strip() for l in f.read().splitlines()] )) + if dockerfile and os.path.relpath(dockerfile, path).startswith( + '..'): + with open(dockerfile, 'r') as df: + dockerfile = ( + '.dockerfile.{0:x}'.format(random.getrandbits(160)), + df.read() + ) + else: + dockerfile = (dockerfile, None) context = utils.tar( path, exclude=exclude, dockerfile=dockerfile, gzip=gzip ) -- cgit v1.2.1 From 16751ac509b4bbe75293847fe87099ff51a74013 Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Fri, 30 Mar 2018 10:22:39 -0700 Subject: Properly handle relative Dockerfile paths and Dockerfile on different drives Signed-off-by: Joffrey F --- docker/api/build.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'docker/api/build.py') diff --git a/docker/api/build.py b/docker/api/build.py index 2a22759..d69985e 100644 --- a/docker/api/build.py +++ b/docker/api/build.py @@ -149,15 +149,7 @@ class BuildApiMixin(object): lambda x: x != '' and x[0] != '#', [l.strip() for l in f.read().splitlines()] )) - if dockerfile and os.path.relpath(dockerfile, path).startswith( - '..'): - with open(dockerfile, 'r') as df: - dockerfile = ( - '.dockerfile.{0:x}'.format(random.getrandbits(160)), - df.read() - ) - else: - dockerfile = (dockerfile, None) + dockerfile = process_dockerfile(dockerfile, path) context = utils.tar( path, exclude=exclude, dockerfile=dockerfile, gzip=gzip ) @@ -312,3 +304,22 @@ class BuildApiMixin(object): ) else: log.debug('No auth config found') + + +def process_dockerfile(dockerfile, path): + if not dockerfile: + return (None, None) + + abs_dockerfile = dockerfile + if not os.path.isabs(dockerfile): + abs_dockerfile = os.path.join(path, dockerfile) + + if (os.path.splitdrive(path)[0] != os.path.splitdrive(abs_dockerfile)[0] or + os.path.relpath(abs_dockerfile, path).startswith('..')): + with open(abs_dockerfile, 'r') as df: + return ( + '.dockerfile.{0:x}'.format(random.getrandbits(160)), + df.read() + ) + else: + return (dockerfile, None) -- cgit v1.2.1 From 1d6f8ecf9277ef1c77f3d530efaafd39323cc8e7 Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Thu, 12 Apr 2018 12:38:27 -0700 Subject: Support absolute paths for in-context Dockerfiles Signed-off-by: Joffrey F --- docker/api/build.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'docker/api/build.py') diff --git a/docker/api/build.py b/docker/api/build.py index d69985e..a76e32c 100644 --- a/docker/api/build.py +++ b/docker/api/build.py @@ -316,10 +316,12 @@ def process_dockerfile(dockerfile, path): if (os.path.splitdrive(path)[0] != os.path.splitdrive(abs_dockerfile)[0] or os.path.relpath(abs_dockerfile, path).startswith('..')): + # Dockerfile not in context - read data to insert into tar later with open(abs_dockerfile, 'r') as df: return ( '.dockerfile.{0:x}'.format(random.getrandbits(160)), df.read() ) - else: - return (dockerfile, None) + + # Dockerfile is inside the context - return path relative to context root + return (os.path.relpath(abs_dockerfile, path), None) -- cgit v1.2.1 From 8360ecae973a84bbd203cfe145657618a5659415 Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Wed, 25 Apr 2018 16:29:41 -0700 Subject: prune_builds test Signed-off-by: Joffrey F --- docker/api/build.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'docker/api/build.py') diff --git a/docker/api/build.py b/docker/api/build.py index 3d83b98..f62a731 100644 --- a/docker/api/build.py +++ b/docker/api/build.py @@ -264,6 +264,23 @@ class BuildApiMixin(object): return self._stream_helper(response, decode=decode) + @utils.minimum_version('1.31') + def prune_builds(self): + """ + Delete the builder cache + + Returns: + (dict): A dictionary containing information about the operation's + result. The ``SpaceReclaimed`` key indicates the amount of + bytes of disk space reclaimed. + + Raises: + :py:class:`docker.errors.APIError` + If the server returns an error. + """ + url = self._url("/build/prune") + return self._result(self._post(url), True) + def _set_auth_headers(self, headers): log.debug('Looking for auth config') @@ -305,22 +322,6 @@ class BuildApiMixin(object): else: log.debug('No auth config found') - @utils.minimum_version('1.31') - def prune_build(self): - """ - Delete builder cache - - Returns: - (dict): A dict containing - the amount of disk space reclaimed in bytes. - - Raises: - :py:class:`docker.errors.APIError` - If the server returns an error. - """ - url = self._url("/build/prune") - return self._result(self._post(url), True) - def process_dockerfile(dockerfile, path): if not dockerfile: -- cgit v1.2.1 From 17f41b56726957177724711b5bff6d51b02e6d93 Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Thu, 24 May 2018 17:19:18 -0700 Subject: Avoid unwanted modification of dockerfile path Signed-off-by: Joffrey F --- docker/api/build.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'docker/api/build.py') diff --git a/docker/api/build.py b/docker/api/build.py index f62a731..3c3f130 100644 --- a/docker/api/build.py +++ b/docker/api/build.py @@ -341,4 +341,9 @@ def process_dockerfile(dockerfile, path): ) # Dockerfile is inside the context - return path relative to context root - return (os.path.relpath(abs_dockerfile, path), None) + if dockerfile == abs_dockerfile: + # Only calculate relpath if necessary to avoid errors + # on Windows client -> Linux Docker + # see https://github.com/docker/compose/issues/5969 + dockerfile = os.path.relpath(abs_dockerfile, path) + return (dockerfile, None) -- cgit v1.2.1 From f1189bfb4b1f2ecb6adc77f7349a085bdca1a824 Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Fri, 8 Jun 2018 15:14:06 -0700 Subject: Allow passing of env overrides to credstore through APIClient ctor Signed-off-by: Joffrey F --- docker/api/build.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'docker/api/build.py') diff --git a/docker/api/build.py b/docker/api/build.py index 3c3f130..419255f 100644 --- a/docker/api/build.py +++ b/docker/api/build.py @@ -302,7 +302,8 @@ class BuildApiMixin(object): # credentials/native_store.go#L68-L83 for registry in self._auth_configs.get('auths', {}).keys(): auth_data[registry] = auth.resolve_authconfig( - self._auth_configs, registry + self._auth_configs, registry, + credstore_env=self.credstore_env, ) else: auth_data = self._auth_configs.get('auths', {}).copy() -- cgit v1.2.1