Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions loader/extends.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,20 @@ func ApplyExtends(ctx context.Context, dict map[string]any, workingdir string, o
if err := ct.Add(ctx.Value(consts.ComposeFileKey{}).(string), name); err != nil {
return err
}
extends := x.(map[string]any)
var (
ref string
file any
)
switch v := x.(type) {
case map[string]any:
ref = v["service"].(string)
file = v["file"]
case string:
ref = v
}

var base any
ref := extends["service"].(string)
if file, ok := extends["file"]; ok {
if file != nil {
path := file.(string)
for _, loader := range opts.ResourceLoaders {
if !loader.Accept(path) {
Expand Down
3 changes: 1 addition & 2 deletions loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,7 @@ name: load-extends
services:
foo:
image: busybox
extends:
service: bar
extends: bar
bar:
image: alpine
command: echo`)
Expand Down
1 change: 1 addition & 0 deletions transform/canonical.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func init() {
transformers["services.*"] = transformService
transformers["services.*.build.secrets.*"] = transformFileMount
transformers["services.*.depends_on"] = transformDependsOn
transformers["services.*.extends"] = transformExtends
transformers["services.*.networks"] = transformServiceNetworks
transformers["services.*.volumes.*"] = transformVolumeMount
transformers["services.*.secrets.*"] = transformFileMount
Expand Down
35 changes: 35 additions & 0 deletions transform/extends.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Copyright 2020 The Compose Specification Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package transform

import (
"github.com/compose-spec/compose-go/v2/tree"
"github.com/pkg/errors"
)

func transformExtends(data any, p tree.Path) (any, error) {
switch v := data.(type) {
case map[string]any:
return transformMapping(v, p)
case string:
return map[string]any{
"service": v,
}, nil
default:
return data, errors.Errorf("invalid type %T for extends", v)
}
}