如何调试docker-compose?配置路径在哪里设置?

huangapple go评论87阅读模式
英文:

How to debug docker-compose? Where are config paths set?

问题

我正在尝试调试docker-compose,即这个Go文件,以解决一些问题(这个问题)。为了做到这一点,我已经设置了一个GoLang调试器。

go run main.go -f /.../project_root/docker-compose.yml -f /.../project_root/folder1/docker-compose.yml config的输出结果如预期,即合并后的配置文件。

由于某种原因,我无法在代码中找到设置配置文件的地方,尽管它们必须在某个地方设置,因为输出结果是正确合并的配置文件。我怀疑它们可能在这里这里附近设置。但在前一个位置,cli.configFile的值为nil,而在后一个位置,o.ConfigPaths的值为nil

所以我有两个问题:

  1. 配置文件是在哪里设置的?
  2. (如果无法回答第一个问题)在尝试模拟实际的docker-compose命令行行为时,我做错了什么?

编辑

根据上述问题和已经找到配置路径可能被设置的位置,我现在的问题是卷路径是在哪里设置的。

英文:

I am trying to debug docker-compose, i.e. this Go file, to work on some issue (this one). To do that, I have set up a GoLang debugger

The output of go run main.go -f /.../project_root/docker-compose.yml -f /.../project_root/folder1/docker-compose.yml config is as expected, the merged config files.

For some reason, I can not find the config files being set in the code, although they must be set somewhere as the output is the correctly merged config files. I suspected they must be set somewhere around here or here. But in the former place, the value of cli.configFile is nil, and in the latter place, the value of o.ConfigPaths is nil.

So I have two questions:

  1. Where are the config files being set? and
  2. (if 1 cannot be answered) What am I doing wrong in trying to emulate the behavior of the actual docker-compose command?

Edit

In accordance to the above mentioned issue and having found where the config paths are probably set, my question now is where the volume paths are being set.

答案1

得分: 1

哪些配置路径?默认配置文件(docker-compose.yaml)的路径由cli.WithDefaultConfigPath方法设置(在compose-go存储库中)。默认配置的可能名称在这里设置:

// DefaultFileNames定义了自动发现的Compose文件名称(按优先顺序)
var DefaultFileNames = []string{"compose.yaml", "compose.yml", "docker-compose.yml", "docker-compose.yaml"}

WithDefaultConfigPath方法遍历此列表,如果找到匹配的文件,则将其应用于ProjectOptions结构体中的ConfigPaths字段,在这里

type ProjectOptions struct {
	ProjectName   string
	Profiles      []string
	ConfigPaths   []string
	WorkDir       string
	ProjectDir    string
	EnvFile       string
	Compatibility bool
}

WithDefaultConfigPath方法应用于toProjectOptions方法中,在这里

func (o *ProjectOptions) toProjectOptions(po ...cli.ProjectOptionsFn) (*cli.ProjectOptions, error) {
	return cli.NewProjectOptions(o.ConfigPaths,
		append(po,
			cli.WithWorkingDirectory(o.ProjectDir),
			cli.WithOsEnv,
			cli.WithEnvFile(o.EnvFile),
			cli.WithDotEnv,
			cli.WithConfigFileEnv,
			cli.WithDefaultConfigPath,
			cli.WithName(o.ProjectName))...)
}
英文:

Which config paths? The path for the default configuration file (docker-compose.yaml) is set by the cli.WithDefaultConfigPath method (in the compose-go repository). The possible names for the default config are set here:

// DefaultFileNames defines the Compose file names for auto-discovery (in order of preference)
var DefaultFileNames = []string{"compose.yaml", "compose.yml", "docker-compose.yml", "docker-compose.yaml"}

The WithDefaultConfigPath method iterates over this list, and if it finds a matching file, it gets applied to the ConfigPaths field in the ProjectOptions struct, here:

type ProjectOptions struct {
	ProjectName   string
	Profiles      []string
	ConfigPaths   []string
	WorkDir       string
	ProjectDir    string
	EnvFile       string
	Compatibility bool
}

The WithDefaultConfigPath method is applied in the toProjectOptions method, here:

func (o *ProjectOptions) toProjectOptions(po ...cli.ProjectOptionsFn) (*cli.ProjectOptions, error) {
	return cli.NewProjectOptions(o.ConfigPaths,
		append(po,
			cli.WithWorkingDirectory(o.ProjectDir),
			cli.WithOsEnv,
			cli.WithEnvFile(o.EnvFile),
			cli.WithDotEnv,
			cli.WithConfigFileEnv,
			cli.WithDefaultConfigPath,
			cli.WithName(o.ProjectName))...)
}

huangapple
  • 本文由 发表于 2022年12月22日 05:33:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/74881979.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定