Visitar URL original
Merge pull request #1746 from thaJeztah/carry_compose_template_driver · docker/cli@2871b72 · GitHub
Skip to content

Commit 2871b72

Browse files
authored
Merge pull request #1746 from thaJeztah/carry_compose_template_driver
[carry] Add support for `template_driver` in composefiles
2 parents e4aa87f + 7764101 commit 2871b72

5 files changed

Lines changed: 122 additions & 46 deletions

File tree

‎cli/compose/convert/compose.go‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,13 @@ func Secrets(namespace Namespace, secrets map[string]composetypes.SecretConfig)
110110
if err != nil {
111111
return nil, err
112112
}
113-
result = append(result, swarm.SecretSpec{Annotations: obj.Annotations, Data: obj.Data})
113+
spec := swarm.SecretSpec{Annotations: obj.Annotations, Data: obj.Data}
114+
if secret.TemplateDriver != "" {
115+
spec.Templating = &swarm.Driver{
116+
Name: secret.TemplateDriver,
117+
}
118+
}
119+
result = append(result, spec)
114120
}
115121
return result, nil
116122
}
@@ -127,7 +133,13 @@ func Configs(namespace Namespace, configs map[string]composetypes.ConfigObjConfi
127133
if err != nil {
128134
return nil, err
129135
}
130-
result = append(result, swarm.ConfigSpec{Annotations: obj.Annotations, Data: obj.Data})
136+
spec := swarm.ConfigSpec{Annotations: obj.Annotations, Data: obj.Data}
137+
if config.TemplateDriver != "" {
138+
spec.Templating = &swarm.Driver{
139+
Name: config.TemplateDriver,
140+
}
141+
}
142+
result = append(result, spec)
131143
}
132144
return result, nil
133145
}

‎cli/compose/loader/loader_test.go‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,3 +1484,64 @@ func TestTransform(t *testing.T) {
14841484

14851485
assert.Check(t, is.DeepEqual(samplePortsConfig, ports))
14861486
}
1487+
1488+
func TestLoadTemplateDriver(t *testing.T) {
1489+
config, err := loadYAML(`
1490+
version: '3.8'
1491+
services:
1492+
hello-world:
1493+
image: redis:alpine
1494+
secrets:
1495+
- secret
1496+
configs:
1497+
- config
1498+
1499+
configs:
1500+
config:
1501+
name: config
1502+
external: true
1503+
template_driver: config-driver
1504+
1505+
secrets:
1506+
secret:
1507+
name: secret
1508+
external: true
1509+
template_driver: secret-driver
1510+
`)
1511+
assert.NilError(t, err)
1512+
expected := &types.Config{
1513+
Filename: "filename.yml",
1514+
Version: "3.8",
1515+
Services: types.Services{
1516+
{
1517+
Name: "hello-world",
1518+
Image: "redis:alpine",
1519+
Configs: []types.ServiceConfigObjConfig{
1520+
{
1521+
Source: "config",
1522+
},
1523+
},
1524+
Secrets: []types.ServiceSecretConfig{
1525+
{
1526+
Source: "secret",
1527+
},
1528+
},
1529+
},
1530+
},
1531+
Configs: map[string]types.ConfigObjConfig{
1532+
"config": {
1533+
Name: "config",
1534+
External: types.External{External: true},
1535+
TemplateDriver: "config-driver",
1536+
},
1537+
},
1538+
Secrets: map[string]types.SecretConfig{
1539+
"secret": {
1540+
Name: "secret",
1541+
External: types.External{External: true},
1542+
TemplateDriver: "secret-driver",
1543+
},
1544+
},
1545+
}
1546+
assert.DeepEqual(t, config, expected, cmpopts.EquateEmpty())
1547+
}

‎cli/compose/schema/bindata.go‎

Lines changed: 37 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎cli/compose/schema/data/config_schema_v3.8.json‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,8 @@
537537
"name": {"type": "string"}
538538
}
539539
},
540-
"labels": {"$ref": "#/definitions/list_or_dict"}
540+
"labels": {"$ref": "#/definitions/list_or_dict"},
541+
"template_driver": {"type": "string"}
541542
},
542543
"patternProperties": {"^x-": {}},
543544
"additionalProperties": false
@@ -555,7 +556,8 @@
555556
"name": {"type": "string"}
556557
}
557558
},
558-
"labels": {"$ref": "#/definitions/list_or_dict"}
559+
"labels": {"$ref": "#/definitions/list_or_dict"},
560+
"template_driver": {"type": "string"}
559561
},
560562
"patternProperties": {"^x-": {}},
561563
"additionalProperties": false

‎cli/compose/types/types.go‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -503,11 +503,12 @@ type CredentialSpecConfig struct {
503503

504504
// FileObjectConfig is a config type for a file used by a service
505505
type FileObjectConfig struct {
506-
Name string `yaml:",omitempty" json:"name,omitempty"`
507-
File string `yaml:",omitempty" json:"file,omitempty"`
508-
External External `yaml:",omitempty" json:"external,omitempty"`
509-
Labels Labels `yaml:",omitempty" json:"labels,omitempty"`
510-
Extras map[string]interface{} `yaml:",inline" json:"-"`
506+
Name string `yaml:",omitempty" json:"name,omitempty"`
507+
File string `yaml:",omitempty" json:"file,omitempty"`
508+
External External `yaml:",omitempty" json:"external,omitempty"`
509+
Labels Labels `yaml:",omitempty" json:"labels,omitempty"`
510+
Extras map[string]interface{} `yaml:",inline" json:"-"`
511+
TemplateDriver string `mapstructure:"template_driver" yaml:"template_driver,omitempty" json:"template_driver,omitempty"`
511512
}
512513

513514
// SecretConfig for a secret

0 commit comments

Comments
 (0)