Add support for extra_hosts in build config

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2017-10-25 14:51:11 -07:00
parent c0366b71e9
commit c5408f3a40
6 changed files with 30 additions and 3 deletions

View File

@ -1023,6 +1023,7 @@ def merge_build(output, base, override):
md.merge_mapping('args', parse_build_arguments)
md.merge_field('cache_from', merge_unique_items_lists, default=[])
md.merge_mapping('labels', parse_labels)
md.merge_mapping('extra_hosts', parse_extra_hosts)
return dict(md)

View File

@ -92,7 +92,8 @@
"cache_from": {"$ref": "#/definitions/list_of_strings"},
"network": {"type": "string"},
"target": {"type": "string"},
"shm_size": {"type": ["integer", "string"]}
"shm_size": {"type": ["integer", "string"]},
"extra_hosts": {"$ref": "#/definitions/list_or_dict"}
},
"additionalProperties": false
}

View File

@ -930,6 +930,7 @@ class Service(object):
network_mode=build_opts.get('network', None),
target=build_opts.get('target', 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:

View File

@ -833,6 +833,29 @@ class ServiceTest(DockerClientTestCase):
assert service.image()
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):
service = self.create_service('web')
container = create_and_start_container(service).inspect()

View File

@ -498,6 +498,7 @@ class ServiceTest(unittest.TestCase):
network_mode=None,
target=None,
shmsize=None,
extra_hosts=None,
)
def test_ensure_image_exists_no_build(self):
@ -538,7 +539,8 @@ class ServiceTest(unittest.TestCase):
cache_from=None,
network_mode=None,
target=None,
shmsize=None
shmsize=None,
extra_hosts=None,
)
def test_build_does_not_pull(self):

View File

@ -18,7 +18,6 @@ deps =
-rrequirements-dev.txt
commands =
py.test -v \
--full-trace \
--cov=compose \
--cov-report html \
--cov-report term \