-
Notifications
You must be signed in to change notification settings - Fork 114
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
feat: Add label_file support to service #713
Changes from 8 commits
7a2f9a9
e608b09
b378ecd
457e8f0
88f1ac2
c697f13
88117ef
eeda727
9831427
381733b
ccf14e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# passed through | ||
FOO=foo_from_label_file | ||
LABEL.WITH.DOT=ok | ||
LABEL_WITH_UNDERSCORE=ok | ||
|
||
# overridden in example2.label | ||
BAR=bar_from_label_file | ||
|
||
# overridden in full-example.yml | ||
BAZ=baz_from_label_file |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
BAR=bar_from_label_file_2 | ||
|
||
# overridden in configDetails.Labels | ||
QUX=quz_from_label_file_2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ func init() { | |
unique["services.*.env_file"] = envFileIndexer | ||
unique["services.*.expose"] = exposeIndexer | ||
unique["services.*.labels"] = keyValueIndexer | ||
unique["services.*.label_file"] = labelFileIndexer | ||
unique["services.*.links"] = keyValueIndexer | ||
unique["services.*.networks.*.aliases"] = keyValueIndexer | ||
unique["services.*.networks.*.link_local_ips"] = keyValueIndexer | ||
|
@@ -227,3 +228,16 @@ func envFileIndexer(y any, p tree.Path) (string, error) { | |
} | ||
return "", nil | ||
} | ||
|
||
func labelFileIndexer(y any, p tree.Path) (string, error) { | ||
switch value := y.(type) { | ||
case string: | ||
return value, nil | ||
case map[string]any: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not relevant anymore AFAICT |
||
if pathValue, ok := value["path"]; ok { | ||
return pathValue.(string), nil | ||
} | ||
return "", fmt.Errorf("label path attribute %s is missing", p) | ||
} | ||
return "", nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,6 +240,7 @@ | |
"domainname": {"type": "string"}, | ||
"entrypoint": {"$ref": "#/definitions/command"}, | ||
"env_file": {"$ref": "#/definitions/env_file"}, | ||
"label_file": {"$ref": "#/definitions/label_file"}, | ||
"environment": {"$ref": "#/definitions/list_or_dict"}, | ||
|
||
"expose": { | ||
|
@@ -866,9 +867,6 @@ | |
"path": { | ||
"type": "string" | ||
}, | ||
"format": { | ||
"type": "string" | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this removal intentional ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, you wrote to make it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure, but here you removed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, accidentally deleted it, put it back |
||
"required": { | ||
"type": ["boolean", "string"], | ||
"default": true | ||
|
@@ -884,6 +882,16 @@ | |
] | ||
}, | ||
|
||
"label_file": { | ||
"oneOf": [ | ||
{"type": "string"}, | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds to me this is a premature feature to add support for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ndeloof agree, fixed |
||
"type": "array", | ||
"items": {"type": "string"} | ||
} | ||
] | ||
}, | ||
|
||
"string_or_list": { | ||
"oneOf": [ | ||
{"type": "string"}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
Copyright 2020 The Compose Specification Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package transform | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/compose-spec/compose-go/v2/tree" | ||
) | ||
|
||
func transformLabelFile(data any, p tree.Path, _ bool) (any, error) { | ||
switch v := data.(type) { | ||
case string: | ||
return []any{ | ||
transformLabelFileValue(v), | ||
}, nil | ||
case []any: | ||
for i, e := range v { | ||
v[i] = transformLabelFileValue(e) | ||
} | ||
return v, nil | ||
default: | ||
return nil, fmt.Errorf("%s: invalid type %T for label_file", p, v) | ||
} | ||
} | ||
|
||
func transformLabelFileValue(data any) any { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not relevant anymore |
||
switch v := data.(type) { | ||
case string: | ||
return map[string]any{ | ||
"path": v, | ||
"required": true, | ||
} | ||
case map[string]any: | ||
if _, ok := v["required"]; !ok { | ||
v["required"] = true | ||
} | ||
return v | ||
} | ||
return nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
Copyright 2020 The Compose Specification Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package types | ||
|
||
import ( | ||
"encoding/json" | ||
) | ||
|
||
type LabelFile struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unused ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, thank you, removed |
||
Path string `yaml:"path,omitempty" json:"path,omitempty"` | ||
Format string `yaml:"format,omitempty" json:"format,omitempty"` | ||
} | ||
|
||
// MarshalYAML makes LabelFile implement yaml.Marshaler | ||
func (e LabelFile) MarshalYAML() (interface{}, error) { | ||
return e.Path, nil | ||
} | ||
|
||
// MarshalJSON makes LabelFile implement json.Marshaler | ||
func (e *LabelFile) MarshalJSON() ([]byte, error) { | ||
return json.Marshal(e.Path) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI this huge test we inherited from legacy compose parser in docker/cli.
As it is painful to maintain, we prefer to have individual test checking specific attribute is well supported (which you also provided 🥳)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should I revert these changes or keep them?