Home > Software engineering >  How to debug docker-compose? Where are config paths set?
How to debug docker-compose? Where are config paths set?

Time:12-22

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.

CodePudding user response:

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))...)
}
  • Related