Skip to content

Commit

Permalink
use compose-go to interpolate compose variables
Browse files Browse the repository at this point in the history
This allows for nested variables interpolation.

Fixes docker#4265

Signed-off-by: N. Le Roux <[email protected]>
  • Loading branch information
gilbsgilbs committed Jan 9, 2025
1 parent ff4697d commit 982d52c
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 535 deletions.
2 changes: 1 addition & 1 deletion cli/compose/interpolation/interpolation.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"os"
"strings"

"github.com/docker/cli/cli/compose/template"
"github.com/compose-spec/compose-go/v2/template"
"github.com/pkg/errors"
)

Expand Down
6 changes: 6 additions & 0 deletions cli/compose/interpolation/interpolation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
var defaults = map[string]string{
"USER": "jenny",
"FOO": "bar",
"CMD": "my-cmd",
"count": "5",
}

Expand All @@ -26,6 +27,10 @@ func TestInterpolate(t *testing.T) {
services := map[string]any{
"servicea": map[string]any{
"image": "example:${USER}",
"command": []any{
"${CMD:-${UNDEF_CMD:-}}",
"${UNDEF:-${CMD}}",
},
"volumes": []any{"$FOO:/target"},
"logging": map[string]any{
"driver": "${FOO}",
Expand All @@ -38,6 +43,7 @@ func TestInterpolate(t *testing.T) {
expected := map[string]any{
"servicea": map[string]any{
"image": "example:jenny",
"command": []any{"my-cmd", "my-cmd"},
"volumes": []any{"bar:/target"},
"logging": map[string]any{
"driver": "bar",
Expand Down
2 changes: 1 addition & 1 deletion cli/compose/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
"strings"
"time"

"github.com/compose-spec/compose-go/v2/template"
interp "github.com/docker/cli/cli/compose/interpolation"
"github.com/docker/cli/cli/compose/schema"
"github.com/docker/cli/cli/compose/template"
"github.com/docker/cli/cli/compose/types"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types/versions"
Expand Down
248 changes: 0 additions & 248 deletions cli/compose/template/template.go

This file was deleted.

Loading

0 comments on commit 982d52c

Please sign in to comment.