diff --git a/loader/full-example.yml b/loader/full-example.yml index 2ae6c48f9..585c31b7e 100644 --- a/loader/full-example.yml +++ b/loader/full-example.yml @@ -160,8 +160,8 @@ services: # somehost: "162.242.195.82" # otherhost: "50.31.209.229" extra_hosts: - - "somehost:162.242.195.82" - "otherhost:50.31.209.229" + - "somehost:162.242.195.82" hostname: foo diff --git a/loader/full-struct_test.go b/loader/full-struct_test.go index 80d92181e..263ef22fe 100644 --- a/loader/full-struct_test.go +++ b/loader/full-struct_test.go @@ -716,8 +716,8 @@ services: - project_db_1:mysql - project_db_1:postgresql extra_hosts: - otherhost: 50.31.209.229 - somehost: 162.242.195.82 + - otherhost:50.31.209.229 + - somehost:162.242.195.82 hostname: foo healthcheck: test: @@ -1302,10 +1302,10 @@ func fullExampleJSON(workingDir, homeDir string) string { "project_db_1:mysql", "project_db_1:postgresql" ], - "extra_hosts": { - "otherhost": "50.31.209.229", - "somehost": "162.242.195.82" - }, + "extra_hosts": [ + "otherhost:50.31.209.229", + "somehost:162.242.195.82" + ], "hostname": "foo", "healthcheck": { "test": [ diff --git a/types/types.go b/types/types.go index b01167ba0..78f12ccdd 100644 --- a/types/types.go +++ b/types/types.go @@ -354,12 +354,12 @@ type ThrottleDevice struct { // ShellCommand is a string or list of string args. // // When marshaled to YAML, nil command fields will be omitted if `omitempty` -// is specified as a struct tag. Explicitly empty commands (i.e. `[]` or `''`) +// is specified as a struct tag. Explicitly empty commands (i.e. `[]` or `”`) // will serialize to an empty array (`[]`). // // When marshaled to JSON, the `omitempty` struct must NOT be specified. // If the command field is nil, it will be serialized as `null`. -// Explicitly empty commands (i.e. `[]` or `''`) will serialize to an empty +// Explicitly empty commands (i.e. `[]` or `”`) will serialize to an empty // array (`[]`). // // The distinction between nil and explicitly empty is important to distinguish @@ -539,6 +539,18 @@ func (h HostsList) AsList() []string { return l } +func (h HostsList) MarshalYAML() (interface{}, error) { + list := h.AsList() + sort.Strings(list) + return list, nil +} + +func (h HostsList) MarshalJSON() ([]byte, error) { + list := h.AsList() + sort.Strings(list) + return json.Marshal(list) +} + // LoggingConfig the logging configuration for a service type LoggingConfig struct { Driver string `yaml:",omitempty" json:"driver,omitempty"`