Merge pull request #5819 from docker/5433-build-zip

Add --compress option to build command
This commit is contained in:
Joffrey F 2018-03-27 00:52:06 +02:00 committed by GitHub
commit 771a1382bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 4 deletions

View File

@ -254,6 +254,7 @@ class TopLevelCommand(object):
Usage: build [options] [--build-arg key=val...] [SERVICE...]
Options:
--compress Compress the build context using gzip.
--force-rm Always remove intermediate containers.
--no-cache Do not use cache when building the image.
--pull Always attempt to pull a newer version of the image.
@ -277,7 +278,9 @@ class TopLevelCommand(object):
pull=bool(options.get('--pull', False)),
force_rm=bool(options.get('--force-rm', False)),
memory=options.get('--memory'),
build_args=build_args)
build_args=build_args,
gzip=options.get('--compress', False),
)
def bundle(self, options):
"""

View File

@ -366,10 +366,10 @@ class Project(object):
return containers
def build(self, service_names=None, no_cache=False, pull=False, force_rm=False, memory=None,
build_args=None):
build_args=None, gzip=False):
for service in self.get_services(service_names):
if service.can_be_built():
service.build(no_cache, pull, force_rm, memory, build_args)
service.build(no_cache, pull, force_rm, memory, build_args, gzip)
else:
log.info('%s uses an image, skipping' % service.name)

View File

@ -967,7 +967,8 @@ class Service(object):
return [build_spec(secret) for secret in self.secrets]
def build(self, no_cache=False, pull=False, force_rm=False, memory=None, build_args_override=None):
def build(self, no_cache=False, pull=False, force_rm=False, memory=None, build_args_override=None,
gzip=False):
log.info('Building %s' % self.name)
build_opts = self.options.get('build', {})
@ -1003,6 +1004,7 @@ class Service(object):
container_limits={
'memory': parse_bytes(memory) if memory else None
},
gzip=gzip
)
try:

View File

@ -1105,6 +1105,24 @@ class ServiceTest(DockerClientTestCase):
service.build()
assert service.image()
def test_build_with_gzip(self):
base_dir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, base_dir)
with open(os.path.join(base_dir, 'Dockerfile'), 'w') as f:
f.write('\n'.join([
'FROM busybox',
'COPY . /src',
'RUN cat /src/hello.txt'
]))
with open(os.path.join(base_dir, 'hello.txt'), 'w') as f:
f.write('hello world\n')
service = self.create_service('build_gzip', build={
'context': text_type(base_dir),
})
service.build(gzip=True)
assert service.image()
def test_start_container_stays_unprivileged(self):
service = self.create_service('web')
container = create_and_start_container(service).inspect()

View File

@ -487,6 +487,7 @@ class ServiceTest(unittest.TestCase):
shmsize=None,
extra_hosts=None,
container_limits={'memory': None},
gzip=False,
)
def test_ensure_image_exists_no_build(self):
@ -529,6 +530,7 @@ class ServiceTest(unittest.TestCase):
shmsize=None,
extra_hosts=None,
container_limits={'memory': None},
gzip=False
)
def test_build_does_not_pull(self):