Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request moby#5 from aanand/hostname
WIP: support hostname
- Loading branch information
Showing
79 changed files
with
7,560 additions
and
1,829 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
package: . | ||
import: | ||
- package: github.com/mattn/go-shellwords | ||
- package: github.com/stretchr/testify | ||
- package: github.com/xeipuuv/gojsonreference | ||
- package: github.com/xeipuuv/gojsonschema | ||
- package: gopkg.in/yaml.v2 | ||
- package: github.com/docker/go-units | ||
- package: github.com/mattn/go-shellwords | ||
- package: github.com/stretchr/testify | ||
- package: github.com/xeipuuv/gojsonreference | ||
- package: github.com/xeipuuv/gojsonschema | ||
- package: gopkg.in/yaml.v2 | ||
- package: github.com/docker/go-units | ||
- package: github.com/mitchellh/mapstructure |
89 changes: 89 additions & 0 deletions
89
vendor/src/github.com/aanand/compose-file/interpolation/interpolation.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package interpolation | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aanand/compose-file/template" | ||
"github.com/aanand/compose-file/types" | ||
) | ||
|
||
func Interpolate(config types.Dict, section string, mapping template.Mapping) (types.Dict, error) { | ||
out := types.Dict{} | ||
|
||
for name, item := range config { | ||
if item == nil { | ||
out[name] = nil | ||
continue | ||
} | ||
interpolatedItem, err := interpolateSectionItem(name, item.(types.Dict), section, mapping) | ||
if err != nil { | ||
return nil, err | ||
} | ||
out[name] = interpolatedItem | ||
} | ||
|
||
return out, nil | ||
} | ||
|
||
func interpolateSectionItem( | ||
name string, | ||
item types.Dict, | ||
section string, | ||
mapping template.Mapping, | ||
) (types.Dict, error) { | ||
|
||
out := types.Dict{} | ||
|
||
for key, value := range item { | ||
interpolatedValue, err := recursiveInterpolate(value, mapping) | ||
if err != nil { | ||
return nil, fmt.Errorf( | ||
"Invalid interpolation format for %#v option in %s %#v: %#v", | ||
key, section, name, err.Template, | ||
) | ||
} | ||
out[key] = interpolatedValue | ||
} | ||
|
||
return out, nil | ||
|
||
} | ||
|
||
func recursiveInterpolate( | ||
value interface{}, | ||
mapping template.Mapping, | ||
) (interface{}, *template.InvalidTemplateError) { | ||
|
||
switch value := value.(type) { | ||
|
||
case string: | ||
return template.Substitute(value, mapping) | ||
|
||
case types.Dict: | ||
out := types.Dict{} | ||
for key, elem := range value { | ||
interpolatedElem, err := recursiveInterpolate(elem, mapping) | ||
if err != nil { | ||
return nil, err | ||
} | ||
out[key] = interpolatedElem | ||
} | ||
return out, nil | ||
|
||
case []interface{}: | ||
out := make([]interface{}, len(value)) | ||
for i, elem := range value { | ||
interpolatedElem, err := recursiveInterpolate(elem, mapping) | ||
if err != nil { | ||
return nil, err | ||
} | ||
out[i] = interpolatedElem | ||
} | ||
return out, nil | ||
|
||
default: | ||
return value, nil | ||
|
||
} | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
vendor/src/github.com/aanand/compose-file/interpolation/interpolation_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package interpolation | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/aanand/compose-file/types" | ||
) | ||
|
||
var defaults = map[string]string{ | ||
"USER": "jenny", | ||
"FOO": "bar", | ||
} | ||
|
||
func defaultMapping(name string) (string, bool) { | ||
val, ok := defaults[name] | ||
return val, ok | ||
} | ||
|
||
func TestInterpolate(t *testing.T) { | ||
services := types.Dict{ | ||
"servicea": types.Dict{ | ||
"image": "example:${USER}", | ||
"volumes": []interface{}{"$FOO:/target"}, | ||
"logging": types.Dict{ | ||
"driver": "${FOO}", | ||
"options": types.Dict{ | ||
"user": "$USER", | ||
}, | ||
}, | ||
}, | ||
} | ||
expected := types.Dict{ | ||
"servicea": types.Dict{ | ||
"image": "example:jenny", | ||
"volumes": []interface{}{"bar:/target"}, | ||
"logging": types.Dict{ | ||
"driver": "bar", | ||
"options": types.Dict{ | ||
"user": "jenny", | ||
}, | ||
}, | ||
}, | ||
} | ||
result, err := Interpolate(services, "service", defaultMapping) | ||
assert.NoError(t, err) | ||
assert.Equal(t, expected, result) | ||
} | ||
|
||
func TestInvalidInterpolation(t *testing.T) { | ||
services := types.Dict{ | ||
"servicea": types.Dict{ | ||
"image": "${", | ||
}, | ||
} | ||
_, err := Interpolate(services, "service", defaultMapping) | ||
assert.EqualError(t, err, `Invalid interpolation format for "image" option in service "servicea": "${"`) | ||
} |
Oops, something went wrong.