Skip to content

Commit 82a567a

Browse files
committed
restore support for extends short syntax
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 6537c6c commit 82a567a

File tree

4 files changed

+50
-5
lines changed

4 files changed

+50
-5
lines changed

loader/extends.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,20 @@ func ApplyExtends(ctx context.Context, dict map[string]any, workingdir string, o
4141
if err := ct.Add(ctx.Value(consts.ComposeFileKey{}).(string), name); err != nil {
4242
return err
4343
}
44-
extends := x.(map[string]any)
44+
var (
45+
ref string
46+
file any
47+
)
48+
switch v := x.(type) {
49+
case map[string]any:
50+
ref = v["service"].(string)
51+
file = v["file"]
52+
case string:
53+
ref = v
54+
}
55+
4556
var base any
46-
ref := extends["service"].(string)
47-
if file, ok := extends["file"]; ok {
57+
if file != nil {
4858
path := file.(string)
4959
for _, loader := range opts.ResourceLoaders {
5060
if !loader.Accept(path) {

loader/loader_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,7 @@ name: load-extends
325325
services:
326326
foo:
327327
image: busybox
328-
extends:
329-
service: bar
328+
extends: bar
330329
bar:
331330
image: alpine
332331
command: echo`)

transform/canonical.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func init() {
2828
transformers["services.*"] = transformService
2929
transformers["services.*.build.secrets.*"] = transformFileMount
3030
transformers["services.*.depends_on"] = transformDependsOn
31+
transformers["services.*.extends"] = transformExtends
3132
transformers["services.*.networks"] = transformServiceNetworks
3233
transformers["services.*.volumes.*"] = transformVolumeMount
3334
transformers["services.*.secrets.*"] = transformFileMount

transform/extends.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
Copyright 2020 The Compose Specification Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package transform
18+
19+
import (
20+
"github.com/compose-spec/compose-go/v2/tree"
21+
"github.com/pkg/errors"
22+
)
23+
24+
func transformExtends(data any, p tree.Path) (any, error) {
25+
switch v := data.(type) {
26+
case map[string]any:
27+
return transformMapping(v, p)
28+
case string:
29+
return map[string]any{
30+
"service": v,
31+
}, nil
32+
default:
33+
return data, errors.Errorf("invalid type %T for extends", v)
34+
}
35+
}

0 commit comments

Comments
 (0)