Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compose/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,7 @@ def to_dict(service):
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)


Expand Down
3 changes: 2 additions & 1 deletion compose/config/config_schema_v2.3.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions compose/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,7 @@ def build(self, no_cache=False, pull=False, force_rm=False, build_args_override=
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:
Expand Down
23 changes: 23 additions & 0 deletions tests/integration/service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,29 @@ def test_build_with_target(self):
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()
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ def test_create_container(self):
network_mode=None,
target=None,
shmsize=None,
extra_hosts=None,
)

def test_ensure_image_exists_no_build(self):
Expand Down Expand Up @@ -538,7 +539,8 @@ def test_ensure_image_exists_force_build(self):
cache_from=None,
network_mode=None,
target=None,
shmsize=None
shmsize=None,
extra_hosts=None,
)

def test_build_does_not_pull(self):
Expand Down
1 change: 0 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ deps =
-rrequirements-dev.txt
commands =
py.test -v \
--full-trace \
--cov=compose \
--cov-report html \
--cov-report term \
Expand Down