Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for labels during build #4735

Closed
Closed
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_schema_v3.2.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"context": {"type": "string"},
"dockerfile": {"type": "string"},
"args": {"$ref": "#/definitions/list_or_dict"},
"labels": {"$ref": "#/definitions/list_or_dict"},
"cache_from": {"$ref": "#/definitions/list_of_strings"}
},
"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 @@ -831,6 +831,7 @@ def build(self, no_cache=False, pull=False, force_rm=False, build_args_override=
nocache=no_cache,
dockerfile=build_opts.get('dockerfile', None),
cache_from=build_opts.get('cache_from', None),
labels=build_opts.get('labels', None),
buildargs=build_args
)

Expand Down
27 changes: 27 additions & 0 deletions tests/unit/config/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,33 @@ def test_load_with_buildargs(self):
assert service['build']['args']['opt1'] == '42'
assert service['build']['args']['opt2'] == 'foobar'

def test_load_with_labels(self):
service = config.load(
build_config_details(
{
'version': '3.2',
'services': {
'web': {
'build': {
'context': '.',
'dockerfile': 'Dockerfile-alt',
'labels': {
'label1': 42,
'label2': 'foobar'
}
}
}
}
},
'tests/fixtures/extends',
'filename.yml'
)
).services[0]
assert 'labels' in service['build']
assert 'label1' in service['build']['labels']
assert service['build']['labels']['label1'] == 42
assert service['build']['labels']['label2'] == 'foobar'

def test_build_args_allow_empty_properties(self):
service = config.load(
build_config_details(
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ def test_create_container(self):
nocache=False,
rm=True,
buildargs={},
labels=None,
cache_from=None,
)

Expand Down Expand Up @@ -508,6 +509,7 @@ def test_ensure_image_exists_force_build(self):
nocache=False,
rm=True,
buildargs={},
labels=None,
cache_from=None,
)

Expand Down