Browse Source

rename `convert` to `config` to align with compose v1 UX

Signed-off-by: Nicolas De Loof <[email protected]>
Nicolas De Loof 2 years ago
parent
commit
41e056341b

+ 6 - 6
cmd/compose/convert.go → cmd/compose/config.go

@@ -53,9 +53,9 @@ func convertCommand(p *ProjectOptions, streams api.Streams, backend api.Service)
 		ProjectOptions: p,
 	}
 	cmd := &cobra.Command{
-		Aliases: []string{"config"},
-		Use:     "convert [OPTIONS] [SERVICE...]",
-		Short:   "Converts the compose file to platform's canonical format",
+		Aliases: []string{"convert"}, // for backward compatibility with Cloud integrations
+		Use:     "config [OPTIONS] [SERVICE...]",
+		Short:   "Parse, resolve and render compose file in canonical format",
 		PreRunE: Adapt(func(ctx context.Context, args []string) error {
 			if opts.quiet {
 				devnull, err := os.Open(os.DevNull)
@@ -86,7 +86,7 @@ func convertCommand(p *ProjectOptions, streams api.Streams, backend api.Service)
 				return runConfigImages(streams, opts, args)
 			}
 
-			return runConvert(ctx, streams, backend, opts, args)
+			return runConfig(ctx, streams, backend, opts, args)
 		}),
 		ValidArgsFunction: completeServiceNames(p),
 	}
@@ -108,7 +108,7 @@ func convertCommand(p *ProjectOptions, streams api.Streams, backend api.Service)
 	return cmd
 }
 
-func runConvert(ctx context.Context, streams api.Streams, backend api.Service, opts convertOptions, services []string) error {
+func runConfig(ctx context.Context, streams api.Streams, backend api.Service, opts convertOptions, services []string) error {
 	var content []byte
 	project, err := opts.ToProject(services,
 		cli.WithInterpolation(!opts.noInterpolate),
@@ -120,7 +120,7 @@ func runConvert(ctx context.Context, streams api.Streams, backend api.Service, o
 		return err
 	}
 
-	content, err = backend.Convert(ctx, project, api.ConvertOptions{
+	content, err = backend.Config(ctx, project, api.ConfigOptions{
 		Format:              opts.Format,
 		Output:              opts.Output,
 		ResolveImageDigests: opts.resolveImageDigests,

+ 1 - 1
docs/reference/compose.md

@@ -9,7 +9,7 @@ Docker Compose
 |:--------------------------------|:------------------------------------------------------------------------|
 | [`alpha`](compose_alpha.md)     | Experimental commands                                                   |
 | [`build`](compose_build.md)     | Build or rebuild services                                               |
-| [`convert`](compose_convert.md) | Converts the compose file to platform's canonical format                |
+| [`config`](compose_config.md)   | Parse, resolve and render compose file in canonical format              |
 | [`cp`](compose_cp.md)           | Copy files/folders between a service container and the local filesystem |
 | [`create`](compose_create.md)   | Creates containers for a service.                                       |
 | [`down`](compose_down.md)       | Stop and remove containers, networks                                    |

+ 3 - 5
docs/reference/compose_convert.md → docs/reference/compose_config.md

@@ -1,11 +1,11 @@
 # docker compose convert
 
 <!---MARKER_GEN_START-->
-Converts the compose file to platform's canonical format
+Parse, resolve and render compose file in canonical format
 
 ### Aliases
 
-`docker compose convert`, `docker compose config`
+`docker compose config`, `docker compose convert`
 
 ### Options
 
@@ -29,8 +29,6 @@ Converts the compose file to platform's canonical format
 
 ## Description
 
-`docker compose convert` renders the actual data model to be applied on the target platform. When used with the Docker engine,
+`docker compose config` renders the actual data model to be applied on the Docker engine.
 it merges the Compose files set by `-f` flags, resolves variables in the Compose file, and expands short-notation into
 the canonical format.
-
-To allow smooth migration from docker-compose, this subcommand declares alias `docker compose config`

+ 2 - 2
docs/reference/docker_compose.yaml

@@ -115,7 +115,7 @@ pname: docker
 plink: docker.yaml
 cname:
     - docker compose build
-    - docker compose convert
+    - docker compose config
     - docker compose cp
     - docker compose create
     - docker compose down
@@ -141,7 +141,7 @@ cname:
     - docker compose version
 clink:
     - docker_compose_build.yaml
-    - docker_compose_convert.yaml
+    - docker_compose_config.yaml
     - docker_compose_cp.yaml
     - docker_compose_create.yaml
     - docker_compose_down.yaml

+ 138 - 0
docs/reference/docker_compose_config.yaml

@@ -0,0 +1,138 @@
+command: docker compose config
+aliases: docker compose config, docker compose convert
+short: Parse, resolve and render compose file in canonical format
+long: |-
+    `docker compose config` renders the actual data model to be applied on the Docker engine.
+    it merges the Compose files set by `-f` flags, resolves variables in the Compose file, and expands short-notation into
+    the canonical format.
+usage: docker compose config [OPTIONS] [SERVICE...]
+pname: docker compose
+plink: docker_compose.yaml
+options:
+    - option: format
+      value_type: string
+      default_value: yaml
+      description: 'Format the output. Values: [yaml | json]'
+      deprecated: false
+      hidden: false
+      experimental: false
+      experimentalcli: false
+      kubernetes: false
+      swarm: false
+    - option: hash
+      value_type: string
+      description: Print the service config hash, one per line.
+      deprecated: false
+      hidden: false
+      experimental: false
+      experimentalcli: false
+      kubernetes: false
+      swarm: false
+    - option: images
+      value_type: bool
+      default_value: "false"
+      description: Print the image names, one per line.
+      deprecated: false
+      hidden: false
+      experimental: false
+      experimentalcli: false
+      kubernetes: false
+      swarm: false
+    - option: no-consistency
+      value_type: bool
+      default_value: "false"
+      description: |
+        Don't check model consistency - warning: may produce invalid Compose output
+      deprecated: false
+      hidden: false
+      experimental: false
+      experimentalcli: false
+      kubernetes: false
+      swarm: false
+    - option: no-interpolate
+      value_type: bool
+      default_value: "false"
+      description: Don't interpolate environment variables.
+      deprecated: false
+      hidden: false
+      experimental: false
+      experimentalcli: false
+      kubernetes: false
+      swarm: false
+    - option: no-normalize
+      value_type: bool
+      default_value: "false"
+      description: Don't normalize compose model.
+      deprecated: false
+      hidden: false
+      experimental: false
+      experimentalcli: false
+      kubernetes: false
+      swarm: false
+    - option: output
+      shorthand: o
+      value_type: string
+      description: Save to file (default to stdout)
+      deprecated: false
+      hidden: false
+      experimental: false
+      experimentalcli: false
+      kubernetes: false
+      swarm: false
+    - option: profiles
+      value_type: bool
+      default_value: "false"
+      description: Print the profile names, one per line.
+      deprecated: false
+      hidden: false
+      experimental: false
+      experimentalcli: false
+      kubernetes: false
+      swarm: false
+    - option: quiet
+      shorthand: q
+      value_type: bool
+      default_value: "false"
+      description: Only validate the configuration, don't print anything.
+      deprecated: false
+      hidden: false
+      experimental: false
+      experimentalcli: false
+      kubernetes: false
+      swarm: false
+    - option: resolve-image-digests
+      value_type: bool
+      default_value: "false"
+      description: Pin image tags to digests.
+      deprecated: false
+      hidden: false
+      experimental: false
+      experimentalcli: false
+      kubernetes: false
+      swarm: false
+    - option: services
+      value_type: bool
+      default_value: "false"
+      description: Print the service names, one per line.
+      deprecated: false
+      hidden: false
+      experimental: false
+      experimentalcli: false
+      kubernetes: false
+      swarm: false
+    - option: volumes
+      value_type: bool
+      default_value: "false"
+      description: Print the volume names, one per line.
+      deprecated: false
+      hidden: false
+      experimental: false
+      experimentalcli: false
+      kubernetes: false
+      swarm: false
+deprecated: false
+experimental: false
+experimentalcli: false
+kubernetes: false
+swarm: false
+

+ 3 - 3
pkg/api/api.go

@@ -52,7 +52,7 @@ type Service interface {
 	// List executes the equivalent to a `docker stack ls`
 	List(ctx context.Context, options ListOptions) ([]Stack, error)
 	// Convert translate compose model into backend's native format
-	Convert(ctx context.Context, project *types.Project, options ConvertOptions) ([]byte, error)
+	Config(ctx context.Context, project *types.Project, options ConfigOptions) ([]byte, error)
 	// Kill executes the equivalent to a `compose kill`
 	Kill(ctx context.Context, projectName string, options KillOptions) error
 	// RunOneOffContainer creates a service oneoff container and starts its dependencies
@@ -185,8 +185,8 @@ type DownOptions struct {
 	Volumes bool
 }
 
-// ConvertOptions group options of the Convert API
-type ConvertOptions struct {
+// ConfigOptions group options of the Config API
+type ConfigOptions struct {
 	// Format define the output format used to dump converted application model (json|yaml)
 	Format string
 	// Output defines the path to save the application model

+ 5 - 5
pkg/api/proxy.go

@@ -38,7 +38,7 @@ type ServiceProxy struct {
 	LogsFn               func(ctx context.Context, projectName string, consumer LogConsumer, options LogOptions) error
 	PsFn                 func(ctx context.Context, projectName string, options PsOptions) ([]ContainerSummary, error)
 	ListFn               func(ctx context.Context, options ListOptions) ([]Stack, error)
-	ConvertFn            func(ctx context.Context, project *types.Project, options ConvertOptions) ([]byte, error)
+	ConfigFn             func(ctx context.Context, project *types.Project, options ConfigOptions) ([]byte, error)
 	KillFn               func(ctx context.Context, project string, options KillOptions) error
 	RunOneOffContainerFn func(ctx context.Context, project *types.Project, opts RunOptions) (int, error)
 	RemoveFn             func(ctx context.Context, project string, options RemoveOptions) error
@@ -78,7 +78,7 @@ func (s *ServiceProxy) WithService(service Service) *ServiceProxy {
 	s.LogsFn = service.Logs
 	s.PsFn = service.Ps
 	s.ListFn = service.List
-	s.ConvertFn = service.Convert
+	s.ConfigFn = service.Config
 	s.KillFn = service.Kill
 	s.RunOneOffContainerFn = service.RunOneOffContainer
 	s.RemoveFn = service.Remove
@@ -214,14 +214,14 @@ func (s *ServiceProxy) List(ctx context.Context, options ListOptions) ([]Stack,
 }
 
 // Convert implements Service interface
-func (s *ServiceProxy) Convert(ctx context.Context, project *types.Project, options ConvertOptions) ([]byte, error) {
-	if s.ConvertFn == nil {
+func (s *ServiceProxy) Config(ctx context.Context, project *types.Project, options ConfigOptions) ([]byte, error) {
+	if s.ConfigFn == nil {
 		return nil, ErrNotImplemented
 	}
 	for _, i := range s.interceptors {
 		i(ctx, project)
 	}
-	return s.ConvertFn(ctx, project, options)
+	return s.ConfigFn(ctx, project, options)
 }
 
 // Kill implements Service interface

+ 1 - 1
pkg/compose/compose.go

@@ -120,7 +120,7 @@ func getContainerNameWithoutProject(c moby.Container) string {
 	return name
 }
 
-func (s *composeService) Convert(ctx context.Context, project *types.Project, options api.ConvertOptions) ([]byte, error) {
+func (s *composeService) Config(ctx context.Context, project *types.Project, options api.ConfigOptions) ([]byte, error) {
 	if options.ResolveImageDigests {
 		info, err := s.apiClient().Info(ctx)
 		if err != nil {

+ 6 - 6
pkg/mocks/mock_docker_compose_api.go

@@ -50,19 +50,19 @@ func (mr *MockServiceMockRecorder) Build(ctx, project, options interface{}) *gom
 	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Build", reflect.TypeOf((*MockService)(nil).Build), ctx, project, options)
 }
 
-// Convert mocks base method.
-func (m *MockService) Convert(ctx context.Context, project *types.Project, options api.ConvertOptions) ([]byte, error) {
+// Config mocks base method.
+func (m *MockService) Config(ctx context.Context, project *types.Project, options api.ConfigOptions) ([]byte, error) {
 	m.ctrl.T.Helper()
-	ret := m.ctrl.Call(m, "Convert", ctx, project, options)
+	ret := m.ctrl.Call(m, "Config", ctx, project, options)
 	ret0, _ := ret[0].([]byte)
 	ret1, _ := ret[1].(error)
 	return ret0, ret1
 }
 
-// Convert indicates an expected call of Convert.
-func (mr *MockServiceMockRecorder) Convert(ctx, project, options interface{}) *gomock.Call {
+// Config indicates an expected call of Config.
+func (mr *MockServiceMockRecorder) Config(ctx, project, options interface{}) *gomock.Call {
 	mr.mock.ctrl.T.Helper()
-	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Convert", reflect.TypeOf((*MockService)(nil).Convert), ctx, project, options)
+	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Config", reflect.TypeOf((*MockService)(nil).Config), ctx, project, options)
 }
 
 // Copy mocks base method.