Fix loader error with different build syntax

`build: .` was not working anymore. Fixing this by adding a new
tranform function for BuildConfig.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
Vincent Demeester 2017-09-20 11:42:08 +02:00
parent bd31cb4bd5
commit 0da9f14821
No known key found for this signature in database
GPG Key ID: 083CC6FD6EB699A3
2 changed files with 32 additions and 0 deletions

View File

@ -221,6 +221,7 @@ func createTransformHook() mapstructure.DecodeHookFuncType {
reflect.TypeOf(types.Labels{}): transformMappingOrListFunc("=", false), reflect.TypeOf(types.Labels{}): transformMappingOrListFunc("=", false),
reflect.TypeOf(types.MappingWithColon{}): transformMappingOrListFunc(":", false), reflect.TypeOf(types.MappingWithColon{}): transformMappingOrListFunc(":", false),
reflect.TypeOf(types.ServiceVolumeConfig{}): transformServiceVolumeConfig, reflect.TypeOf(types.ServiceVolumeConfig{}): transformServiceVolumeConfig,
reflect.TypeOf(types.BuildConfig{}): transformBuildConfig,
} }
return func(_ reflect.Type, target reflect.Type, data interface{}) (interface{}, error) { return func(_ reflect.Type, target reflect.Type, data interface{}) (interface{}, error) {
@ -563,6 +564,17 @@ func transformStringSourceMap(data interface{}) (interface{}, error) {
} }
} }
func transformBuildConfig(data interface{}) (interface{}, error) {
switch value := data.(type) {
case string:
return map[string]interface{}{"context": value}, nil
case map[string]interface{}:
return data, nil
default:
return data, errors.Errorf("invalid type %T for service build", value)
}
}
func transformServiceVolumeConfig(data interface{}) (interface{}, error) { func transformServiceVolumeConfig(data interface{}) (interface{}, error) {
switch value := data.(type) { switch value := data.(type) {
case string: case string:

View File

@ -528,6 +528,26 @@ services:
assert.Equal(t, []string{"build", "links"}, unsupported) assert.Equal(t, []string{"build", "links"}, unsupported)
} }
func TestBuildProperties(t *testing.T) {
dict, err := ParseYAML([]byte(`
version: "3"
services:
web:
image: web
build: .
links:
- bar
db:
image: db
build:
context: ./db
`))
require.NoError(t, err)
configDetails := buildConfigDetails(dict, nil)
_, err = Load(configDetails)
require.NoError(t, err)
}
func TestDeprecatedProperties(t *testing.T) { func TestDeprecatedProperties(t *testing.T) {
dict, err := ParseYAML([]byte(` dict, err := ParseYAML([]byte(`
version: "3" version: "3"