From 73677146f4e987aeaef88c3520bc0595d52d8f06 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 1 Sep 2025 13:51:31 +0200 Subject: [PATCH] cli/command/stack: internalize GetConfigDetails, LoadComposefile These were deprecated in ad6ab189a642625d54053ac6e7080e8940288d2d and were only used internally. Move them back inside the stack package. Signed-off-by: Sebastiaan van Stijn --- cli/command/stack/config.go | 18 ++++++++++------- cli/command/stack/deploy.go | 3 +-- cli/command/stack/{loader => }/loader.go | 20 ++++++++----------- cli/command/stack/{loader => }/loader_test.go | 6 +++--- cli/command/stack/options/opts.go | 8 -------- 5 files changed, 23 insertions(+), 32 deletions(-) rename cli/command/stack/{loader => }/loader.go (86%) rename cli/command/stack/{loader => }/loader_test.go (92%) diff --git a/cli/command/stack/config.go b/cli/command/stack/config.go index 462aa447b..36863f7ff 100644 --- a/cli/command/stack/config.go +++ b/cli/command/stack/config.go @@ -6,28 +6,32 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" - "github.com/docker/cli/cli/command/stack/loader" - "github.com/docker/cli/cli/command/stack/options" composeLoader "github.com/docker/cli/cli/compose/loader" composetypes "github.com/docker/cli/cli/compose/types" "github.com/spf13/cobra" "gopkg.in/yaml.v3" ) +// configOptions holds docker stack config options +type configOptions struct { + composeFiles []string + skipInterpolation bool +} + func newConfigCommand(dockerCLI command.Cli) *cobra.Command { - var opts options.Config + var opts configOptions cmd := &cobra.Command{ Use: "config [OPTIONS]", Short: "Outputs the final config file, after doing merges and interpolations", Args: cli.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - configDetails, err := loader.GetConfigDetails(opts.Composefiles, dockerCLI.In()) + configDetails, err := getConfigDetails(opts.composeFiles, dockerCLI.In()) if err != nil { return err } - cfg, err := outputConfig(configDetails, opts.SkipInterpolation) + cfg, err := outputConfig(configDetails, opts.skipInterpolation) if err != nil { return err } @@ -40,8 +44,8 @@ func newConfigCommand(dockerCLI command.Cli) *cobra.Command { } flags := cmd.Flags() - flags.StringSliceVarP(&opts.Composefiles, "compose-file", "c", []string{}, `Path to a Compose file, or "-" to read from stdin`) - flags.BoolVar(&opts.SkipInterpolation, "skip-interpolation", false, "Skip interpolation and output only merged config") + flags.StringSliceVarP(&opts.composeFiles, "compose-file", "c", []string{}, `Path to a Compose file, or "-" to read from stdin`) + flags.BoolVar(&opts.skipInterpolation, "skip-interpolation", false, "Skip interpolation and output only merged config") return cmd } diff --git a/cli/command/stack/deploy.go b/cli/command/stack/deploy.go index 82301d514..a2ac0b637 100644 --- a/cli/command/stack/deploy.go +++ b/cli/command/stack/deploy.go @@ -3,7 +3,6 @@ package stack import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" - "github.com/docker/cli/cli/command/stack/loader" "github.com/docker/cli/cli/command/stack/options" "github.com/docker/cli/cli/command/stack/swarm" "github.com/spf13/cobra" @@ -22,7 +21,7 @@ func newDeployCommand(dockerCLI command.Cli) *cobra.Command { if err := validateStackName(opts.Namespace); err != nil { return err } - config, err := loader.LoadComposefile(dockerCLI, opts) + config, err := loadComposeFile(dockerCLI, opts) if err != nil { return err } diff --git a/cli/command/stack/loader/loader.go b/cli/command/stack/loader.go similarity index 86% rename from cli/command/stack/loader/loader.go rename to cli/command/stack/loader.go index 8187efb5a..3e42bf028 100644 --- a/cli/command/stack/loader/loader.go +++ b/cli/command/stack/loader.go @@ -1,7 +1,7 @@ // FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16: //go:build go1.23 -package loader +package stack import ( "fmt" @@ -21,11 +21,9 @@ import ( "github.com/pkg/errors" ) -// LoadComposefile parse the composefile specified in the cli and returns its Config and version. -// -// Deprecated: this function was for internal use and will be removed in the next release. -func LoadComposefile(dockerCli command.Cli, opts options.Deploy) (*composetypes.Config, error) { - configDetails, err := GetConfigDetails(opts.Composefiles, dockerCli.In()) +// loadComposeFile parse the composefile specified in the cli and returns its configOptions and version. +func loadComposeFile(streams command.Streams, opts options.Deploy) (*composetypes.Config, error) { + configDetails, err := getConfigDetails(opts.Composefiles, streams.In()) if err != nil { return nil, err } @@ -43,13 +41,13 @@ func LoadComposefile(dockerCli command.Cli, opts options.Deploy) (*composetypes. unsupportedProperties := loader.GetUnsupportedProperties(dicts...) if len(unsupportedProperties) > 0 { - _, _ = fmt.Fprintf(dockerCli.Err(), "Ignoring unsupported options: %s\n\n", + _, _ = fmt.Fprintf(streams.Err(), "Ignoring unsupported options: %s\n\n", strings.Join(unsupportedProperties, ", ")) } deprecatedProperties := loader.GetDeprecatedProperties(dicts...) if len(deprecatedProperties) > 0 { - _, _ = fmt.Fprintf(dockerCli.Err(), "Ignoring deprecated options:\n\n%s\n\n", + _, _ = fmt.Fprintf(streams.Err(), "Ignoring deprecated options:\n\n%s\n\n", propertyWarnings(deprecatedProperties)) } @@ -85,10 +83,8 @@ func propertyWarnings(properties map[string]string) string { return strings.Join(msgs, "\n\n") } -// GetConfigDetails parse the composefiles specified in the cli and returns their ConfigDetails -// -// Deprecated: this function was for internal use and will be removed in the next release. -func GetConfigDetails(composefiles []string, stdin io.Reader) (composetypes.ConfigDetails, error) { +// getConfigDetails parse the composefiles specified in the cli and returns their ConfigDetails +func getConfigDetails(composefiles []string, stdin io.Reader) (composetypes.ConfigDetails, error) { var details composetypes.ConfigDetails if len(composefiles) == 0 { diff --git a/cli/command/stack/loader/loader_test.go b/cli/command/stack/loader_test.go similarity index 92% rename from cli/command/stack/loader/loader_test.go rename to cli/command/stack/loader_test.go index 6c0da17aa..823440074 100644 --- a/cli/command/stack/loader/loader_test.go +++ b/cli/command/stack/loader_test.go @@ -1,4 +1,4 @@ -package loader +package stack import ( "os" @@ -22,7 +22,7 @@ services: file := fs.NewFile(t, "test-get-config-details", fs.WithContent(content)) defer file.Remove() - details, err := GetConfigDetails([]string{file.Path()}, nil) + details, err := getConfigDetails([]string{file.Path()}, nil) assert.NilError(t, err) assert.Check(t, is.Equal(filepath.Dir(file.Path()), details.WorkingDir)) assert.Assert(t, is.Len(details.ConfigFiles, 1)) @@ -37,7 +37,7 @@ services: foo: image: alpine:3.5 ` - details, err := GetConfigDetails([]string{"-"}, strings.NewReader(content)) + details, err := getConfigDetails([]string{"-"}, strings.NewReader(content)) assert.NilError(t, err) cwd, err := os.Getwd() assert.NilError(t, err) diff --git a/cli/command/stack/options/opts.go b/cli/command/stack/options/opts.go index 8d1fbd6e8..9c7a86c95 100644 --- a/cli/command/stack/options/opts.go +++ b/cli/command/stack/options/opts.go @@ -13,14 +13,6 @@ type Deploy struct { Quiet bool } -// Config holds docker stack config options -// -// Deprecated: this type was for internal use and will be removed in the next release. -type Config struct { - Composefiles []string - SkipInterpolation bool -} - // Remove holds docker stack remove options // // Deprecated: this type was for internal use and will be removed in the next release.