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 authored and Nils Le Roux committed May 8, 2023
1 parent 8a8b600 commit 76d986f
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 541 deletions.
2 changes: 1 addition & 1 deletion cli/compose/interpolation/interpolation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"os"
"strings"

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

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

Expand All @@ -22,7 +23,11 @@ func defaultMapping(name string) (string, bool) {
func TestInterpolate(t *testing.T) {
services := map[string]interface{}{
"servicea": map[string]interface{}{
"image": "example:${USER}",
"image": "example:${USER}",
"command": []interface{}{
"${CMD:-${UNDEF_CMD:-}}",
"${UNDEF:-${CMD}}",
},
"volumes": []interface{}{"$FOO:/target"},
"logging": map[string]interface{}{
"driver": "${FOO}",
Expand All @@ -36,6 +41,7 @@ func TestInterpolate(t *testing.T) {
"servicea": map[string]interface{}{
"image": "example:jenny",
"volumes": []interface{}{"bar:/target"},
"command": []interface{}{"my-cmd", "my-cmd"},
"logging": map[string]interface{}{
"driver": "bar",
"options": map[string]interface{}{
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 @@ -9,9 +9,9 @@ import (
"strings"
"time"

"github.com/compose-spec/compose-go/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
247 changes: 0 additions & 247 deletions cli/compose/template/template.go

This file was deleted.

Loading

0 comments on commit 76d986f

Please sign in to comment.