Merge pull request #1746 from thaJeztah/carry_compose_template_driver

[carry] Add support for `template_driver` in composefiles
This commit is contained in:
Vincent Demeester 2019-03-19 08:09:27 +01:00 committed by GitHub
commit 2871b723ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 122 additions and 46 deletions

View File

@ -110,7 +110,13 @@ func Secrets(namespace Namespace, secrets map[string]composetypes.SecretConfig)
if err != nil { if err != nil {
return nil, err return nil, err
} }
result = append(result, swarm.SecretSpec{Annotations: obj.Annotations, Data: obj.Data}) spec := swarm.SecretSpec{Annotations: obj.Annotations, Data: obj.Data}
if secret.TemplateDriver != "" {
spec.Templating = &swarm.Driver{
Name: secret.TemplateDriver,
}
}
result = append(result, spec)
} }
return result, nil return result, nil
} }
@ -127,7 +133,13 @@ func Configs(namespace Namespace, configs map[string]composetypes.ConfigObjConfi
if err != nil { if err != nil {
return nil, err return nil, err
} }
result = append(result, swarm.ConfigSpec{Annotations: obj.Annotations, Data: obj.Data}) spec := swarm.ConfigSpec{Annotations: obj.Annotations, Data: obj.Data}
if config.TemplateDriver != "" {
spec.Templating = &swarm.Driver{
Name: config.TemplateDriver,
}
}
result = append(result, spec)
} }
return result, nil return result, nil
} }

View File

@ -1484,3 +1484,64 @@ func TestTransform(t *testing.T) {
assert.Check(t, is.DeepEqual(samplePortsConfig, ports)) assert.Check(t, is.DeepEqual(samplePortsConfig, ports))
} }
func TestLoadTemplateDriver(t *testing.T) {
config, err := loadYAML(`
version: '3.8'
services:
hello-world:
image: redis:alpine
secrets:
- secret
configs:
- config
configs:
config:
name: config
external: true
template_driver: config-driver
secrets:
secret:
name: secret
external: true
template_driver: secret-driver
`)
assert.NilError(t, err)
expected := &types.Config{
Filename: "filename.yml",
Version: "3.8",
Services: types.Services{
{
Name: "hello-world",
Image: "redis:alpine",
Configs: []types.ServiceConfigObjConfig{
{
Source: "config",
},
},
Secrets: []types.ServiceSecretConfig{
{
Source: "secret",
},
},
},
},
Configs: map[string]types.ConfigObjConfig{
"config": {
Name: "config",
External: types.External{External: true},
TemplateDriver: "config-driver",
},
},
Secrets: map[string]types.SecretConfig{
"secret": {
Name: "secret",
External: types.External{External: true},
TemplateDriver: "secret-driver",
},
},
}
assert.DeepEqual(t, config, expected, cmpopts.EquateEmpty())
}

View File

@ -510,45 +510,45 @@ bnBpPlHfjORjkTRf1wyAwiYqMXd9/G6313QfoXs6/sbZ66r6e179PwAA//8ZL3SpvkUAAA==
"/data/config_schema_v3.8.json": { "/data/config_schema_v3.8.json": {
local: "data/config_schema_v3.8.json", local: "data/config_schema_v3.8.json",
size: 17912, size: 18006,
modtime: 1518458244, modtime: 1518458244,
compressed: ` compressed: `
H4sIAAAAAAAC/+xcS4/bOBK++1cImrlNPwLsYLGb2x73tHvehiPQVNnmNEVyipTTTuD/vtCzJYoUaVtO H4sIAAAAAAAC/+xcS4/juBG++1cI2r1tPwbIIkjmlmNOyTkNj0BTZZvbFMktUp72DvzfAz1bokiRtuXu
dzAdIEi3VHzUk18VS/m+SpL0V033UJD0c5LujVGfHx//0FLcN08fJO4ecyRbc//p98fm2S/pXTWO5dUQ 3qQHGEy3VHwU68GvHpofqyRJf9Z0DwVJvybp3hj19fHxNy3FffP0QeLuMUeyNfdffn1snv2U3lXjWF4N
KsWW7bLmTXb428M/HqrhDYk5KqiI5OYPoKZ5hvBnyRCqwU/pAVAzKdL13ap6p1AqQMNAp5+TanNJ0pN0 oVJs2S5r3mSHvzz87aEa3pCYo4KKSG5+A2qaZwi/lwyhGvyUHgA1kyJd362qdwqlAjQMdPo1qTaXJD1J
DwbTaoNM7NL68ameIUlSDXhgdDBDv9VfHl/nf+zJ7uxZB5utnytiDKD473Rv9esvT+T+27/u//fp/p8P 92AwrTbIxC6tH5/qGZIk1YAHRgcz9Fv96fF1/see7M6edbDZ+rkixgCKf0/3Vr/+9kTu//jH/X++3P/9
2f36t19Hryv5Imyb5XPYMsEMk6JfP+0pT+1Pp35hkuc1MeGjtbeEaxjzLMB8lfgc4rkneyOe2/Ud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Xe5I7frzfRo9akvZd31slpHq9jrGMvtv66q2deWrvIbMYbQfVSl7syCyQ8ofE4K Umeo8RG8brkRngT3jb3ucldu15vpkepTn8q6689qHS1ir2Est/86q2aXLV3pN2IMofuoTN2ZCZM3SHxO
/c6Q1lJ9RLQzItrPbv/vz1bbr1GDXzzWVOEPSK+w0IhvRN6B/n8StU4OYadaW6oPtf4sarXadQbqnV4b Ev1Ol9ZSfXq0Mzzan13/P56utl+jBr94rKnCH5BeoaER34h8APkvIdZRBaBQnBjIZuzzDbRgcmc7taCl
zUk8uqd4Nbwl6rdhkzn+TwlfhuXdlO+S01q0FfY85wueWw+/zSDZud7/G0HABRol3Tq1ii+rvi3S/iTe +tSC/1EtsJqBBtowLUrNCSi6Y3k1rEH127DJHP9jhS9+827KV0K1Fm1lM8/5grfiwy8zOHnuy4IbAcwF
H0u68ZMP5Cs+xXFyrfl93BrTfNy+HsnHImm+yxkAhXVUYu76bN5uzOk+X/f0Co6z11X197T6fwAAAP// 2jDdMrVSO6u+6dL+4N7verrxk8/vKz7FcVI0/TFuvGk+nV+Pzsciab76GcCQdVTY7/oo32776T6O93Qi
yYJltPhFAAA= jmPjVfX3tPpvAAAA//+mJNa5VkYAAA==
`, `,
}, },

View File

@ -537,7 +537,8 @@
"name": {"type": "string"} "name": {"type": "string"}
} }
}, },
"labels": {"$ref": "#/definitions/list_or_dict"} "labels": {"$ref": "#/definitions/list_or_dict"},
"template_driver": {"type": "string"}
}, },
"patternProperties": {"^x-": {}}, "patternProperties": {"^x-": {}},
"additionalProperties": false "additionalProperties": false
@ -555,7 +556,8 @@
"name": {"type": "string"} "name": {"type": "string"}
} }
}, },
"labels": {"$ref": "#/definitions/list_or_dict"} "labels": {"$ref": "#/definitions/list_or_dict"},
"template_driver": {"type": "string"}
}, },
"patternProperties": {"^x-": {}}, "patternProperties": {"^x-": {}},
"additionalProperties": false "additionalProperties": false

View File

@ -508,6 +508,7 @@ type FileObjectConfig struct {
External External `yaml:",omitempty" json:"external,omitempty"` External External `yaml:",omitempty" json:"external,omitempty"`
Labels Labels `yaml:",omitempty" json:"labels,omitempty"` Labels Labels `yaml:",omitempty" json:"labels,omitempty"`
Extras map[string]interface{} `yaml:",inline" json:"-"` Extras map[string]interface{} `yaml:",inline" json:"-"`
TemplateDriver string `mapstructure:"template_driver" yaml:"template_driver,omitempty" json:"template_driver,omitempty"`
} }
// SecretConfig for a secret // SecretConfig for a secret