mirror of
https://github.com/docker/compose.git
synced 2026-08-31 06:49:15 +00:00
Skip validation when extracting config variables
Signed-off-by: bigmomma <scarab.systems@yahoo.com>
This commit is contained in:
parent
39ee1d02b6
commit
fc83fbfa9e
3 changed files with 75 additions and 2 deletions
|
|
@ -28,6 +28,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/compose-spec/compose-go/v2/cli"
|
||||
"github.com/compose-spec/compose-go/v2/loader"
|
||||
"github.com/compose-spec/compose-go/v2/template"
|
||||
"github.com/compose-spec/compose-go/v2/types"
|
||||
"github.com/docker/cli/cli/command"
|
||||
|
|
@ -519,7 +520,7 @@ func runConfigImages(ctx context.Context, dockerCli command.Cli, opts configOpti
|
|||
|
||||
func runVariables(ctx context.Context, dockerCli command.Cli, opts configOptions, services []string) error {
|
||||
opts.noInterpolate = true
|
||||
model, err := opts.ToModel(ctx, dockerCli, services, cli.WithoutEnvironmentResolution)
|
||||
model, err := opts.ToModel(ctx, dockerCli, services, cli.WithoutEnvironmentResolution, cli.WithLoadOptions(loader.WithSkipValidation))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import (
|
|||
"text/tabwriter"
|
||||
|
||||
"github.com/compose-spec/compose-go/v2/cli"
|
||||
"github.com/compose-spec/compose-go/v2/loader"
|
||||
"github.com/compose-spec/compose-go/v2/template"
|
||||
"github.com/compose-spec/compose-go/v2/types"
|
||||
"github.com/docker/cli/cli/command"
|
||||
|
|
@ -165,7 +166,7 @@ func extractInterpolationVariablesFromModel(ctx context.Context, dockerCli comma
|
|||
ProjectOptions: projectOptions,
|
||||
}
|
||||
|
||||
model, err := opts.ToModel(ctx, dockerCli, nil, cli.WithoutEnvironmentResolution)
|
||||
model, err := opts.ToModel(ctx, dockerCli, nil, cli.WithoutEnvironmentResolution, cli.WithLoadOptions(loader.WithSkipValidation))
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -271,6 +271,77 @@ services:
|
|||
"\nExpected:\n%s\nGot:\n%s", expected, actualOutput)
|
||||
}
|
||||
|
||||
func TestExtractInterpolationVariablesFromModelAllowsTemplatedPortFields(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
cli := mocks.NewMockCli(ctrl)
|
||||
|
||||
dir := t.TempDir()
|
||||
composePath := filepath.Join(dir, "compose.yaml")
|
||||
assert.NilError(t, os.WriteFile(composePath, []byte(`
|
||||
name: remote-defaults
|
||||
services:
|
||||
web:
|
||||
image: nginx
|
||||
ports:
|
||||
- host_ip: "${LXKNS_ADDRESS:-127.0.0.1}"
|
||||
published: "${LXKNS_PORT:-5010}"
|
||||
target: 80
|
||||
protocol: tcp
|
||||
`), 0o600))
|
||||
|
||||
projectOptions := &ProjectOptions{
|
||||
ConfigPaths: []string{composePath},
|
||||
ProjectDir: dir,
|
||||
}
|
||||
info, noVariables, err := extractInterpolationVariablesFromModel(t.Context(), cli, projectOptions, []string{})
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, noVariables == false)
|
||||
|
||||
values := map[string]string{}
|
||||
for _, variable := range info {
|
||||
values[variable.name] = variable.defaultValue
|
||||
}
|
||||
assert.Equal(t, values["LXKNS_ADDRESS"], "127.0.0.1")
|
||||
assert.Equal(t, values["LXKNS_PORT"], "5010")
|
||||
}
|
||||
|
||||
func TestRunVariablesAllowsTemplatedPortFields(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
dir := t.TempDir()
|
||||
composePath := filepath.Join(dir, "compose.yaml")
|
||||
assert.NilError(t, os.WriteFile(composePath, []byte(`
|
||||
name: remote-defaults
|
||||
services:
|
||||
web:
|
||||
image: nginx
|
||||
ports:
|
||||
- host_ip: "${LXKNS_ADDRESS:-127.0.0.1}"
|
||||
published: "${LXKNS_PORT:-5010}"
|
||||
target: 80
|
||||
protocol: tcp
|
||||
`), 0o600))
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
cli := mocks.NewMockCli(ctrl)
|
||||
cli.EXPECT().Out().Return(streams.NewOut(buf)).AnyTimes()
|
||||
|
||||
opts := configOptions{
|
||||
Format: "json",
|
||||
ProjectOptions: &ProjectOptions{
|
||||
ConfigPaths: []string{composePath},
|
||||
ProjectDir: dir,
|
||||
},
|
||||
}
|
||||
assert.NilError(t, runVariables(t.Context(), cli, opts, nil))
|
||||
|
||||
output := buf.String()
|
||||
assert.Assert(t, strings.Contains(output, `"LXKNS_ADDRESS"`), output)
|
||||
assert.Assert(t, strings.Contains(output, `"LXKNS_PORT"`), output)
|
||||
}
|
||||
|
||||
func TestConfirmRemoteIncludes(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue