Skip to content

Commit

Permalink
feat: Add label_file support to service
Browse files Browse the repository at this point in the history
Signed-off-by: Suleiman Dibirov <idsulik@gmail.com>
  • Loading branch information
idsulik committed Nov 22, 2024
1 parent 58f8cad commit c4bb361
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions override/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func init() {
mergeSpecials["services.*.dns_search"] = mergeToSequence
mergeSpecials["services.*.entrypoint"] = override
mergeSpecials["services.*.env_file"] = mergeToSequence
mergeSpecials["services.*.label_file"] = mergeToSequence
mergeSpecials["services.*.environment"] = mergeToSequence
mergeSpecials["services.*.extra_hosts"] = mergeExtraHosts
mergeSpecials["services.*.healthcheck.test"] = override
Expand Down
14 changes: 14 additions & 0 deletions override/uncity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
if pathValue, ok := value["path"]; ok {
return pathValue.(string), nil
}
return "", fmt.Errorf("label path attribute %s is missing", p)
}
return "", nil
}
1 change: 1 addition & 0 deletions paths/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func ResolveRelativePaths(project map[string]any, base string, remotes []RemoteR
"services.*.build.context": r.absContextPath,
"services.*.build.additional_contexts.*": r.absContextPath,
"services.*.env_file.*.path": r.absPath,
"services.*.label_file.*.path": r.absPath,
"services.*.extends.file": r.absExtendsPath,
"services.*.develop.watch.*.path": r.absSymbolicLink,
"services.*.volumes.*": r.absVolumeMount,
Expand Down
31 changes: 31 additions & 0 deletions schema/compose-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -852,6 +853,36 @@
},

"env_file": {
"oneOf": [
{"type": "string"},
{
"type": "array",
"items": {
"oneOf": [
{"type": "string"},
{
"type": "object",
"additionalProperties": false,
"properties": {
"path": {
"type": "string"
},
"required": {
"type": ["boolean", "string"],
"default": true
}
},
"required": [
"path"
]
}
]
}
}
]
},

"label_file": {
"oneOf": [
{"type": "string"},
{
Expand Down
1 change: 1 addition & 0 deletions transform/canonical.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func init() {
transformers["services.*.build.additional_contexts"] = transformKeyValue
transformers["services.*.depends_on"] = transformDependsOn
transformers["services.*.env_file"] = transformEnvFile
transformers["services.*.label_file"] = transformLabelFile
transformers["services.*.extends"] = transformExtends
transformers["services.*.networks"] = transformServiceNetworks
transformers["services.*.volumes.*"] = transformVolumeMount
Expand Down
1 change: 1 addition & 0 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ type ServiceConfig struct {
Ipc string `yaml:"ipc,omitempty" json:"ipc,omitempty"`
Isolation string `yaml:"isolation,omitempty" json:"isolation,omitempty"`
Labels Labels `yaml:"labels,omitempty" json:"labels,omitempty"`
LabelFiles []LabelFile `yaml:"label_file,omitempty" json:"label_file,omitempty"`

Check failure on line 92 in types/types.go

View workflow job for this annotation

GitHub Actions / test (1.22, ubuntu-latest)

undefined: LabelFile) (typecheck)

Check failure on line 92 in types/types.go

View workflow job for this annotation

GitHub Actions / test (1.22, ubuntu-latest)

undefined: LabelFile) (typecheck)

Check failure on line 92 in types/types.go

View workflow job for this annotation

GitHub Actions / test (1.22, ubuntu-latest)

undefined: LabelFile) (typecheck)

Check failure on line 92 in types/types.go

View workflow job for this annotation

GitHub Actions / test (1.22, macos-latest)

undefined: LabelFile) (typecheck)

Check failure on line 92 in types/types.go

View workflow job for this annotation

GitHub Actions / test (1.22, macos-latest)

undefined: LabelFile) (typecheck)

Check failure on line 92 in types/types.go

View workflow job for this annotation

GitHub Actions / test (1.22, macos-latest)

undefined: LabelFile) (typecheck)

Check failure on line 92 in types/types.go

View workflow job for this annotation

GitHub Actions / test (1.21, macos-latest)

undefined: LabelFile) (typecheck)

Check failure on line 92 in types/types.go

View workflow job for this annotation

GitHub Actions / test (1.21, macos-latest)

undefined: LabelFile) (typecheck)

Check failure on line 92 in types/types.go

View workflow job for this annotation

GitHub Actions / test (1.21, macos-latest)

undefined: LabelFile) (typecheck)
CustomLabels Labels `yaml:"-" json:"-"`
Links []string `yaml:"links,omitempty" json:"links,omitempty"`
Logging *LoggingConfig `yaml:"logging,omitempty" json:"logging,omitempty"`
Expand Down

0 comments on commit c4bb361

Please sign in to comment.