mirror of https://github.com/docker/compose.git
Merge pull request #5819 from docker/5433-build-zip
Add --compress option to build command
This commit is contained in:
commit
771a1382bd
|
@ -254,6 +254,7 @@ class TopLevelCommand(object):
|
||||||
Usage: build [options] [--build-arg key=val...] [SERVICE...]
|
Usage: build [options] [--build-arg key=val...] [SERVICE...]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
|
--compress Compress the build context using gzip.
|
||||||
--force-rm Always remove intermediate containers.
|
--force-rm Always remove intermediate containers.
|
||||||
--no-cache Do not use cache when building the image.
|
--no-cache Do not use cache when building the image.
|
||||||
--pull Always attempt to pull a newer version of 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)),
|
pull=bool(options.get('--pull', False)),
|
||||||
force_rm=bool(options.get('--force-rm', False)),
|
force_rm=bool(options.get('--force-rm', False)),
|
||||||
memory=options.get('--memory'),
|
memory=options.get('--memory'),
|
||||||
build_args=build_args)
|
build_args=build_args,
|
||||||
|
gzip=options.get('--compress', False),
|
||||||
|
)
|
||||||
|
|
||||||
def bundle(self, options):
|
def bundle(self, options):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -366,10 +366,10 @@ class Project(object):
|
||||||
return containers
|
return containers
|
||||||
|
|
||||||
def build(self, service_names=None, no_cache=False, pull=False, force_rm=False, memory=None,
|
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):
|
for service in self.get_services(service_names):
|
||||||
if service.can_be_built():
|
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:
|
else:
|
||||||
log.info('%s uses an image, skipping' % service.name)
|
log.info('%s uses an image, skipping' % service.name)
|
||||||
|
|
||||||
|
|
|
@ -967,7 +967,8 @@ class Service(object):
|
||||||
|
|
||||||
return [build_spec(secret) for secret in self.secrets]
|
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)
|
log.info('Building %s' % self.name)
|
||||||
|
|
||||||
build_opts = self.options.get('build', {})
|
build_opts = self.options.get('build', {})
|
||||||
|
@ -1003,6 +1004,7 @@ class Service(object):
|
||||||
container_limits={
|
container_limits={
|
||||||
'memory': parse_bytes(memory) if memory else None
|
'memory': parse_bytes(memory) if memory else None
|
||||||
},
|
},
|
||||||
|
gzip=gzip
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -1105,6 +1105,24 @@ class ServiceTest(DockerClientTestCase):
|
||||||
service.build()
|
service.build()
|
||||||
assert service.image()
|
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):
|
def test_start_container_stays_unprivileged(self):
|
||||||
service = self.create_service('web')
|
service = self.create_service('web')
|
||||||
container = create_and_start_container(service).inspect()
|
container = create_and_start_container(service).inspect()
|
||||||
|
|
|
@ -487,6 +487,7 @@ class ServiceTest(unittest.TestCase):
|
||||||
shmsize=None,
|
shmsize=None,
|
||||||
extra_hosts=None,
|
extra_hosts=None,
|
||||||
container_limits={'memory': None},
|
container_limits={'memory': None},
|
||||||
|
gzip=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_ensure_image_exists_no_build(self):
|
def test_ensure_image_exists_no_build(self):
|
||||||
|
@ -529,6 +530,7 @@ class ServiceTest(unittest.TestCase):
|
||||||
shmsize=None,
|
shmsize=None,
|
||||||
extra_hosts=None,
|
extra_hosts=None,
|
||||||
container_limits={'memory': None},
|
container_limits={'memory': None},
|
||||||
|
gzip=False
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_build_does_not_pull(self):
|
def test_build_does_not_pull(self):
|
||||||
|
|
Loading…
Reference in New Issue