cli/command/stack: internalize GetConfigDetails, LoadComposefile
These were deprecated in ad6ab189a6 and
were only used internally. Move them back inside the stack package.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
@ -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)
|
||||
@ -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.
|
||||
|
||||
Reference in New Issue
Block a user