Skip to content

Commit 65dd424

Browse files
committed
allow services to use x-... as names
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent c78dcff commit 65dd424

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

loader/loader.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ func loadSections(filename string, config map[string]interface{}, configDetails
261261
return nil, err
262262
}
263263

264-
cfg.Networks, err = LoadNetworks(getSection(config, "networks"), configDetails.Version)
264+
cfg.Networks, err = LoadNetworks(getSection(config, "networks"))
265265
if err != nil {
266266
return nil, err
267267
}
@@ -426,6 +426,14 @@ func formatInvalidKeyError(keyPrefix string, key interface{}) error {
426426
func LoadServices(filename string, servicesDict map[string]interface{}, workingDir string, lookupEnv template.Mapping, opts *Options) ([]types.ServiceConfig, error) {
427427
var services []types.ServiceConfig
428428

429+
x, ok := servicesDict["extensions"]
430+
if ok {
431+
// as a top-level attribute, "services" doesn't support extensions, and a service can be named `x-foo`
432+
for k, v := range x.(map[string]interface{}) {
433+
servicesDict[k] = v
434+
}
435+
}
436+
429437
for name := range servicesDict {
430438
serviceConfig, err := loadServiceWithExtends(filename, name, servicesDict, workingDir, lookupEnv, opts, &cycleTracker{})
431439
if err != nil {
@@ -620,7 +628,7 @@ func transformUlimits(data interface{}) (interface{}, error) {
620628

621629
// LoadNetworks produces a NetworkConfig map from a compose file Dict
622630
// the source Dict is not validated if directly used. Use Load() to enable validation
623-
func LoadNetworks(source map[string]interface{}, version string) (map[string]types.NetworkConfig, error) {
631+
func LoadNetworks(source map[string]interface{}) (map[string]types.NetworkConfig, error) {
624632
networks := make(map[string]types.NetworkConfig)
625633
err := Transform(source, &networks)
626634
if err != nil {

loader/loader_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,7 @@ func TestLoadNetworksWarnOnDeprecatedExternalNameVersion35(t *testing.T) {
13621362
},
13631363
},
13641364
}
1365-
networks, err := LoadNetworks(source, "3.5")
1365+
networks, err := LoadNetworks(source)
13661366
assert.NilError(t, err)
13671367
expected := map[string]types.NetworkConfig{
13681368
"foo": {
@@ -1386,7 +1386,7 @@ func TestLoadNetworksWarnOnDeprecatedExternalName(t *testing.T) {
13861386
},
13871387
},
13881388
}
1389-
networks, err := LoadNetworks(source, "3.4")
1389+
networks, err := LoadNetworks(source)
13901390
assert.NilError(t, err)
13911391
expected := map[string]types.NetworkConfig{
13921392
"foo": {

0 commit comments

Comments
 (0)