浏览代码

config --environment

Signed-off-by: Nicolas De Loof <[email protected]>
Nicolas De Loof 1 年之前
父节点
当前提交
d633c33a19
共有 3 个文件被更改,包括 28 次插入0 次删除
  1. 17 0
      cmd/compose/config.go
  2. 1 0
      docs/reference/compose_config.md
  3. 10 0
      docs/reference/docker_compose_config.yaml

+ 17 - 0
cmd/compose/config.go

@@ -54,6 +54,7 @@ type configOptions struct {
 	hash                string
 	noConsistency       bool
 	variables           bool
+	environment         bool
 }
 
 func (o *configOptions) ToProject(ctx context.Context, dockerCli command.Cli, services []string, po ...cli.ProjectOptionsFn) (*types.Project, error) {
@@ -118,6 +119,9 @@ func configCommand(p *ProjectOptions, dockerCli command.Cli) *cobra.Command {
 			if opts.variables {
 				return runVariables(ctx, dockerCli, opts, args)
 			}
+			if opts.environment {
+				return runEnvironment(ctx, dockerCli, opts, args)
+			}
 
 			return runConfig(ctx, dockerCli, opts, args)
 		}),
@@ -138,6 +142,7 @@ func configCommand(p *ProjectOptions, dockerCli command.Cli) *cobra.Command {
 	flags.BoolVar(&opts.images, "images", false, "Print the image names, one per line.")
 	flags.StringVar(&opts.hash, "hash", "", "Print the service config hash, one per line.")
 	flags.BoolVar(&opts.variables, "variables", false, "Print model variables and default values.")
+	flags.BoolVar(&opts.environment, "environment", false, "Print environment used for interpolation.")
 	flags.StringVarP(&opts.Output, "output", "o", "", "Save to file (default to stdout)")
 
 	return cmd
@@ -385,6 +390,18 @@ func runVariables(ctx context.Context, dockerCli command.Cli, opts configOptions
 	}, "NAME", "REQUIRED", "DEFAULT VALUE", "ALTERNATE VALUE")
 }
 
+func runEnvironment(ctx context.Context, dockerCli command.Cli, opts configOptions, services []string) error {
+	project, err := opts.ToProject(ctx, dockerCli, services)
+	if err != nil {
+		return err
+	}
+
+	for _, v := range project.Environment.Values() {
+		fmt.Println(v)
+	}
+	return nil
+}
+
 func escapeDollarSign(marshal []byte) []byte {
 	dollar := []byte{'$'}
 	escDollar := []byte{'$', '$'}

+ 1 - 0
docs/reference/compose_config.md

@@ -12,6 +12,7 @@ Parse, resolve and render compose file in canonical format
 | Name                      | Type     | Default | Description                                                                 |
 |:--------------------------|:---------|:--------|:----------------------------------------------------------------------------|
 | `--dry-run`               |          |         | Execute command in dry run mode                                             |
+| `--environment`           |          |         | Print environment used for interpolation.                                   |
 | `--format`                | `string` | `yaml`  | Format the output. Values: [yaml \| json]                                   |
 | `--hash`                  | `string` |         | Print the service config hash, one per line.                                |
 | `--images`                |          |         | Print the image names, one per line.                                        |

+ 10 - 0
docs/reference/docker_compose_config.yaml

@@ -9,6 +9,16 @@ usage: docker compose config [OPTIONS] [SERVICE...]
 pname: docker compose
 plink: docker_compose.yaml
 options:
+    - option: environment
+      value_type: bool
+      default_value: "false"
+      description: Print environment used for interpolation.
+      deprecated: false
+      hidden: false
+      experimental: false
+      experimentalcli: false
+      kubernetes: false
+      swarm: false
     - option: format
       value_type: string
       default_value: yaml