mirror of https://github.com/docker/compose.git
Merge pull request #5361 from docker/5282-build-extra-hosts
Add support for extra_hosts in build config
This commit is contained in:
commit
d48002a09d
|
@ -1023,6 +1023,7 @@ def merge_build(output, base, override):
|
||||||
md.merge_mapping('args', parse_build_arguments)
|
md.merge_mapping('args', parse_build_arguments)
|
||||||
md.merge_field('cache_from', merge_unique_items_lists, default=[])
|
md.merge_field('cache_from', merge_unique_items_lists, default=[])
|
||||||
md.merge_mapping('labels', parse_labels)
|
md.merge_mapping('labels', parse_labels)
|
||||||
|
md.merge_mapping('extra_hosts', parse_extra_hosts)
|
||||||
return dict(md)
|
return dict(md)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,8 @@
|
||||||
"cache_from": {"$ref": "#/definitions/list_of_strings"},
|
"cache_from": {"$ref": "#/definitions/list_of_strings"},
|
||||||
"network": {"type": "string"},
|
"network": {"type": "string"},
|
||||||
"target": {"type": "string"},
|
"target": {"type": "string"},
|
||||||
"shm_size": {"type": ["integer", "string"]}
|
"shm_size": {"type": ["integer", "string"]},
|
||||||
|
"extra_hosts": {"$ref": "#/definitions/list_or_dict"}
|
||||||
},
|
},
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
}
|
}
|
||||||
|
|
|
@ -930,6 +930,7 @@ class Service(object):
|
||||||
network_mode=build_opts.get('network', None),
|
network_mode=build_opts.get('network', None),
|
||||||
target=build_opts.get('target', None),
|
target=build_opts.get('target', None),
|
||||||
shmsize=parse_bytes(build_opts.get('shm_size')) if build_opts.get('shm_size') else None,
|
shmsize=parse_bytes(build_opts.get('shm_size')) if build_opts.get('shm_size') else None,
|
||||||
|
extra_hosts=build_opts.get('extra_hosts', None),
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -833,6 +833,29 @@ class ServiceTest(DockerClientTestCase):
|
||||||
assert service.image()
|
assert service.image()
|
||||||
assert service.image()['Config']['Labels']['com.docker.compose.test.target'] == 'one'
|
assert service.image()['Config']['Labels']['com.docker.compose.test.target'] == 'one'
|
||||||
|
|
||||||
|
@v2_3_only()
|
||||||
|
def test_build_with_extra_hosts(self):
|
||||||
|
self.require_api_version('1.27')
|
||||||
|
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',
|
||||||
|
'RUN ping -c1 foobar',
|
||||||
|
'RUN ping -c1 baz',
|
||||||
|
]))
|
||||||
|
|
||||||
|
service = self.create_service('build_extra_hosts', build={
|
||||||
|
'context': text_type(base_dir),
|
||||||
|
'extra_hosts': {
|
||||||
|
'foobar': '127.0.0.1',
|
||||||
|
'baz': '127.0.0.1'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
service.build()
|
||||||
|
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()
|
||||||
|
|
|
@ -498,6 +498,7 @@ class ServiceTest(unittest.TestCase):
|
||||||
network_mode=None,
|
network_mode=None,
|
||||||
target=None,
|
target=None,
|
||||||
shmsize=None,
|
shmsize=None,
|
||||||
|
extra_hosts=None,
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_ensure_image_exists_no_build(self):
|
def test_ensure_image_exists_no_build(self):
|
||||||
|
@ -538,7 +539,8 @@ class ServiceTest(unittest.TestCase):
|
||||||
cache_from=None,
|
cache_from=None,
|
||||||
network_mode=None,
|
network_mode=None,
|
||||||
target=None,
|
target=None,
|
||||||
shmsize=None
|
shmsize=None,
|
||||||
|
extra_hosts=None,
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_build_does_not_pull(self):
|
def test_build_does_not_pull(self):
|
||||||
|
|
Loading…
Reference in New Issue